Resources

Google Maps API Tutorial

GEvents

Here’s a list of the accessible GEvent types.

Event Object Parameters
“addmaptype” GMap2, GMap map type
“addoverlay” GMap2, GMap overlay
“clearoverlays” GMap2, GMap
“click” GMap2, GMap overly, latlng, overlaylatlng
“dblclick” GMap2, GMap the first parameter is always null
The second parameter is the GLatLng
“drag” GMap2, GMap
“dragend” GMap2, GMap
“dragstart” GMap2, GMap
“infowindowbeforeclose” GMap2, GMap
“infowindowclose” GMap2, GMap
“infowindowopen” GMap2, GMap
“load” GMap2, GMap
“maptypechanged” GMap2, GMap
“move” GMap2, GMap
“moveend” GMap2, GMap
“movestart” GMap2, GMap
“mousemove” GMap2, GMap GLatLng
“mouseout” GMap2, GMap GLatLng
“mouseover” GMap2, GMap GLatLng
“removemaptype” GMap2, GMap map type
“removeoverlay” GMap2, GMap overlay
“resize” GMap2, GMap
“singlerightclick” GMap2, GMap 1. GLatLng() identifying the pixel position of the mouse within the map div.
2. URL of tile (if over the base map)
3. Map container if over the base map. Reference to the Gmarker if over a marker.
“zoomend” GMap2, GMap old zoom level, new zoom level
“zooming” GMap2, GMap
“zoomstart” GMap2, GMap direction (+1 = zoom in, -1 = zoom out)
latlng pivot
bool recentering
Event Object Parameters
“zoom” GMap old zoom level, new zoom level (v1 syntax)
Event Object Parameters
“newcopyright” GMapType copyright
Event Object Parameters
“newcopyright” GTileLayer copyright
Event Object Parameters
“newcopyright” GCopyrightCollection copyright
Event Object Parameters
“click” GMarker latlng of marker
“changed” GMarker marker, previous position
“dblclick” GMarker latlng of marker
“drag” GMarker latlng
“dragend” GMarker latlng
“dragstart” GMarker latlng
“infowindowbeforeclose” GMarker marker
“infowindowclose” GMarker marker
“infowindowopen” GMarker marker
“infowindowprepareopen” GMarker marker
“mousedown” GMarker latlng of marker
“mouseover” GMarker latlng of marker
“mouseout” GMarker latlng of marker
“mouseup” GMarker latlng of marker
“remove” GMarker
“visibilitychanged” GMarker true if the marker is now visible, else false
Event Object Parameters
“changed” GMarkerManager GBounds indicating active region in units of 1024×1024 pixels, number of active markers
Event Object Parameters
“cancelline” GPolyline
“click” GPolyline GLatLng of clicked location
“endline” GPolyline
“lineupdated” GPolyline
“mouseout” GPolyline
“mouseover” GPolyline
“remove” GPolyline
“visibilitychanged” GPolyline true if the poly is now visible, else false
Event Object Parameters
“cancelline” GPolygon
“click” GPolygon GLatLng of clicked location
“endline” GPolygon
“lineupdated” GPolygon
“mouseout” GPolygon
“mouseover” GPolygon
“remove” GPolygon
“visibilitychanged” GPolygon true if the poly is now visible, else false
Event Object Parameters
“moveend” GKeyboardHandler
“movestart” GKeyboardHandler
Event Object Parameters
“animate” [GInfoWindow] proportion of the animation that has been performed
“closeclick” [GInfoWindow]
“maximizeclick” [GInfoWindow]
“maximizeend” [GInfoWindow]
“restoreclick” [GInfoWindow]
“restoreend” [GInfoWindow]
Event Object Parameters
“click” GDraggableObject browser-specific event object
“dblclick” GDraggableObject browser-specific event object
“drag” GDraggableObject browser-specific event object
“dragend” GDraggableObject browser-specific event object
“dragstart” GDraggableObject browser-specific event object
“mouseup” GDraggableObject browser-specific event object
“mousedown” GDraggableObject browser-specific event object
“move” GDraggableObject
Event Object Parameters
“visibilitychanged” GScreenOverlay true if the overlay is now visible, else false
Event Object Parameters
“visibilitychanged” GGroundOverlay true if the overlay is now visible, else false
Event Object Parameters
“load” GGeoXml
Event Object Parameters
“changed” GTrafficOverlay true if the viewport contains traffic data
Event Object Parameters
“error” GStreetViewPanorama error code
“initialized” GStreetViewPanorama location object
“pitchchanged” GStreetViewPanorama pitch
“yawchanged” GStreetViewPanorama yaw
“zoomchanged” GStreetViewPanorama zoom
Event Object Parameters
“changed” GStreetViewOverlay true if the viewport contains StreetView data

Notes

  1. Watch out for those parameters. The same event can have different parameters with different objects.
  2. The GInfoWindow class isn’t directly accessible, but you can use GEvent.addListener(map.getInfoWindow(),”closeclick” …).
  3. The “closeclick” event is only triggered when the user actually clicks on the info window close icon, not for anything else that closes the info window.
  4. Watch out for the difference between the “zoom” event (GMap() only) which returns zoom levels in APIv1 format and the “zoomend” event which returns zoom levels in APIv2 format.
  5. To differentiate the situation where the user moves the map rather than the map being moved by code, you can use drag* and dblclick events. The move* events are triggered by anything that moves the map, which can include calls made by your own Javascript code and the opening of an info window.

Custom Events

It’s also possible to use the GEvent system to pass messages between different parts of your own code with custom events. Simply use GEvent.addListener(marker, “myevent”) to listen for the event andGEvent.trigger(marker, “myevent”) to trigger it. You can pass up to two parameters.

You can pass these custom events on any object, these can be API objects, HTML elements, data structures, or any type of Object().

 GEvent.addListener(map, "myevent", ... GEvent.addListener(document.getElementById("message"), "thisevent", ... var fred = new Object(); GEvent.addListener(fred, "thatevent", ... 

GEvent.addDomListener

It’s also possible to use GEvent.addDomListener() to listen for Dom events on HTML Elements.

Writing GEvent.addDomListener(document.getElementById(“button”), “mouseover”, … has a similar effect to writing <input id=”button” onmouseover=”…”>, but there are one or two advantages to using the GEvent system:

  1. You may find it easier to add or remove GEvent listeners
  2. You can use GEvent.trigger on these events

You can use this system to handle any of the standard HTML Dom events: “blur”, “click”, “dblclick”, “focus”, “keydown”, “keypress”, “keyup”, “load”, “mousedown”, “mousemove”, “mouseout”, “mouseover”, “mouseup”.

When using this system, the full event details are passed in the first parameter. So for example you could write

GEvent.addDomListener(document.getElementById("map"), "click", function(e) {...

and then examine the details of the event “e” and behave differently if, say, the ALT or CTRL keys were pressed by testing if (e.altKey) or if (e.ctrlKey).

Note that if you write GEvent.addDomListener(map, “click” then you don’t get the Dom event because a GMap2() object isn’t a HTML element. You get the conventional “map click” event instead, with the parameters “overlay” and “latlng”.

Advertisements