I use a google Map to collect point data, that is saved to a Postgis database. With dblclick the user adds a marker, that is draggable and has a listener that opens (onclick) a modal dialog window to enter additional data. When the data is saved to the database (via php-script), the standard marker is replaced by a marker that reflects the type of point acquired. The user can than add the next point.
All this works fine, I only have the problem, that the dblclick-event can be fired a few times, so that the user gets confused with several new markers.
The addListenerOnce doesn't help me since the user usually needs to add a bunch of new points. Also this old post didn't help googlemaps-v3-api-create-only-1-marker-on-click since it is intended to only use ONE point.
How can I prevent the dblclick-event to add new markers, as long, as the first one isn't saved?
var marker;
var modalOnClick;
//Add listener to map, to insert new Marker with modal
google.maps.event.addListener(map, "dblclick", function(event){
marker = new MarkerWithLabel ({
position: event.latLng,
map: map,
icon:mmcross,
draggable: true,
labelContent: '',
labelAnchor: new google.maps.Point(15,33),
labelClass: "labels", // the CSS class for the label
labelInBackground: false
});
map.setCenter(event.latLng);
//Open Modal Form to insert data
modalOnClick = google.maps.event.addListener(marker, 'click', function() {
$('#myModal').modal('show');
});
});
// Function to save data
function saveData(){
...
$('#myModal').modal('hide');
google.maps.event.removeListener(modalOnClick);
}; // END saveData()
google.maps.event.addListenerOnce
, but I only can insert one marker. Is there a way to reset this listener e.g. at the end of my saveData() function? so that the user can continue adding new points.