Add bookmarks to gmap

0

I want to add a bookmark at the point I'm showing on the map. It loads the map and everything, but I can not add the bookmark.

<h:body>
    <h:form>
        <p:poll interval="10"
            listener="#{gadoBean.obterPosicaoTag}"
            update="panelMap"/>
    <p:panel id="panelMap">
        <p:gmap id="mapa"  
            center="#{gadoBean.center}"
            zoom="18" 
            model="#{gadoBean.mapa}"  
            type="HYBRID" 
            style="width:600px;height:400px"/>
    </p:panel>
</h:form> 
</h:body>
</html>

ManagedBean:

@Named
@SessionScoped
public class GadoBean implements Serializable {

private static final long serialVersionUID = 1L;
private MapModel mapa;
private Circle circulo = null;
private Tag tag;
private Gado gadoAtual;
private float lastLat, lastLong;
private Coordenadas coordenadas;
private List<Coordenadas> posicoes;
private Fazenda fazendaAtual;
private String center;
private LatLng coord;

@Inject
private CoordenadasService coordenadasService;

@Inject
private CoordenadasRep coordenadasRep;

public GadoBean() {

    mapa = new DefaultMapModel();


}

public void inicializar() {

}




public void obterPosicaoTag() {
    posicoes = new ArrayList<Coordenadas>();
    posicoes = coordenadasRep.listar();
    int totalPosicoes = this.getPosicoes().size(); 
    if (totalPosicoes > 0) {
        Coordenadas posicaoAtual = this.getPosicoes().get(totalPosicoes - 1);
        coord = new LatLng(posicaoAtual.getPosLongitude(), posicaoAtual.getPosLatitude());
        lastLong = (float) posicaoAtual.getPosLongitude();
        lastLat = (float) posicaoAtual.getPosLatitude();
        center = lastLat + "," + lastLong;
        System.out.println(center);
        mapa.addOverlay(new Marker(coord));




    }
}

//getters and setters
    
asked by anonymous 13.07.2016 / 20:20

1 answer

0

I made some changes and now it worked:

<f:metadata>
    <f:viewParam name="dummy"/>
    <f:event listener="#{gadoBean.obterPosicaoTag}" type="preRenderView"/>
</f:metadata>
<h:body>

<h:form>
    <p:poll interval="10"
            listener="#{gadoBean.obterPosicaoTag}"
            update="panelMap"/>
    <p:panel id="panelMap">
        <p:gmap id="mapa"  
            center="#{gadoBean.center}"
            zoom="18" 
            model="#{gadoBean.mapa}"  
            type="HYBRID" 
            style="width:600px;height:400px"/>
    </p:panel>
</h:form> 
</h:body>
</html>

No Bean:

public GadoBean() {
}

public void inicializar() {
}

public void obterPosicaoTag() {
    mapa = new DefaultMapModel();
    posicoes = new ArrayList<Coordenadas>();
    posicoes = coordenadasRep.listar();
    int totalPosicoes = this.getPosicoes().size();
    if (totalPosicoes > 0) {
        Coordenadas posicaoAtual = this.getPosicoes().get(totalPosicoes -  1);
        coord = new LatLng(posicaoAtual.getPosLatitude(),  posicaoAtual.getPosLongitude());
        mapa.addOverlay(new Marker(coord, "Gado"));
        lastLong = (float) posicaoAtual.getPosLongitude();
        lastLat = (float) posicaoAtual.getPosLatitude();
        center = lastLat + "," + lastLong;
   }
}
    
14.07.2016 / 02:09