如何从地图上删除带有圆圈的标记? [英] How can I remove marker with bonded circle from the map?

查看:111
本文介绍了如何从地图上删除带有圆圈的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实用标记将圆圈绑定起来,使得像这样的视图:

I did bind the circle with marker to make view like:

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

But when I try to remove marker from the map, the circle still exists. Hmm,

如何删除带有圆圈的标记?

How can I remove marker with circle?

相关代码:

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

任何建议将不胜感激.

谢谢

推荐答案

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

If you want to remove the Circle when you remove the marker, you need to remove it also.

 cityCircle.setMap(null);

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

You will need to keep a reference to the circle to do that (not tested):

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

这篇关于如何从地图上删除带有圆圈的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆