在primefaces中,封装了google map组件,使用非常方便。
1,在页面中(如xhtml)引入google map的JS
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
2,在页面使用gmap标签
<p:gmap id="gmap" center="#{storeManagerAction.latLngStr}" zoom="13"
type="HYBRID" model="#{storeManagerAction.draggableModel}"
style="width:600px;height:400px">
<p:ajax event="markerDrag"
listener="#{storeManagerAction.onMarkerDrag}" update="growl" />
</p:gmap>
3,后台Bean中属性方法定义
private MapModel draggableModel;
public void onMarkerDrag(MarkerDragEvent event)
{
Marker marker = event.getMarker();
store.setLatitude(marker.getLatlng().getLat());
store.setLongitude(marker.getLatlng().getLng());
}
在使用<p:gmap标签时,它有一个type属性,该属性取值范围如下:
ROADMAP,用于显示默认的道路地图视图
SATELLITE,用于显示 Google 地球卫星图片
HYBRID,用于同时显示普通视图和卫星视图
TERRAIN,用于根据地形信息显示实际地图。
本文介绍如何在PrimeFaces中使用Google Maps组件。首先通过引入JS文件加载地图API,然后利用<p:gmap>标签配置地图的基本属性,如中心点、缩放级别等。此外,还介绍了如何在Bean中实现拖动标记的功能。
811

被折叠的 条评论
为什么被折叠?



