Google Maps API Tutorial© 2006, 2007, 2008, 2009 Mike Williams |
Translate this page: |
Making your own custom markersTo make custom markers, you'll need a graphics program that supports partially transparent PNG images.I've used Paint Shop Pro 8. In that program there's just one special thing to watch out for: don't use "save", use the PNG optimiser and specify "Alpha Channel Transparency". To create a custom shadow, take a copy of your marker, change all the opaque points to black, reduce the opacity to about 50%, skew the image by about 45 degrees and add some blur. I've also used POV-Ray to create custom 3d markers. Use the switches "+ua +fn" to create a partially transparent png file. To create a shadow image in POV-Ray, I applied the keyword "noimage" to my marker object, and allowed the shadow to fall on a tilted plane plane {y,0 pigment {rgb 2} rotate -x*45}In this case it's not possible to make the plane transparent directly from POV-Ray, the white plane needs to be removed with a suitable image editor. GIcon.transparentTo create a transparentImage for your custom marker, simply load the marker image into an image editor, change the opacity to 1% and export the result as a 24-bit partially transparent PNG. The transparentImage allows the marker to correctly respond to clicks and mouseover events in IE when the marker is under a shadow. You can omit the transparentImage, in which case clicks and mouseovers will not work correctly for icons that are in shadow.GIcon.imageMapTo get shadowed markers to correctly respond to clicks in other browsers, you need to create an imageMap. That's a lot trickier, and I'm not going to cover that in this tutorial.GIcon.printImage and GIcon.mozPrintImageMost browsers can't print partially transparent PNG images. Google has provided the option to provide printable GIF images instead. If you want your markers to be printable you can create the required GIF images by converting your PNG images to GIF format. For the GIcon.printImage Google a GIF with transparency that matches that of the PNG image. For GIcon.mozPrintImage Google use a non-transparent GIF with the background set to a pale grey.In my experiments, Firefox seems to print the transparent GIFs just as well as the non-transparent ones, it just ignores the transparency when printing. If you omit the GIcon.printImage and GIcon.mozPrintImage settings, then IE6 will print the main PNG images of the markers (ignoring the transparency) but Firefox will omit the markers from the print. GIcon.printShadowIf you want shadows to be printed you need to provide a GIF image for this parameter. GIF images don't support partial transparency, but it is possible to dither the image, like this dithshadow.gif image used by Google![]() Third Party MarkersIf you don't want to draw your own markers, you can find some markers that other people have made.There's a list of available marker sets here: http://mapki.com/index.php?title=Icon_Image_Sets Setting the GIcon parameters
In both cases, the values count from the top left corner which is considered to be the point (1,1). This may well be different from what you see in an image editing program, where the top left pixel is usually considered to be (0,0). Positioning the infoWindowAnchor is an art rather than a science. You can see when it looks wrong but there doesn't seem to be any formula that will produce the result that looks right.
Required parametersThey're not actually mandatory. There are certain strange circumstances in which you might want to omit almost any parameter, but you should think carefully before omitting any of these parameters:
Graham's Custom Marker MakerIf you don't want to go through all the bother of doing that yourself, then simply create the main image file and pass it to Graham's Custom Marker Maker www.powerhut.co.uk/googlemaps/custom_markers.php. You get back a zip file that contains files for all the other parts of the GIcon and some sample code with all the parameter settings. |