I'm using the Google Maps API to build a map full of markers, but I want one marker to stand out from the others. The simplest thing to do, I think, would be to change the color of the marker to blue, instead of red. Is this a simple thing to do or do I have to create a whole new icon somehow? If I do have to create a new icon, what's the easiest way to do that?
Check this out (which you probably have seen):
http://code.google.com/apis/maps/documentation/overlays.html#Icons_overview
You would have one set of logic do all the 'regular' pins, and another that does the 'special' pin(s) using the new marker defined.
One way is to use the MapIconMaker. There's an example here. Google Maps default icons are 20px width and 34px height, so you could use something like this to emulate:
var newIcon = MapIconMaker.createMarkerIcon({width: 20, height: 34, primaryColor: "#0000FF", cornercolor:"#0000FF"});
var marker = new GMarker(map.getCenter(), {icon: newIcon});
You could even wrap it in some function to make things even easier on yourself:
function getIcon(color) {
return MapIconMaker.createMarkerIcon({width: 20, height: 34, primaryColor: color, cornercolor:color});
}
That's what I personally use for all markers I create. I prefer to have the option to change colors of a whim.
Update: The Hex color of the default icon is "#FE7569". Also, you can setImage on a Marker rather than creating a new Marker with a new icon. So if you want a function to highlight you could go with something like this, using the function above:
function highlightMarker(marker, highlight) {
var color = "#FE7569";
if (highlight) {
color = "#0000FF";
}
marker.setImage(getIcon(color).image);
}