[英]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 : 通常的用户交互是这样的:
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! 看起来
bean
和p: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):
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.