Javascript 谷歌地图API 3-绑定后删除圆圈
我一辈子都搞不明白为什么Javascript 谷歌地图API 3-绑定后删除圆圈,javascript,jquery,google-maps-api-3,Javascript,Jquery,Google Maps Api 3,我一辈子都搞不明白为什么setMap(null)不起作用。我真的很不高兴有这么多关于使用bindTo添加覆盖的文档,但没有一个关于如何删除它的单词。我做错了什么 我正在上创建圆。半径\u类型单击。然后,当我将下拉菜单切换到其他形状时,它不会删除圆 我这样称呼地图: var map = new google.maps.Map(document.getElementById('map'), {...} // this toggles the shapes, but I can't get it t
setMap(null)
不起作用。我真的很不高兴有这么多关于使用bindTo添加覆盖的文档,但没有一个关于如何删除它的单词。我做错了什么
我正在上创建圆。半径\u类型
单击。然后,当我将下拉菜单切换到其他形状时,它不会删除圆
我这样称呼地图:
var map = new google.maps.Map(document.getElementById('map'), {...}
// this toggles the shapes, but I can't get it to remove the circle for the marker
$('.radius_type.selectee').click(function(){
var shape = $(this).find('span').html();
var opts= {...};
switch(shape){
case 'circle': // Here is the added circle to the second marker.
var circle = new google.maps.Circle(opts);
circle.setOptions({radius:17063,map:map});
circle.bindTo('center',markers[1],'position');
// It binds, now how to remove it?
break;
case 'square':
//tried - circle.setMap(null);
//tried - map.setMap(null);
//tried - google.map.event.setMap(null);
//tried - every web page on the topic.
//
// I don't understand how to unbind the circle from the marker.
var rect = new google.maps.rect(opts);
break;
case 'draw':
draw.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
break;
}
});
使用
$('element')。在('change',function())
上删除圆圈您可以尝试以下代码段:
circle.setCenter(null);
circle.unbind('center');
请回答您的问题,在强制性等待期过后,选择正确答案。这就结束了你的问题,而不会危及自动驾驶仪。我在你的答案中添加了代码格式,以提高可读性。在代码中添加了关于为什么以及如何工作的解释。