简体   繁体   English

Primefaces GMap,如何在pointSelect事件后更新缩放

[英]Primefaces GMap, How to update zoom after pointSelect Event

I have ap:gmap component. 我有ap:gmap组件。 It gets the zoom attribute from a bean, and adds a Marker on pointSelect 它从bean获取zoom属性,并在pointSelect上添加Marker

The usual User interaction is like this : 通常的用户交互是这样的:

  1. User zooms in, to find his desired Location 用户放大,找到他想要的位置
  2. User Clicks on map 用户点击地图
  3. Map reloads with a Marker right on the point where she clicked 使用标记重新加载地图,直到她点击的位置

My only problem is that after the map refresh, the map is zoomed out, as the zoom attribute is not getting updated 我唯一的问题是,在地图刷新后,地图会缩小,因为缩放属性没有得到更新

p:gmap code looks like this p:gmap代码看起来像这样

<p:gmap
    binding="#{mapBean.gmap}"
    zoom="#{mapBean.zoom}"
    model="#{mapBean.poiMapModel}"
    widgetVar="poiMap"
    id="poiMapComponent"        
    >
    <p:ajax event="pointSelect" 
        listener="#{mapBean.onPointSelect}"  
        update=":#{p:component('poiMapComponent')}"
    />  
</p:gmap>

MapBean's relevant Code is : MapBean的相关代码是:

public void onPointSelect(PointSelectEvent event) {  

        LatLng latlng = event.getLatLng();  


        int _zoom = this.getGmap().getZoom(); //This never gets changed
        System.out.println("NEW ZOOM = " + _zoom);

        //Creating a new Marker in the clicked area
        selectedMarker = new Marker(latlng, "");
        poiMapModel.addOverlay(selectedMarker);
    }


    public org.primefaces.component.gmap.GMap getGmap() {
        return gmap;
    }
    public void setGmap(org.primefaces.component.gmap.GMap gmap) {
        this.gmap = gmap;
    }

After some testing, I'm sure that the MapBean.setZoom() is never getting called. 经过一些测试,我确信MapBean.setZoom()永远不会被调用。

As you can see, I even tried binding the component back to the bean, so I Could get the p:gmap's current zoom value. 如您所见,我甚至尝试将组件绑定回bean,因此我可以获得p:gmap的当前缩放值。 But it seems that the PointSelect event always resets the zoom value. 但似乎PointSelect事件总是重置zoom值。 I can't find a way to process the changed zoom whatsoever. 我无法找到一种处理变焦变焦的方法。

It seems like there's a one-way communication between the bean and the p:gmap component! 看起来beanp:gmap组件之间存在单向通信

My question is : Is there any way to detect zoom changes and get the updated value? 我的问题是:有没有办法检测缩放变化并获得更新值? Have the p:gmap updating the bean's zoom attribute p:gmap更新bean的zoom属性

The p:gmap event API has four events (user guide 4.0 ed.2.2 p.214): p:gmap事件API有四个事件(用户指南4.0 ed.2.2 p.214):

  1. markerDrag : Get dragged marker instance markerDrag:获取拖动的标记实例
  2. overlaySelect : Get selected overlay instance overlaySelect:获取选定的叠加实例
  3. pointSelect : Get coordinates of selected point pointSelect:获取所选点的坐标
  4. stateChange : Get boundaries of map / zoom level of map stateChange:获取地图的地图/缩放级别的边界

So you can get the zoom level with 所以你可以用它来获得缩放级别

<p:ajax event="stateChange" listener="#{mapBean.onStateChange}"/>

public void onStateChange(StateChangeEvent event) {  
   zoom = event.getZoomLevel();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM