Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately I can't tell you exactly what you are doing wrong because I can't make sense of the code you posted (incomplete and badly formatted...sorry). However, after getting familiar with the examples online <strong><em>I think</em></strong> I can tell you why your markers were not being dragged after you added one to the map. I'm also going to provide you my working sample since you've been waiting so long for an answer.</p> <p>When you called <code>map.addOverLay</code> via the javascript, you were indeed setting a marker on the client side and (assuming that your code worked) updating the server side after clicking Add. However, you needed to <strong>reload</strong> <code>p:gmap</code> with the updated collection of markers that were on the server. When you added the new marker, <code>p:gmap</code> was still referencing the old collection. Therefore, when you tried to move it you couldn't. As far as <code>p:gmap</code> was concerned no <code>MarkerDragEvent</code> was being fired because you were not dragging one of <strong><em>its</em></strong> markers. You were simply touching a static image that was set by <code>map.addOverlay</code>. So to fix this, you need to update <code>p:gmap</code> after clicking Add by adding it in the <code>p:ajax</code> list</p> <pre><code>&lt;p:commandButton id="test" value="Add" actionListener="#{mapBean.addMarker}" update=":growl, :gmap" oncomplete="markerAddComplete()"/&gt; </code></pre> <p>That's really it honestly. As far as the answer from the similar problem you found...I can't make sense of it either. Anyway, here is the the code</p> <p><strong>Index.xhtml</strong></p> <pre><code>&lt;h:head&gt; &lt;title&gt;Facelet Title&lt;/title&gt; &lt;script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"&gt;&lt;/script&gt; &lt;h:outputScript name="javascript/common.js" /&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;p:growl id="growl" showDetail="true"/&gt; &lt;p:gmap id="gmap" center="36.890257,30.707417" zoom="13" type="HYBRID" style="width:600px;height:400px" model="#{mapBean.draggableModel}" onPointClick="handlePointClick(event);" widgetVar="map"&gt; &lt;p:ajax event="markerDrag" listener="#{mapBean.onMarkerDrag}" update="growl" /&gt; &lt;/p:gmap&gt; &lt;p:dialog widgetVar="dlg" showEffect="fade"&gt; &lt;h:form prependId="false"&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:outputLabel for="title" value="Title:" /&gt; &lt;p:inputText id="title" value="#{mapBean.title}" /&gt; &lt;f:facet name="footer"&gt; &lt;p:commandButton id="test" value="Add" actionListener="#{mapBean.addMarker}" update=":growl, :gmap" oncomplete="markerAddComplete()"/&gt; &lt;p:commandButton value="Cancel" onclick="return cancel()"/&gt; &lt;/f:facet&gt; &lt;/h:panelGrid&gt; &lt;h:inputHidden id="lat" value="#{mapBean.lat}" /&gt; &lt;h:inputHidden id="lng" value="#{mapBean.lng}" /&gt; &lt;/h:form&gt; &lt;/p:dialog&gt; &lt;/h:body&gt; </code></pre> <p><strong>MapBean.java</strong></p> <pre><code>@ManagedBean public class MapBean implements Serializable { private MapModel draggableModel; private String title; private double lat; private double lng; public MapBean() { draggableModel = new DefaultMapModel(); //Shared coordinates LatLng coord1 = new LatLng(36.879466, 30.667648); LatLng coord2 = new LatLng(36.883707, 30.689216); LatLng coord3 = new LatLng(36.879703, 30.706707); LatLng coord4 = new LatLng(36.885233, 30.702323); //Draggable draggableModel.addOverlay(new Marker(coord1, "Konyaalti","Konyaalti","http://maps.google.com/mapfiles/ms/micons/red-dot.png")); draggableModel.addOverlay(new Marker(coord2, "Ataturk Parki", "Ataturk Parki","http://maps.google.com/mapfiles/ms/micons/red-dot.png")); draggableModel.addOverlay(new Marker(coord3, "Karaalioglu Parki", "Karaalioglu Parki","http://maps.google.com/mapfiles/ms/micons/red-dot.png")); draggableModel.addOverlay(new Marker(coord4, "Kaleici", "Kaleici", "http://maps.google.com/mapfiles/ms/micons/red-dot.png")); for(Marker marker : draggableModel.getMarkers()) { marker.setDraggable(true); } } public MapModel getDraggableModel() { return draggableModel; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLng() { return lng; } public void setLng(double lng) { this.lng = lng; } public void onMarkerDrag(MarkerDragEvent event) { Marker marker = event.getMarker(); addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Dragged", "Lat:" + marker.getLatlng().getLat() + ", Lng:" + marker.getLatlng().getLng())); } public void addMessage(FacesMessage message) { FacesContext.getCurrentInstance().addMessage(null, message); } public void addMarker(ActionEvent actionEvent) { Marker marker = new Marker(new LatLng(lat, lng), title, "SOME VALUE", "http://maps.google.com/mapfiles/ms/micons/red-dot.png"); marker.setDraggable(true); draggableModel.addOverlay(marker); addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Added", "Lat:" + lat + ", Lng:" + lng + "Is marker draggable ?" + marker.isDraggable())); } } </code></pre> <p><strong>common.js</strong> </p> <p>This file contains the javascript. I was using Netbeans and this file was located in a folder called javascript in the following directory Web Pages/resources/javascript. No need to mix it with the JSF. Try to be clean, it will help you in the long run. The code is basically <a href="http://www.primefaces.org/showcase/ui/gmapAddMarkers.jsf" rel="nofollow">the same as the example online</a> so you can just copy it from there. The only thing I did was take out the <code>&lt;script&gt;</code> tags and moved it all in that file. Cheers. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload