问题
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?
Relevant code:
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');
}
Any suggestions would be appreciated.
Thanks,
回答1:
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;
}
来源:https://stackoverflow.com/questions/14006156/how-can-i-remove-marker-with-bonded-circle-from-the-map