簡體   English   中英

db單擊時顯示/隱藏圓圈

[英]Show/Hide Circle when dbClick on the marker

在問這個問題之前,我已經進行過網絡搜索。

當我雙擊帶有此功能的標記時,當前正在繪制一個圓:

  function drawRadius(marker, map){
      google.maps.event.addListener(marker, "dblclick", function () {
           circle = new google.maps.Circle({
            map: map,
            fillColor : '#3333FF',
            fillOpacity : 0.5,
            radius : 10000,
            strokeColor : '#BBD8E9',
            strokeOpacity : 0.9,
            strokeWeight : 2
          });
          circle.bindTo('center', marker, 'position');
      });       
  }

這是完整的代碼: http : //jsfiddle.net/rjhzq/1/

問題是當我雙擊標記時,我想顯示或隱藏圓圈。

我已經嘗試過if (circle!=null){circle.setMap(null);}

但是問題是我在創建標記后立即調用了函數drawCircle。

謝謝您的幫助

您可以將變量添加到標記中,以保留要添加的circle的參考。
就像是:

// If your marker has a circle, remove it and remove the reference to it.
if (marker.circle) {
    marker.circle.setMap(null);
    marker.circle = null;
    return;
}
circle = new google.maps.Circle({
    map: map,
    fillColor: '#3333FF',
    fillOpacity: 0.5,
    radius: 10000,
    strokeColor: '#BBD8E9',
    strokeOpacity: 0.9,
    strokeWeight: 2
});
circle.bindTo('center', marker, 'position');
marker.circle = circle; // Add circle to marker as reference

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM