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