001    package com.google.gwt.maps.client.overlays;
002    
003    import com.google.gwt.core.client.JavaScriptObject;
004    import com.google.gwt.maps.client.MapImpl;
005    import com.google.gwt.maps.client.MapWidget;
006    import com.google.gwt.maps.client.mvc.MVCObject;
007    import com.google.gwt.maps.client.streetview.StreetViewPanoramaImpl;
008    import com.google.gwt.maps.client.streetview.StreetViewPanoramaWidget;
009    
010    /**
011     * You can implement this class if you want to display custom types of overlay objects on the map. This class extends MVCObject.
012     * <br><br>
013     * See <a href="https://developers.google.com/maps/documentation/javascript/reference#OverlayView">OverlayView API Doc</a> 
014     */
015    public class OverlayView extends MVCObject<OverlayView> {
016      
017      /**
018       * use newInstance();
019       */
020      protected OverlayView() {}
021      
022      /**
023       * You should inherit from this class by setting your overlay's prototype to new OverlayView.prototype. You must implement three methods: onAdd(), draw(), and onRemove(). In the add() method, you should create DOM objects and append them as children of the panes. In the draw() method, you should position these elements. In the onRemove() method, you should remove the objects from the DOM. You must call setMap() with a valid Map object to trigger the call to the onAdd() method and setMap(null) in order to trigger the onRemove() method. The setMap() method can be called at the time of construction or at any point afterward when the overlay should be re-shown after removing. The draw() method will then be called whenever a map property changes that could change the position of the element, such as zoom, center, or map type.
024       * @return {@link OverlayView}
025       */
026      public final static OverlayView newInstance() {
027        return createJso().cast();
028      }
029    
030      private final static native JavaScriptObject createJso() /*-{
031        return new $wnd.google.maps.OverlayView();
032      }-*/; 
033      
034      /**
035       * Implement this method to draw or update the overlay. This method is called after onAdd() and when the position from projection.fromLatLngToPixel() would return a new value for a given LatLng. This can happen on change of zoom, center, or map type. It is not necessarily called on drag or resize.
036       */
037      public final native void draw() /*-{
038        this.draw();
039      }-*/;
040      
041      /**
042       * get mapWidget
043       */
044      public final MapWidget getMapWidget() {
045        return MapWidget.newInstance(getMapImpl());
046      }
047      
048      private final native MapImpl getMapImpl() /*-{
049        return this.getMap();
050      }-*/;
051    
052      /**
053       * Returns the panes in which this OverlayView can be rendered. Only available after draw has been called.
054       */
055      public final native MapPanes getPanes() /*-{
056        return this.getPanes();
057      }-*/;
058      
059      /**
060       * Returns the MapCanvasProjection object associated with this OverlayView. Only available after draw has been called.
061       */
062      public final native MapCanvasProjection getProjection() /*-{
063        return this.getProjection();
064      }-*/;
065      
066      /**
067       * Implement this method to initialize the overlay DOM elements. This method is called once after setMap() is called with a valid map. At this point, panes and projection will have been initialized.
068       */
069      public final native void onAdd() /*-{
070        this.onAdd();
071      }-*/;
072      
073      /**
074       * Implement this method to remove your elements from the DOM. This method is called once following a call to setMap(null).
075       */
076      public final native void onRemove() /*-{
077        this.onRemove();
078      }-*/;
079      
080      /**
081       * Adds the overlay to the map or panorama. 
082       * @param mapWidget
083       */
084      public final void setMap(MapWidget mapWidget) {
085        setMapImpl(mapWidget.getJso());
086      }
087      
088      private final native void setMapImpl(MapImpl map) /*-{
089        this.setMap(map);
090      }-*/;
091    
092      /**
093       * Adds the overlay to the map or panorama. 
094       * @param streetViewPanoramaWdiget
095       */
096      public final void setMap(StreetViewPanoramaWidget streetViewPanoramaWdiget) {
097        setMapImpl(streetViewPanoramaWdiget.getJso());
098      }
099      
100      private final native void setMapImpl(StreetViewPanoramaImpl pano) /*-{
101        this.setMap(pano);
102      }-*/;
103      
104    }