Я использую инструмент карты Google из primefaces .
Я хочу, чтобы мой пользователь мог разместить только один маркер на карте.
Значения координат должны храниться в переменных управляемого компонента.
Как я могу это сделать?
Посмотрите, что я сделал до сих пор:
Я создал карту:
<f:view contentType="text/html">
<p:gmap id="gmap" center="36.890257,30.707417" zoom="13" type="HYBRID"
style="width:600px;height:400px"
model="#{mapBean.emptyModel}"
onPointClick="handlePointClick(event);"
widgetVar="map" /> </f:view>
<p:dialog widgetVar="dlg" effect="FADE" effectDuration="0.5" close="false" fixedCenter="true">
<h:form prependId="false">
<h:panelGrid columns="2">
<h:outputLabel for="title" value="Title:" />
<p:inputText id="title" value="#{mapBean.title}" />
<f:facet name="footer">
<p:commandButton value="Add"
actionListener="#{mapBean.addMarker}"
update="messages"
oncomplete="markerAddComplete()"/>
<p:commandButton value="Cancel" onclick="return cancel()"/>
</f:facet>
</h:panelGrid>
<h:inputHidden id="lat" value="#{newOfferSupportController.mapLocationX}" />
<h:inputHidden id="lng" value="#{newOfferSupportController.mapLocationY}" />
</h:form>
</p:dialog>
<script type="text/javascript">
var currentMarker = null;
function handlePointClick(event) {
if(currentMarker == null) {
document.getElementById('lat').value = event.latLng.lat();
document.getElementById('lng').value = event.latLng.lng();
currentMarker = new google.maps.Marker({
position:new google.maps.LatLng(event.latLng.lat(), event.latLng.lng())
});
map.addOverlay(currentMarker);
dlg.show();
}
}
function markerAddComplete() {
var title = document.getElementById('title');
currentMarker.setTitle(title.value);
title.value = "";
currentMarker = null;
dlg.hide();
}
function cancel() {
dlg.hide();
currentMarker.setMap(null);
currentMarker = null;
return false;
}
</script>
Я также смазал переменные, которые будут содержать координаты:
@ManagedBean
@RequestScoped
public class NewOfferSupportController {
private float mapLocationX;
private float mapLocationY;
//Get & set methods
Все это работает так же, как и в простых страница , но у меня есть 2 проблемы:
Проблема 1: После того, как маркер установлен, его нельзя разместить снова.
Проблема 2: В той же форме, где находится карта, есть некоторые другие элементы, такие как текстовые поля. Я заметил, что проверка не происходит, когда я нажимаю на кнопку отправки, расположенную в форме, где находится карта. На самом деле форма вообще не отправляется (это не происходило до того, как я добавил карту), почему карта разрушается проверка?
![enter image description here](https://i.stack.imgur.com/qRwdt.png)