public class EventHandlers extends Object
An instance of this class is assigned to the document model so that Javascript can access it to make callbacks when events occur.
An application calls on one of the two addXXEventHandler methods in the
GoogleMap class to register an
instance of the GFXEventHandler interface against a certain event
type in the Google Maps event model. See addUIEventHandler and
addStateEventHandler.
This class uses a key based on a UUID to map the Javascript event handlers registered against the Google Maps model back to our Java event handlers stored here. The addXXEventHandler methods in GoogleMap create functions that call back into this class using the supplied key.
Currently an instance of this class is registered as:
document.jsHandlers
The event listeners are established using the following Javascript calls:
google.maps.event.addListener(map, 'event_type', function(event) { document.jsHandlers.handleUIEvent('key', event.latLng); });
google.maps.event.addListener(map, 'event_type', function() { document.jsHandlers.handleStateEvent('key'); });
- Author:
- Geoff Capper
-
Constructor Summary
Constructors Constructor Description EventHandlers() -
Method Summary
Modifier and Type Method Description protected GMapMouseEventbuildMouseEvent(JSObject jsObject)voidhandleStateEvent(String callbackKey)This method is called from Javascript, passing in the previously created callback key.voidhandleUIEvent(String callbackKey, JSObject result)This method is called from Javascript, passing in the previously created callback key, and the event object.StringregisterHandler(GFXEventHandler handler)Registers a handler and returns the callback key to be passed to Javascript.
-
Constructor Details
-
EventHandlers
public EventHandlers()
-
-
Method Details
-
registerHandler
Registers a handler and returns the callback key to be passed to Javascript.- Parameters:
handler- Handler to be registered.- Returns:
- A String random UUID that can be used as the callback key.
-
handleUIEvent
This method is called from Javascript, passing in the previously created callback key, and the event object. The current implementation is receiving the LatLng object that the Javascript MouseEvent contains.It may be more useful to return the MouseEvent and let clients go from there, but there is only the stop() method on the MouseEvent?
- Parameters:
callbackKey- Key generated by the call to registerHandler.result- Currently the event object from the Google Maps event.
-
handleStateEvent
This method is called from Javascript, passing in the previously created callback key. It uses that to find the correct handler and then passes on the call. State events in the Google Maps API don't pass any parameters.- Parameters:
callbackKey- Key generated by the call to registerHandler.
-
buildMouseEvent
-