我确实用标记绑定了圆圈,使其成为:
但是当我尝试从地图中删除标记时,圆圈仍然存在。嗯,
如何删除带圆圈的标记?
相关代码:
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');
}
任何建议都将不胜感激。
谢谢,
答案 0 :(得分: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;
}