001    package com.google.gwt.maps.client.layers;
002    
003    import com.google.gwt.core.client.JavaScriptObject;
004    import com.google.gwt.event.shared.HandlerRegistration;
005    import com.google.gwt.maps.client.MapImpl;
006    import com.google.gwt.maps.client.MapWidget;
007    import com.google.gwt.maps.client.events.MapEventType;
008    import com.google.gwt.maps.client.events.MapHandlerRegistration;
009    import com.google.gwt.maps.client.events.fusiontablemouse.FusionTablesMouseEventFormatter;
010    import com.google.gwt.maps.client.events.fusiontablemouse.FusionTablesMouseMapHandler;
011    import com.google.gwt.maps.client.mvc.MVCObject;
012    
013    /**
014     * A FusionTablesLayer allows you to display data from a Google Fusion Table on a map, as a rendered layer. (See <a href="https://developers.google.com/fusiontables/">Fusion Table site</a>). Table data can be queried using the same query language as is used in the Fusion Tables API. This class extends MVCObject.
015     * <br><br>
016     * See <a href="https://developers.google.com/maps/documentation/javascript/reference#FusionTablesLayer">FusionTablesLayer API Doc</a>
017     */
018    public class FusionTablesLayer extends MVCObject<FusionTablesLayer> {
019      
020      /**
021       * use newInstance();
022       */
023      protected FusionTablesLayer() {}
024    
025      /**
026       * A layer that displays data from a Fusion Table.
027       * @param options
028       */
029      public final static FusionTablesLayer newInstance(FusionTablesLayerOptions options) {
030        return createJso(options).cast();
031      }
032    
033      private static native JavaScriptObject createJso(FusionTablesLayerOptions options) /*-{
034        return new $wnd.google.maps.FusionTablesLayer(options);
035      }-*/;
036      
037      /**
038       * Renders the layer on the specified map. If map is set to null, the layer will be removed.
039       * @param mapWidget
040       */
041      public final void setMap(MapWidget mapWidget) {
042        setMapImpl(mapWidget.getJso());
043      }
044    
045      private final native void setMapImpl(MapImpl map) /*-{
046        this.map = map;
047      }-*/;
048      
049      /**
050       * Returns the map on which this layer is displayed.
051       */
052      public final MapWidget getMap() {
053        return MapWidget.newInstance(getMapImpl());
054      }
055    
056      private final native MapImpl getMapImpl() /*-{
057        return this.map;
058      }-*/;
059      
060      /**
061       * set Options
062       * @param options
063       */
064      public final native void setOptions(FusionTablesLayerOptions options) /*-{
065        this.setOptions(options);
066      }-*/;
067      
068      /**
069       * This event is fired when a feature in the layer is clicked.
070       * @param handler
071       */
072      public final HandlerRegistration addClickHandler(FusionTablesMouseMapHandler handler) {
073        return MapHandlerRegistration.addHandler(this, MapEventType.CLICK, handler, new FusionTablesMouseEventFormatter());
074      }
075    }