Google Maps API Tutorial© 2008, 2009 Mike Williams
|Translate this page:|
Here's an example
Warning: This trick relies on undocumented details of the GGeoXml behaviour. It may well fail to work in future releases.
When GGeoXml adds overlays to a map, an "addoverlay" event is triggered. It's possible to catch that event, extract information about that overlay, and build a sidebar.
This is possible because GGeoXml adds extra accessible properties to the overlays that it creates. These properties currently are:
Overlay managementGGeoXml now performs some sort of crude overlay management on the overlays it creates. This causes the overlays to be removeOverlay()ed when they leave the viewport and addOverlay()ed again when they re-enter the viewport. We need to be careful not to add an extra side bar entry for the overlay each time it re-enters the viewport.
In my example, I add my own extra property to the overlay to remember that I already know about the overlay.
Sidebar orderGGeoXml adds the overlays in random order. If you need the overlays to appear in alphabetical order of name, then you have to sort them yourself.
Long SidebarThere's no indication of whether a particular overlay is the last one in the KML file. This means that the usual technique of building the sidebar HTML until the last entry has been processed won't work. In my example, I add each sidebar entry one by one. If there are large numbers of overlays, this becomes inefficient, since the browser has to re-render the sidebar div after each entry has been added.
I can't think of any nice way around this, unless you happen to know how many overlays your KML file contains.
Intercepting infowindow contentAnother trick that you might want to perform with GGeoXml is to modify the content of the infowindows that it manages. For example you might want to add a "get directions" facility at the bottom, or you might want to have active content in the info window.
It turns out that modifying overlay.description doesn't modify the contents of the infowindow. The data must be being stored somewhere else before the "addoverlay" event gets triggered.
What you can do is to listen for the undocumented map "infowindowprepareopen" event, and modify the content of the GInfoWindowTab that it passes as a parameter.
In my example I simply add an extra line of text at the bottom of the infowindow contents.
You could place deactivated content in a KML file, perhaps using [ and ] instead of < and >, so that GGeoXml will allow the text to pass through, and then replace those characters as the infowindow opens.