Javascript 单击标记时显示/隐藏圆
在问这个问题之前,我已经在网上搜索过了 当我双击带有此功能的标记时,我当前正在绘制一个圆:Javascript 单击标记时显示/隐藏圆,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,在问这个问题之前,我已经在网上搜索过了 当我双击带有此功能的标记时,我当前正在绘制一个圆: function drawRadius(marker, map){ google.maps.event.addListener(marker, "dblclick", function () { circle = new google.maps.Circle({ map: map, fillColor : '#3333F
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');
});
}
以下是完整的代码:
问题是,我想在双击标记时显示或隐藏圆
我已经试过了
if(circle!=null){circle.setMap(null);}
但问题是,我在创建标记后立即调用函数drawCircle
感谢您的帮助您只需在标记中添加一个变量,以保留添加到标记中的
圆圈的引用。
比如:
// 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
非常感谢普特凡德的帮助!