Skip to content
Advertisement

Change icon back to default state after infoWindow closed Google Maps

So my goal here is to make the icon go from the “normalIcon” state to the “activeIcon” state on button click, which it currently does. It opens an infoWindow when the pin is clicked as well. I want the icon to go back to the “normalIcon” state when the infoWindow is closed. Right now, if you click on a different location it changes the icon back to the “normalIcon” but you have clicked on another icon which is now the “activeIcon”

Here is the javascript I have:

JavaScript

I have tried using infowindow.close like so

JavaScript

but that disables it completely. I feel like I am close but not quite there. Anyone have a quick fix?

Advertisement

Answer

If you want the icon to change when the InfoWindow is closed, add a listener to the InfoWindow for the closeclick event:

closeclick
function()
Arguments: None
This event is fired when the close button was clicked.

JavaScript

proof of concept fiddle

code snippet:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement