【发布时间】:2012-02-26 12:57:27
【问题描述】:
使用 PrimeFaces p:gmap 组件。
我有一个带有带有一组标记的 gmap 组件的页面。
我想在 gmapInfoWindow 中显示街道地址并将其传递给支持 bean。
当我点击地图标记时,我调用一个 javascript 函数来获取反向地理编码器地址。
我可以获取地址并将其显示在 javascript 警报对话框中,但我无法让它填充支持 bean 变量或信息标记。
变量确实被填充了,但直到我下次单击标记时才会更新。 因此,地址总是落后一个标记。
有谁知道我如何在当前页面会话期间获取要更新的地址? 谢谢。
MapMarkerSelect 的支持 bean 代码只有一个 System.out.println 语句来显示 mapAddress 变量。
这是页面代码:
<h:form prependId="false" >
<p:gmap id="gmap" center="#{mappingSessionBean.mapCenter}" zoom="#{mappingSessionBean.mapZoom}" type="HYBRID" rendered="true"
style="#{mappingSessionBean.polygonGmapStyle}" onPointClick="handlePointClick(event);"
model="#{mappingSessionBean.mapModel}" fitBounds="#{mappingSessionBean.fitBoundsFlag}"
widgetVar="map" >
<p:ajax id="gmapAjax" event="overlaySelect" immediate="true" onstart="handlePointClick(event);" listener="#{mappingSessionBean.onMapMarkerSelect}" />
<p:gmapInfoWindow id="infoWindow" >
<p:outputPanel >
<h:panelGrid columns="1" >
<h:outputText id="infoWindowTitle" value="#{mappingSessionBean.selectedMarker.title}" />
<h:outputText id="infoWindowAddress" value="#{mappingSessionBean.mapAddress}" rendered="true" />
<p:commandButton value="Zoom In" action="#{mappingSessionBean.selectedViewInfoListener}" update="gmap" />
</h:panelGrid>
</p:outputPanel>
</p:gmapInfoWindow>
</p:gmap>
<h:inputHidden id="address" value="#{mappingSessionBean.mapAddress}" />
</h:form >
<script type="text/javascript" >
function handlePointClick(event) {
if(navigator.geolocation)
{
browserSupportFlag = true;
var latlng = event.latLng;
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if( status == google.maps.GeocoderStatus.OK )
{
alert( results[0].formatted_address );
document.getElementById('address').value = results[0].formatted_address;
document.getElementById('infoWindowAddress').value = results[0].formatted_address;
}
else
{
alert( "Geocoder failed due to: " + status );
}
});
}
else
{
alert( "No Geolocation");
}
}
</script>
【问题讨论】:
标签: jsf-2 primefaces