Reputation:
I'm using PrimeFaces 8.0.3. The first time the page loads, the gmap has no markers because the table where I store the coordinates is empty. When a new marker is added, the page refreshes but the map still doesn't show the marker. This problem only happens when I run the application on the server, because when I run it locally, the new marker is shown without problems. The page refreshes every ten seconds to check if there are new rows in the table.
Html:
<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=[provided api key]"></script>
<h:form>
<p:panel>
<p:gmap center="-0.2727324,-78.5489364" zoom="18" type="ROADMAP" style="width:90%;height:700px" model="#{mapaCtrl.simpleModel}" />
<p:poll interval="10" listener="#{contadorCtrl.recargarMapa()}" />
</p:panel>
</h:form>
MapaCtrl:
@ManagedBean
@RequestScoped
public class MapaCtrl implements Serializable
{
private MapModel simpleModel;
...
public void dibujarMarcadores()
{
for(int i = 0; i < listaSolicitud.size(); i++)
{
LatLng coord = new LatLng(Double.parseDouble(listaSolicitud.get(i).getLatitud()), Double.parseDouble(listaSolicitud.get(i).getLongitud()));
simpleModel.addOverlay(new Marker(coord, listaSolicitud.get(i).getDescripcionsolicitud()));
}
}
}
ContadorCtrl:
@ManagedBean
@RequestScoped
public class MapaCtrl implements Serializable
{
...
public void recargarMapa()
{
...
if(solicitudesActuales != MapaCtrl.solicitudesIniciales)
{
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try
{
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
}
catch(IOException ex)
{
Logger.getLogger(ContadorCtrl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
How can I show the new markers in the map?
Upvotes: 1
Views: 128
Reputation: 273
You need to assign an id to your map component, and then update it when polling:
<p:gmap id="myMap" center="-0.2727324,-78.5489364" zoom="18" type="ROADMAP" style="width:90%;height:700px" model="#{mapaCtrl.simpleModel}" />
<p:poll interval="10" listener="#{contadorCtrl.recargarMapa()}" update="myMap"/>
Upvotes: 3