fillColor
is a property of Icon
, not Marker
, so calling marker.setOptions({fillColor: '0000ff'})
won't work.
Either call setOptions marker.setOptions({icon: {icon props...}})
or marker.setIcon({icon props...})
To avoid having the icon definitions all over the place, you can stick them in variables:
var icon = {
path: google.maps.SymbolPath.CIRCLE,
fillOpacity: 0.5,
fillColor: 'ff0000',
strokeOpacity: 1.0,
strokeColor: 'fff000',
strokeWeight: 3.0,
scale: 20
};
// same as icon but with different fillColor
// could use jQuery.extend({}, icon, {fillColor: '0000ff'}) to clone instead
var iconSelected = {
path: icon.path,
fillOpacity: icon.fillOpacity,
fillColor: '0000ff',
strokeOpacity: icon.strokOpacity,
strokeColor: icon.strokeColor,
strokeWeight: icon.strokeWeight,
scale: icon.scale
};
var marker = new google.maps.Marker({
map: map,
position: location,
icon: icon
});
Then switch the icon on click:
google.maps.event.addListener(marker, 'click', function() {
this.setIcon(iconSelected);
});
This is just using the API directly, not gmap3, but I'm sure you get the idea.
Here is a working fiddle to demonstrate. It also has a solution to change the previously selected marker color back.