I have an addListener click method for markers on a Google Map (in the setMarkers function):
var infowindow = null;
$(document).ready(function () { initialize(); });
function initialize() {
var centerMap = new google.maps.LatLng(39.828175, -98.5795);
var myOptions = {
zoom: 4,
center: centerMap,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
setMarkers(map, sites);
infowindow = new google.maps.InfoWindow({
content: "loading..."
});
var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);
}
var sites = [
['Mount Evans', 39.58108, -105.63535, 4, 'This is Mount Evans.'],
['Irving Homestead', 40.315939, -105.440630, 2, 'This is the Irving Homestead.'],
['Badlands National Park', 43.785890, -101.90175, 1, 'This is Badlands National Park'],
['Flatirons in the Spring', 39.99948, -105.28370, 3, 'These are the Flatirons in the spring.']
];
function setMarkers(map, markers) {
var myContentDiv = document.getElementById('myDivID');//Reference to you DOM elem
for (var i = 0; i < markers.length; i++) {
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
html: sites[4]
});
var contentString = "Some content";
//marker.xtraData = 'SomeExtraData';//You can even add more data this way
google.maps.event.addListener(marker, "click", function () {
//alert(this.html);
var myTemplate = '<h1>'+this.title+'<h1><p>'+this.html+'</p>';
myContentDiv.innerHTML = myTemplate;//Inset this html inside link
//infowindow.setContent(this.html);
//infowindow.open(map, this);
});
}
}
What I’m looking to do is change the “active” marker to a different image. I did see google.maps.MarkerImage class but when all of my attempts so far have replaced “a” marker (not the one I selected) with the URL, but then the marker doesn’t convert back to normal on the next click (or close of the info box). I feel like I’m pretty close, but am pretty stuck in the mud at the moment. Any help would be greatly appreciated. Thanks!
Here is my example (ported from Mike Williams’ v2 tutorial):
http://www.geocodezip.com/v3_MW_example_hoverchange.html
One way to do it (jsfiddle from your last question, updated):
http://jsfiddle.net/geocodezip/r7fu3a1y/1/
working code snippet: