2

我确实将圆圈与标记绑定以使视图如下:

在此处输入图像描述

但是当我尝试从地图上删除标记时,圆圈仍然存在。唔,

如何删除带圆圈的标记?

相关代码:

 function removeMarker(){
    if(selectedMarker)
       selectedMarker.setMap(null);      
}

....

function createCircle()
{
                var circle = {
                strokeColor: "#006DFC",
                strokeOpacity: 0.4,
                strokeWeight: 2,
                fillColor: "#006DFC",
                fillOpacity: 0.15,
                map: mapA,
                center: selectedMarker.getPosition(),
                radius: 50 // in meters
            };
            var cityCircle = new google.maps.Circle(circle);    


            cityCircle.bindTo('center', selectedMarker, 'position');
}

任何建议,将不胜感激。

谢谢,

4

1 回答 1

3

如果要在删除标记时删除圆圈,则还需要将其删除。

 cityCircle.setMap(null);

您需要保留对圆圈的引用才能做到这一点(未经测试):

function removeMarker(){
  if(selectedMarker)
    selectedMarker.setMap(null); 
    selectedMarker._mycityCircle.unbindAll();
    selectedMarker._mycityCircle.setMap(null);  
}

....

function createCircle()
{
  var circle = {
    strokeColor: "#006DFC",
    strokeOpacity: 0.4,
    strokeWeight: 2,
    fillColor: "#006DFC",
    fillOpacity: 0.15,
    map: mapA,
    center: selectedMarker.getPosition(),
    radius: 50 // in meters
  };

  cityCircle.bindTo('center', selectedMarker, 'position');
  selectedMarker._mycityCircle = cityCircle;
}
于 2012-12-22T20:21:46.500 回答