由于google maps v3不支持多边形或折线的开始或结束编辑,因此我正在尝试构建自己的多边形或折线。
我正在为每个点绘制标记,然后为了完成编辑,我将所有标记设置为在第一个索引点("0")被单击时隐藏,然后将多边形设置为clickable为true。但是用户仍然可以单击地图并继续绘制多边形。我想禁用该事件侦听器,但在鼠标悬停时重新启用它。这可以做到吗?如果我使用Remove Listener,我可以在鼠标悬停时将另一个listener重新附加到多边形上,以便他们可以编辑它吗?
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});
}
});发布于 2011-03-10 02:27:43
您可以对全局变量执行几乎相同的操作,如下所示:(并设置disableListener =true以禁用它)
var disableListener = false;
google.maps.event.addListener(marker, 'click', function() {
if (disableListener)
return;
if (!marker.index == 0)
marker.setMap(null);
}https://stackoverflow.com/questions/4866755
复制相似问题