Reputation: 353
I've been stuck on this for quite a while, so I would really appreciate some insight.
I'm trying to show the (two) Circles and an InfoWindow of a Marker on a click event, and then hide them when you click on it again. The second click event doesn't work. It shows me the stuff on click, but instead of hiding it on the second, it just loads the Circles and InfoWindow again.
Here's my code:
// Toggle Radii and InfoWindow — You can run, but you can't hide?
google.maps.event.addListener(marker, 'click', function() {
if ( ccArray[i].setMap() == null || iwcArray[i].setMap() == null ) {
// First Click
infowindow.open(map,marker);
ccArray[i].setMap(map);
iwcArray[i].setMap(map);
} else {
// Second Click
alert('You can hide, so just do it.');
infowindow.open(null,marker);
ccArray[i].setMap(null);
iwcArray[i].setMap(null);
}
});
Any ideas?
Upvotes: 1
Views: 460
Reputation: 1725
"if ( ccArray[i].setMap() == null || iwcArray[i].setMap() == null ) {
"
ccArray and iwcArray contain google.maps.Circle objects.
google.maps.Circle.setMap() is a function that returns nothing, setMap is used only to set the map property of the circle, not get it. So I suspect that your code will always pass the test and never fall through to the else clause.
Are you sure you don't want to use ccArray[i].getMap() and iwcArray[i].getMap() ?
(see https://developers.google.com/maps/documentation/javascript/reference#Circle
Upvotes: 1