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.bounds.BoundsChangeEventFormatter; 011 import com.google.gwt.maps.client.events.bounds.BoundsChangeMapHandler; 012 import com.google.gwt.maps.client.events.click.ClickEventFormatter; 013 import com.google.gwt.maps.client.events.click.ClickMapHandler; 014 import com.google.gwt.maps.client.events.dblclick.DblClickEventFormatter; 015 import com.google.gwt.maps.client.events.dblclick.DblClickMapHandler; 016 import com.google.gwt.maps.client.events.mousedown.MouseDownEventFormatter; 017 import com.google.gwt.maps.client.events.mousedown.MouseDownMapHandler; 018 import com.google.gwt.maps.client.events.mousemove.MouseMoveEventFormatter; 019 import com.google.gwt.maps.client.events.mousemove.MouseMoveMapHandler; 020 import com.google.gwt.maps.client.events.mouseout.MouseOutEventFormatter; 021 import com.google.gwt.maps.client.events.mouseout.MouseOutMapHandler; 022 import com.google.gwt.maps.client.events.mouseover.MouseOverEventFormatter; 023 import com.google.gwt.maps.client.events.mouseover.MouseOverMapHandler; 024 import com.google.gwt.maps.client.events.mouseup.MouseUpEventFormatter; 025 import com.google.gwt.maps.client.events.mouseup.MouseUpMapHandler; 026 import com.google.gwt.maps.client.events.rightclick.RightClickEventFormatter; 027 import com.google.gwt.maps.client.events.rightclick.RightClickMapHandler; 028 import com.google.gwt.maps.client.mvc.MVCObject; 029 030 /** 031 * A rectangle overlay. This class extends MVCObject. <br> 032 * <br> 033 * See <a href= 034 * "https://developers.google.com/maps/documentation/javascript/reference#Rectangle" 035 * >Rectangle API Doc</a> 036 */ 037 public class Rectangle extends MVCObject<Rectangle> { 038 039 /** 040 * use newInstance(); 041 */ 042 protected Rectangle() { 043 } 044 045 /** 046 * Create a rectangle using the passed RectangleOptions, which specify the 047 * bounds and style. 048 * 049 * @param options 050 */ 051 public final static Rectangle newInstance(RectangleOptions options) { 052 return createJso(options).cast(); 053 } 054 055 private final static native JavaScriptObject createJso( 056 RectangleOptions options) /*-{ 057 return new $wnd.google.maps.Rectangle(options); 058 }-*/; 059 060 /** 061 * Returns the bounds of this rectangle. 062 */ 063 public final native LatLngBounds getBounds() /*-{ 064 return this.getBounds(); 065 }-*/; 066 067 /** 068 * Returns whether this rectangle can be edited by the user. 069 */ 070 public final native boolean getEditable() /*-{ 071 return this.getEditable(); 072 }-*/; 073 074 /** 075 * Renders the rectangle on the specified map. If map is set to null, the 076 * rectangle will be removed. 077 * 078 * @param mapWidget 079 */ 080 public final void setMap(MapWidget mapWidget) { 081 if (mapWidget == null) { 082 setMapImpl(null); 083 } else { 084 setMapImpl(mapWidget.getJso()); 085 } 086 } 087 088 private final native void setMapImpl(MapImpl map) /*-{ 089 this.map = map; 090 }-*/; 091 092 /** 093 * Returns the map on which this rectangle is displayed. 094 */ 095 public final MapWidget getMap() { 096 return MapWidget.newInstance(getMapImpl()); 097 } 098 099 private final native MapImpl getMapImpl() /*-{ 100 return this.map; 101 }-*/; 102 103 /** 104 * If set to true, the user can edit this rectangle by dragging the control 105 * points shown at the corners and on each edge. 106 * 107 * @param editable 108 */ 109 public final native void setEditable(boolean editable) /*-{ 110 this.setEditable(editable); 111 }-*/; 112 113 /** 114 * sets the Rectangle options 115 * 116 * @param options 117 */ 118 public final native void setOptions(RectangleOptions options) /*-{ 119 this.options = options; 120 }-*/; 121 122 public final HandlerRegistration addBoundsChangeHandler( 123 BoundsChangeMapHandler handler) { 124 return MapHandlerRegistration.addHandler(this, 125 MapEventType.BOUNDS_CHANGED, handler, 126 new BoundsChangeEventFormatter()); 127 } 128 129 /** 130 * This event is fired when the DOM click event is fired on the Rectangle. 131 * 132 * @param handler 133 */ 134 public final HandlerRegistration addClickHandler(ClickMapHandler handler) { 135 return MapHandlerRegistration.addHandler(this, MapEventType.CLICK, 136 handler, new ClickEventFormatter()); 137 } 138 139 /** 140 * This event is fired when the DOM dblclick event is fired on the 141 * Rectangle. 142 * 143 * @param handler 144 */ 145 public final HandlerRegistration addDblClickHandler( 146 DblClickMapHandler handler) { 147 return MapHandlerRegistration.addHandler(this, MapEventType.DBLCLICK, 148 handler, new DblClickEventFormatter()); 149 } 150 151 /** 152 * This event is fired when the DOM mousedown event is fired on the 153 * Rectangle. 154 * 155 * @param handler 156 */ 157 public final HandlerRegistration addMouseDownHandler( 158 MouseDownMapHandler handler) { 159 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEDOWN, 160 handler, new MouseDownEventFormatter()); 161 } 162 163 /** 164 * This event is fired when the DOM mousemove event is fired on the 165 * Rectangle. 166 * 167 * @param handler 168 */ 169 public final HandlerRegistration addMouseMoveHandler( 170 MouseMoveMapHandler handler) { 171 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEMOVE, 172 handler, new MouseMoveEventFormatter()); 173 } 174 175 /** 176 * This event is fired on Rectangle mouseout. 177 * 178 * @param handler 179 */ 180 public final HandlerRegistration addMouseOutMoveHandler( 181 MouseOutMapHandler handler) { 182 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOUT, 183 handler, new MouseOutEventFormatter()); 184 } 185 186 /** 187 * This event is fired on Rectangle mouseover. 188 * 189 * @param handler 190 */ 191 public final HandlerRegistration addMouseOverHandler( 192 MouseOverMapHandler handler) { 193 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOVER, 194 handler, new MouseOverEventFormatter()); 195 } 196 197 /** 198 * This event is fired when the DOM mouseup event is fired on the Rectangle. 199 * 200 * @param handler 201 */ 202 public final HandlerRegistration addMouseUpHandler(MouseUpMapHandler handler) { 203 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEUP, 204 handler, new MouseUpEventFormatter()); 205 } 206 207 /** 208 * This event is fired when the Rectangle is right-clicked on. 209 * 210 * @param handler 211 */ 212 public final HandlerRegistration addRightClickHandler( 213 RightClickMapHandler handler) { 214 return MapHandlerRegistration.addHandler(this, MapEventType.RIGHTCLICK, 215 handler, new RightClickEventFormatter()); 216 } 217 218 }