使用Atmosphere.js数据过滤gmap标记

时间:2016-07-28 15:07:56

标签: google-maps primefaces google-maps-markers publish-subscribe atmosphere.js

我想在谷歌地图上设置标记的位置,使用Atmosphere.js,如推送消息。我可以将新的LatLng数据发送到页面,我可以过滤公司(比如订阅),但我不知道如何过滤正确的标记以设置其新位置。哪种方式最好。我需要你的建议。

    <ui:composition template="../template/template.xhtml">
    <ui:define name="title">
        <h:outputText value=""></h:outputText>
    </ui:define>
    <ui:define name="body">

        <h:form>

            <p:remoteCommand name="updateList" update="gmap" process="@this"/>
            <p:socket onMessage="handleMessage" channel="/refreshcordinates/#{haritaBean.companyId}" autoConnect="true"/>

            <p:growl id="growl" life="3000" />

            <p:gmap widgetVar="gMap" id="gmap" center="40.74634,30.67725" zoom="18" type="ROADMAP" style="width:100%;height:800px" model="#{haritaBean.GetCoordinates()}" streetView="true">
            </p:gmap>
        </h:form>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&amp;key=myKey"></script>
        <script type="text/javascript">
            function handleMessage(data) {

                var gMap = PF("gMap").getMap();
                gMap.markers[0].setPosition(new google.maps.LatLng(parseFloat(data.lat), parseFloat(data.lng)));

        </script>

    </ui:define>
</ui:composition>

    private MapModel simpleModel;
    public MapModel GetCoordinates() {
    simpleModel = new DefaultMapModel();
    LatLng coord = new LatLng(40.74634, 30.67725);
    LatLng coord1 = new LatLng(35.74634, 30.67725);

    simpleModel.addOverlay(new Marker(coord, "Konyaalti", "zelenjava.png"));
    simpleModel.addOverlay(new Marker(coord1, "Konyaalti","zelenjava.png"));
    return simpleModel;
}

0 个答案:

没有答案