I could use some Guru recommendations on MapV3 API Event bindings model?

60 views
Skip to first unread message

Brandon Donnelson

unread,
Dec 18, 2011, 7:49:00 PM12/18/11
to google-we...@googlegroups.com
I'm wrapping up the Maps V3 api. Any recommendations on modeling it after the core widgets?

Any recommendations on which example to follow for wrapping up the map events? I see Visualizations api code has a nice way of doing it. The underlying widgets of GWT may be it?

Reference to Map Event bindings
http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener

I think I'll use this, but I'm looking deeper into the GWT core to see if there are better ways?
http://code.google.com/p/gwt-google-apis/source/browse/trunk/visualization/visualization/src/com/google/gwt/visualization/client/events/Handler.java

If your interested in tracking my progress on my bindings...

G+ comments on this:

So far I've copied the Viz api with this: I'm wondering if it would be better to follow the core event model.
public abstract class Handler {

 
/**
   * TODO
   * @param w
   * @param eventName
   * @param handler
   */

 
public static native void addHandler(MapWidget w, String eventName, Handler handler) /*-{
    var jso = w.@com.gonevertical.apis.googlemaps.client.MapWidget::getJso()();
    var callback = function(event) {
      @com.gonevertical.apis.googlemaps.client.events.Handler::onCallback(Lcom/gonevertical/apis/googlemaps/client/events/Handler;Lcom/google/gwt/ajaxloader/client/Properties;)(handler, event);
    };
    $wnd.google.maps.MapsEventListener.addListener(jso, eventName, callback)
  }-*/
;

 
@SuppressWarnings("unused")
 
private static void onCallback(final Handler handler, final Properties properties) {
   
try {
      handler
.onEvent(properties);
   
} catch (Throwable x) {
      GWT
.getUncaughtExceptionHandler().onUncaughtException(x);
   
}
 
}

 
/**
   * This method should be overridden by event-specific Handler subclasses. The
   * subclass should extract the event properties (if any), create a GWT Event
   * bean object, and pass it to the event-specific callback.
   *
   * @param properties The JavaScriptObject containing data about the event.
   * @throws TypeException If some property of the event has an unexpected type.
   */

 
protected abstract void onEvent(Properties properties) throws TypeException;
}

Thanks Brandon Donnelson



Patrick Julien

unread,
Dec 18, 2011, 7:58:29 PM12/18/11
to google-we...@googlegroups.com

Brandon Donnelson

unread,
Dec 18, 2011, 10:39:33 PM12/18/11
to google-we...@googlegroups.com
I have been examining it. Although, I'm thinking that moving to the newer event model and overlay types would be advantageous. The visualization library was written with the new overlay types and the current maps api has some other wrapper system, so I've been digging from that. But I like the GWt core event model and examining how to integrate it. 

One thing is for sure, the deprecation is soon :) 

Thanks for the input,
Brandon

Brandon Donnelson

unread,
Dec 21, 2011, 12:53:25 AM12/21/11
to google-we...@googlegroups.com
So far this is what I have and seems to be working good. I'll stick with this for now I think and change it if something better comes up. 

public class MapHandlerRegistration {

 
/**
   * create a handler for eventName

   * @param w
   * @param eventName
   * @param handler
   * @return
   */

 
public static HandlerRegistration addHandler(MapWidget w, String eventName, MapHandler<?> handler) {
   
final JavaScriptObject listener = addHandlerImpl(w, eventName, handler);
   
HandlerRegistration registration = new HandlerRegistration() {
     
public void removeHandler() {
        removeHandlerImpl
(listener);
     
}
   
};
   
return registration;
 
}

 
/**
   * maps v3 event observation

   * @param w
   * @param eventName
   * @param handler
   * @return
   */

 
private static native JavaScriptObject addHandlerImpl(MapWidget w, String eventName, MapHandler<?> handler) /*-{

    var jso = w.@com.gonevertical.apis.googlemaps.client.MapWidget::getJso()();
    var callback = function(event) {
      @com.gonevertical.apis.googlemaps.client.events.MapHandlerRegistration::onCallback(Lcom/gonevertical/apis/googlemaps/client/events/MapHandler;Lcom/google/gwt/ajaxloader/client/Properties;)(handler, event);
    };          
    return $wnd.google.maps.event.addListener(jso, eventName, callback)
  }-*/
;
 
 
/**
   * HandlerRegistration call when finished
   * @param listener
   */

 
private static native void removeHandlerImpl(JavaScriptObject listener) /*-{
    $wnd.google.maps.MapsEventListener.addListener(listener);
  }-*/
;

 
/**
   * Process event and next step is to format it into an event that extends format handler
   * @param handler
   * @param properties
   */

 
@SuppressWarnings("unused")
 
protected static void onCallback(final MapHandler<?> handler, final Properties properties) {
   
try {
      formatEvent
(handler, properties);
   
} catch (Throwable x) {
      GWT
.getUncaughtExceptionHandler().onUncaughtException(x);
   
}
 
}

 
/**
   * format the event and tell the handler so parent can then work with it
   * @param handler
   * @param properties
   */

 
private static void formatEvent(MapHandler<?> handler, Properties properties) {
   
   
if (handler instanceof ClickMapHandler) {
     
System.out.println("tes2");
     
   
} else {
     
System.out.println("test3");
   
}
   
 
}

}

Brandon 


Brandon Donnelson

unread,
Dec 21, 2011, 12:58:59 AM12/21/11
to google-we...@googlegroups.com
And using it in MapWidget:

  public HandlerRegistration addClickHandler(ClickMapHandler handler) {
   
return MapHandlerRegistration.addHandler(this, "click", handler);
 
}

Brandon Donnelson

unread,
Dec 21, 2011, 2:39:52 PM12/21/11
to google-we...@googlegroups.com
Here is my snippets of the more formalized version I'm now using with most of the classes as snippets:

Reply all
Reply to author
Forward
0 new messages