Page 1 of 1

Add Gmap Marker programatically

Posted: 19 Jul 2010, 16:29
by ramo.karahasan
Hi,

i'm trying to figure out, how to set a marker programatoically via the pointSelectListener listener.

In my backing bean i used this code:

Code: Select all

	public void onPointSelect(PointSelectEvent event) {
		LatLng latlng = event.getLatLng();
		Marker marker = new Marker(latlng);
		model.addOverlay(marker);
		addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Point and Marker selected and set", "Lat:" + latlng.getLat() + ", Lng:" + latlng.getLng()));
	}
in the View i've a gmap component

Code: Select all

<p:gmap center="41.381542, 2.122893" zoom="15" type="ROADMAP"
		style="width:600px;height:400px" model="#{mapBean.model}"
		stateChangeListener="#{mapBean.onStateChange}" onStateChangeUpdate="messages"
		pointSelectListener="#{mapBean.onPointSelect}" onPointSelectUpdate="messages"
/>
so, when i'm clicking at a point, nothing happens, just the growl is shown. if i add an id to my p:gmap and add it to the onPointSelectUpdate event, the gmap is reloaded every time i click on the map but i see one, and every time only one marker. I would like to add multiple markers there, how to realize this? with a list of markers?

Any hints? Is there a way, that i can even allow setting markers, or polygons via links? i mean one link "marker" the seconde linke "polygon". when i click "marker" i have the possibility to add markers do my map, if i click "polygon" i can add polygons to my map.


Greetings and thank you,
Ramo

Re: Add Gmap Marker programatically

Posted: 19 Jul 2010, 18:05
by cagatay.civici

Re: Add Gmap Marker programatically

Posted: 19 Jul 2010, 19:24
by ramo.karahasan
Hi,

yeah i saw this example, but this is realized with Javascript. I thought there would be a way to avoid the javascript code, so that i can directly use events and generate/display the markers from the backing bean, while clikcin into the map.


Ramo

Re: Add Gmap Marker programatically

Posted: 20 Jul 2010, 13:00
by ramo.karahasan
Hey Cagatay,

okay, i would like to implement this Version of the Showcase without the dialog. Just a click on the map, should add the Marker-Overlay to the model. You've implemented it with a Actionlistener in the dialog. So how to realize this without the dialog. in p:gmap i don't have an ActionListener. if i use something like this:

Code: Select all

<p:gmap id="gmap" center="50.00257,8.277417" zoom="13" type="HYBRID"
	style="width:600px;height:400px"
	model="#{mapBean.model}"
	onPointClick="handlePointClick(event);" pointSelectListener="#{mapBean.onPointSelect}" 
	widgetVar="map" />
and this in my backing bean:

Code: Select all

public void onPointSelect(PointSelectEvent event) {
		LatLng latlng = event.getLatLng();
		Marker marker = new Marker(latlng);
		marker.setDraggable(true);
		model.addOverlay(marker);
		addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Point and Marker selected and set", "Lat:" + latlng.getLat() + ", Lng:" + latlng.getLng()));
	}
There is only the first marker set, displayed. I don't know why.

Any hints?


Cheerio,
Ramo

Re: Add Gmap Marker programatically

Posted: 19 Apr 2012, 17:20
by corgan
I think never enter in pointSelectListener method. Have you find some solutions?
Thanks