Google Maps for Vaadin 7

I’ve just released version 0.6 that adds support for both info windows and icons of the markers.

Current implementation doesn’t modify the marker objects when they have been dragged. The listener just gets the new position as the second parameter and it’s up to the user to update the markers if that kind of action is wanted.

Great, thank’s.

I missed that. Thank’s for the answer.

Nice addon. Thanks for window info and customized markers.

I need some other google apis service. Like geocode, distancematrix and route calculations. Is it possible call those services thru GoogleMaps api (in future or now?) or should i do other connections (own request) to google?

Very nicely done.
Now if someone could migrate LocationTextField add-on for use with Vaadin 7, those two could interact very well together.

Hi,
I can’t see in my map any Markers with my a custom Icon saved into theme folder ex. VAADIN/themes/mytheme.

I also tried to copy the icon in the same folder of my class which extends GoogleMap.
Ex. Code:


String urlIcon = VaadinService.getCurrent()
		                  .getBaseDirectory().getAbsolutePath()+ "/VAADIN/themes/mytheme/myicon.png";
GoogleMapMarker gMarker = new GoogleMapMarker(popupTxt, new LatLon(georef[0]
, georef[1]
), false, 
	            		urlIcon);
addMarker(gMarker);

Anyone help me?
Thanks

Those are all supported by Google Maps Javascript API (see
https://developers.google.com/maps/documentation/javascript/reference
). Therefore adding them to the add-on would be possible but currently we don’t have plans for that.

VaadinService.getBaseDirectory().getAbsolutePath() gives you the absolute path to the directory of you application in your file system while here an URL to the icon is wanted. Most of the time it should be enough to use just

String urlIcon = "VAADIN/themes/mytheme/myicon.png";

In case you also need to have the context root in your URL, you can get it using VaadinRequest.getContextPath().

HI Tapio! Using the add-on I found out that the setCenter() method doesn’t always work, the use case is : I have a list of “things” and I want to show their location on map when I select them from a table, but whenever I try to select it and invoke setCenter, the map isn’t centered automatically. Can you help please ?

Regards,
Ivan Frias

We have several sponsors to thank for this add-on. Please contact sales@vaadin.com if you would like to discuss sponsoring those or some other features into a future version of the add-on.

Thanks Tapio !It works!

Could you provide some kind of example app that demonstrates the issue?

The case is that i have a textfield ‘search’ and a button, that i user to take address as input. Than i use geocoding to translate the address to a LatLon object, than as you see at the code on the listener, i call map.setCenter(latLon) and then add a marker. The first time the setCenter works and the marker is added, but the next times setCenter doesn’t work but the marker is added anyway.


		googleMap = new GoogleMap(new LatLon(60.440963, 22.25122), 10.0, apiKey);
        googleMap.setSizeFull();
        googleMap.addMarker("DRAGGABLE: Paavo Nurmi Stadion", new LatLon(
                60.442423, 22.26044), true, "");
        googleMap.addMarker("DRAGGABLE: Kakolan vankila", new LatLon(60.44291,
                22.242415), true, "");
        googleMap.addMarker("NOT DRAGGABLE: Iso-Heikkilä", new LatLon(
                60.450403, 22.230399), false, "");
		googleMap.setMinZoom(0.0);
        googleMap.setMaxZoom(20.0);
		layout.addComponent(googleMap);
		//layout.setExpandRatio(googleMap, 1);

		button.addClickListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				String adr = search.getValue();
				if(adr==null || adr.isEmpty())return;
				
				LatLon latLon = null;
				try {
					latLon = getLatLon(adr);
				} catch (XPathExpressionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParserConfigurationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SAXException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				googleMap.clearMarkers();
				googleMap.setCenter(latLon);				
				googleMap.addMarker(adr, latLon, false, "");
			}
		});

Is it possible to avoid the effect when adding markers to the map ?

Hi Tapio,
First of all. Great job to all of you !!! :slight_smile:
I have noticed the same Issue as Ivan mentioned above. If I move away from a given point, or scroll the Map and invoke setCenter on a particular coordinate, the Map doesn’t seem to get centered.

I noticed however that if I place a Marker at the “target center position”, the marker is appearing at the right place so the issue, at least in my case, is really centering.

I’ve just released version 0.6.1 that fixes setCenter() if the old location came from the client.

0.6.1 also has GoogleMapMarker.setAnimationEnabled() that can be used to disable marker animation.

First, thanks for the add-on, very good job.

I was looking for an issue, where I put the map inside a VerticalSplitPanel, and if I resize the split panel, the map won’t draw correctly the background tiles.

Than I found this in the Google Maps documentation:

…“Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, ‘resize’) .”

The link of the text:
https://developers.google.com/maps/documentation/javascript/reference?csw=1#event

I think that this is the only way to fix this issue.

Also will be interesting to enable from the add-on this property:
google.maps.visualRefresh = true
So we can use the new map style.

Best,
Regards.

Hi,
I have this warning in my eclipse console after few second that my map is loaded:

3-set-2013 12.04.43 com.vaadin.server.communication.ServerRpcHandler parseInvocation
AVVERTENZA: RPC call to com.vaadin.tapio.googlemaps.client.GoogleMapMovedRpc.mapMoved received for connector 100 but no such connector could be found. Resynchronizing client.

Hi Tappio! Hope everything is fine. I’ve experimenting with your plugin and it seems very good. Tell me one thing - do you think it’s possible to change the map Locale ? Right now all my Application is in English but the top and left corners present information in Portuguese and I think it’s because I am not setting the locale properly.

Can you help ?

Best regards,
Ivan

I’ll take a look on these and hopefully both will be in the next version.

Hard to know what causes the RPC call to fail without knowing anything else about your environment. Probably this isn’t an issue if you’re receiving other map moved events without problems.

As told
in the API documentation
, the language used by maps is, by default, chosen from the preferred languages of the browser. I guess I could add a setting for this too.

There you go! 0.6.2 is out with following modifications:

  • Added setting for forcing the language of the maps
  • Added setting for enabling the new visual style
  • Fixed resizing of the map (for example in SplitPanel)

I tried this, but doing draggedMarker.setPosition(newPosition) from the MarkerDragListener does not seem to update the map with the new position it seems - e.g. adding a new marker afterwards brings the dragged one back to the previous position.

I had to explicitly remove the marker and add a new one with the new position, which of course triggers a new animation for every marker in the map (if that’s enabled), which is quite slow/confusing as the response to a simple dragging operation, especially as the number of markers grows.

Is there a way to overcome this? How do you recommend to perform the position update of a marker in the listener?