Since google maps api v3 doesn't support start or end editing of a polygon or polyline I am trying to construct one of my own.
I am drawing markers for each point, then to finish editing I set all marker to hide when the first index point ("0") is clicked then set the polygon to clickable is true. But the user can still click the map and continue drawing the polygon. I want to disable that event listener but re-enable it on mouse over.. Can this be done? If I use Remove Listener can I reattached another listener to the polygon on mouseover so they can edit it?
MapShaper.Feature.prototype.poly = function(type) {
var color = MapShaper.getColor(false),
path = new google.maps.MVCArray,
poly,
self = this,
el = type + "_b";
if(type=="shape"){
poly = self.createShape( {strokeWeight: 3, fillColor: color}, path );
}else if(type=="line"){
poly = self.createLine( {strokeWeight: 3, strokeColor: color }, path );
}
poly.markers = new google.maps.MVCArray;
google.maps.event.addListener(poly, "mouseover", function(){
poly.markers.forEach(function(polyMarker, index){
polyMarker.setVisible(true);
});
});
MapShaper.Feature.prototype.createShape = function(opts, path) {
var poly;
poly = new google.maps.Polygon({
clickable:false,
strokeWeight: opts.strokeWeight,
fillColor: opts.fillColor
});
poly.setPaths(new google.maps.MVCArray([path]));
return poly;
}
MapShaper.Feature.prototype.createShape = function(opts, path) {
var poly;
poly = new google.maps.Polygon({
clickable:false,
strokeWeight: opts.strokeWeight,
fillColor: opts.fillColor
});
poly.setPaths(new google.maps.MVCArray([path]));
return poly;
}
google.maps.event.addListener(marker, 'click', function() {
if (!marker.index == 0) {
marker.setMap(null);
markers.removeAt(marker.index);
path.removeAt(marker.index);
MapShaper.reindex(markers);
if(markers.getLength() == 0){
MapShaper.removeFeature(poly.id);
}
} else {
markers.forEach(function(marker, index) {
marker.setVisible(false)
});
poly.setOptions({clickable: true});
}
});
You can do pretty much the same thing with a global variable, like so: (and set disableListener = true; to disable it)
var disableListener = false;
google.maps.event.addListener(marker, 'click', function() {
if (disableListener)
return;
if (!marker.index == 0)
marker.setMap(null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With