More advanced stuff

Google Maps API Tutorial

Context Menus for Overlays

Although there is an undocumented “singlerightclick” event for markers and some other overlays, it’s safer to use the documented map “singlerightclick” event because undocumented features could be changed or removed in future API releases without notice.

When using the map “singlerightclick” event to handle overlays we need to examine the third argument that gets returned. This argument indicates the overlay on which the click occurred.

You might want to display different options depending on the type of overlay that was clicked. You can test the type of overlay like if (overlay instanceof GMarker) {…}

At present, if a right click occurs on an infowindow, no “singlerightclick” event is generated.

Any variables that are going to be needed by the menu functions need to be held in global variables, because clicks on the menu are executed in global context. In particular, that means that we need to store a global reference to the overlay on which we opened the menu.

Advertisements