Class EventHandlers

java.lang.Object
com.dlsc.gmapsfx.javascript.event.EventHandlers

public class EventHandlers
extends Object
This object forms the bridge between Javascript events and the Java events.

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:

GoogleMap.addUIEventHandler(com.dlsc.gmapsfx.javascript.event.UIEventType, com.dlsc.gmapsfx.javascript.event.UIEventHandler)


 google.maps.event.addListener(map, 'event_type', function(event) {
      document.jsHandlers.handleUIEvent('key', event.latLng);
 });
 

GoogleMap.addStateEventHandler(com.dlsc.gmapsfx.javascript.event.MapStateEventType, com.dlsc.gmapsfx.javascript.event.StateEventHandler)


  google.maps.event.addListener(map, 'event_type', function() {
      document.jsHandlers.handleStateEvent('key');
  });
 
Author:
Geoff Capper
  • Constructor Details

  • Method Details

    • registerHandler

      public String registerHandler​(GFXEventHandler handler)
      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

      public void handleUIEvent​(String callbackKey, JSObject result)
      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

      public void handleStateEvent​(String callbackKey)
      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

      protected GMapMouseEvent buildMouseEvent​(JSObject jsObject)