2011-02-01 39 views
7

Vì bản đồ google api v3 không hỗ trợ chỉnh sửa bắt đầu hoặc kết thúc của đa giác hoặc đa giác, tôi đang cố gắng tạo thành một hình ảnh của riêng mình.bạn có thể vô hiệu hóa một người theo dõi sự kiện mà không xóa nó?

Tôi đang vẽ điểm đánh dấu cho mỗi điểm, sau đó kết thúc chỉnh sửa Tôi đặt tất cả điểm đánh dấu để ẩn khi điểm chỉ mục đầu tiên ("0") được nhấp, sau đó đặt đa giác thành có thể nhấp là đúng. Nhưng người dùng vẫn có thể nhấp vào bản đồ và tiếp tục vẽ đa giác. Tôi muốn vô hiệu hóa danh sách sự kiện đó nhưng kích hoạt lại nó trên chuột. Điều này có thể được thực hiện? Nếu tôi sử dụng Trình xóa danh sách, tôi có thể gắn lại một người theo dõi khác vào đa giác khi di chuột qua để họ có thể chỉnh sửa nó không?

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}); 
      } 
     }); 

Trả lời

9

Bạn có thể làm được khá nhiều điều tương tự với một biến toàn cầu, như vậy: (và thiết lập disableListener = true; để vô hiệu hóa nó)

var disableListener = false; 
google.maps.event.addListener(marker, 'click', function() { 
    if (disableListener) 
     return; 
    if (!marker.index == 0) 
     marker.setMap(null); 
} 
+0

+1 giải pháp rất đẹp –

Các vấn đề liên quan