Changing gmap marker icons while onclick
Is there any way to change gmap marker icon while onclick and get back its original icon while clicking another marker or map. Suppose, In my gmap, I'm showing events in different colors(icon's). while clicking a marker the icon should change to yellow and should get back its o开发者_如何转开发riginal color when clicking another marker on the map.
Check out the WhackAMole game demo.. it demonstrates the concept.. and the use of the setImage() method for GMarker.
http://googlemapsapi.blogspot.com/2007/03/v275-gmarkersetimage-and-mole-whack.html
Duncan
Please take a look:
let selectedMarker;
google.maps.event.addListener(marker, 'click', function() {
if (selectedMarker) {
selectedMarker.setIcon('https://www.test.com/img/regular-marker.png');
}
marker.setIcon('https://www.test.com/img/new-marker.png');
selectedMarker = marker;
});
精彩评论