当用户单击 PrimeFaces GMap 时,我正在尝试绘制一条折线。
折线已经在 GMap 中绘制,但地图总是在用户点击时重新加载。
如果我使用 JavaScript 绘制折线,我可以防止 GMap 重新加载。
有没有办法在不使用 JavaScript 的情况下做到这一点?
<p:remoteCommand name="rcSendPoint" actionListener="#{indexBacking.onPointSelect()}" update="gmap"/>
<p:gmap id="gmap"
widgetVar="gmap"
center="-6.9243586, 107.6202013"
zoom="20" type="HYBRID"
model="#{indexBacking.model}"
style="width:100%;height:400px"
onPointClick="drawPolyline(event);"/>
</h:form>
<script type ="text/javascript">
var point = null;
function drawPolyline(event) {
if (point === null) {
rcSendPoint([{name: 'latitude', value: event.latLng.lat()}, {name: 'longitude', value: event.latLng.lng()}]);
}
}
</script>
public void onPointSelect() {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
lat = Double.valueOf(params.get("latitude"));
lng = Double.valueOf(params.get("longitude"));
polyline.getPaths().add(new LatLng(lat, lng));
model.addOverlay(polyline);
}