001 package com.google.gwt.maps.client.overlays; 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.base.LatLngBounds; 008 import com.google.gwt.maps.client.events.MapEventType; 009 import com.google.gwt.maps.client.events.MapHandlerRegistration; 010 import com.google.gwt.maps.client.events.click.ClickEventFormatter; 011 import com.google.gwt.maps.client.events.click.ClickMapHandler; 012 import com.google.gwt.maps.client.mvc.MVCObject; 013 014 /** 015 * A groundoverlay overlay. This class extends MVCObject. 016 * <br><br> 017 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#GroundOverlay">GroundOverlay API Doc</a> 018 */ 019 public class GroundOverlay extends MVCObject<GroundOverlay> { 020 021 /** 022 * use newInstance(); 023 */ 024 protected GroundOverlay() {} 025 026 /** 027 * Creates a ground overlay from the provided image URL and its LatLngBounds. The image is scaled to fit the current bounds, and projected using the current map projection. 028 * @param url 029 * @param bounds 030 * @param options 031 */ 032 public final static GroundOverlay newInstance(String url, LatLngBounds bounds, GroundOverlayOptions options) { 033 return createJso(url, bounds, options).cast(); 034 } 035 036 private final static native JavaScriptObject createJso(String url, LatLngBounds bounds, GroundOverlayOptions options) /*-{ 037 return new $wnd.google.maps.GroundOverlay(url, bounds, options); 038 }-*/; 039 040 /** 041 * Returns the bounds of this groundoverlay. 042 */ 043 public final native LatLngBounds getBounds() /*-{ 044 return this.getBounds(); 045 }-*/; 046 047 /** 048 * Renders the groundoverlay on the specified map. If map is set to null, the groundoverlay will be removed. 049 * @param mapWidget 050 */ 051 public final void setMap(MapWidget mapWidget) { 052 setMapImpl(mapWidget.getJso()); 053 } 054 055 private final native void setMapImpl(MapImpl map) /*-{ 056 this.map = map; 057 }-*/; 058 059 /** 060 * Returns the map on which this groundoverlay is displayed. 061 */ 062 public final MapWidget getMap() { 063 return MapWidget.newInstance(getMapImpl()); 064 } 065 066 private final native MapImpl getMapImpl() /*-{ 067 return this.map; 068 }-*/; 069 070 /** 071 * Gets the url of the projected image. 072 */ 073 public final native String getUrl() /*-{ 074 this.getUrl(); 075 }-*/; 076 077 /** 078 * This event is fired when the DOM click event is fired on the GroundOverlay. 079 * @param handler 080 */ 081 public final HandlerRegistration addClickHandler(ClickMapHandler handler) { 082 return MapHandlerRegistration.addHandler(this, MapEventType.CLICK, handler, new ClickEventFormatter()); 083 } 084 085 }