我正在使用google.maps.Circle()方法创建一个圆。这一切都工作得很好,但是我如何删除这个圆圈呢?
我的代码:
var populationOptionsAgain = {
strokeColor: "#c4c4c4",
strokeOpacity: 0.35,
strokeWeight: 0,
fillColor: "#ffffff",
fillOpacity: 0.35,
map: map,
center: results[0].geometry.location,
radius: 40000
};
cityCircle = new google.maps.Circle(populationOptionsAgain);
发布于 2011-05-19 20:57:54
您需要将Circle对象上的setMap方法调用为null:
cityCircle.setMap(null);
发布于 2013-11-04 23:03:18
要从地图中删除圆,请调用将null
作为参数传递的setMap()
方法。
circle.setMap(null);
请注意,上面的方法不会删除圆。它只是将圆从地图中删除。如果您希望删除圆,则应将其从地图中删除,然后将圆本身设置为null
。
https://developers.google.com/maps/documentation/javascript/shapes#circle_remove
发布于 2016-03-09 18:56:22
您还需要删除事件侦听器,而不仅仅是隐藏圆圈,事实上circle.setMap(null)
只会隐藏圆圈
function remove_circle(circle) {
// remove event listers
google.maps.event.clearListeners(circle, 'click_handler_name');
google.maps.event.clearListeners(circle, 'drag_handler_name');
circle.setRadius(0);
// if polygon:
// polygon_shape.setPath([]);
circle.setMap(null);
}
https://stackoverflow.com/questions/6058904
复制相似问题