001 package com.google.gwt.maps.client.overlays;
002
003 import com.google.gwt.core.client.JavaScriptObject;
004 import com.google.gwt.core.client.JsArray;
005 import com.google.gwt.event.shared.HandlerRegistration;
006 import com.google.gwt.maps.client.MapImpl;
007 import com.google.gwt.maps.client.MapWidget;
008 import com.google.gwt.maps.client.base.LatLng;
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.click.ClickEventFormatter;
012 import com.google.gwt.maps.client.events.click.ClickMapHandler;
013 import com.google.gwt.maps.client.events.dblclick.DblClickEventFormatter;
014 import com.google.gwt.maps.client.events.dblclick.DblClickMapHandler;
015 import com.google.gwt.maps.client.events.mousedown.MouseDownEventFormatter;
016 import com.google.gwt.maps.client.events.mousedown.MouseDownMapHandler;
017 import com.google.gwt.maps.client.events.mousemove.MouseMoveEventFormatter;
018 import com.google.gwt.maps.client.events.mousemove.MouseMoveMapHandler;
019 import com.google.gwt.maps.client.events.mouseout.MouseOutEventFormatter;
020 import com.google.gwt.maps.client.events.mouseout.MouseOutMapHandler;
021 import com.google.gwt.maps.client.events.mouseover.MouseOverEventFormatter;
022 import com.google.gwt.maps.client.events.mouseover.MouseOverMapHandler;
023 import com.google.gwt.maps.client.events.mouseup.MouseUpEventFormatter;
024 import com.google.gwt.maps.client.events.mouseup.MouseUpMapHandler;
025 import com.google.gwt.maps.client.events.rightclick.RightClickEventFormatter;
026 import com.google.gwt.maps.client.events.rightclick.RightClickMapHandler;
027 import com.google.gwt.maps.client.mvc.MVCArray;
028 import com.google.gwt.maps.client.mvc.MVCObject;
029
030 /**
031 *
032 * <br>
033 * <br>
034 * See <a href=
035 * "https://developers.google.com/maps/documentation/javascript/reference#Polygon"
036 * >Polygon API Doc</a>
037 */
038 public class Polygon extends MVCObject<Polygon> {
039
040 /**
041 * use newInstance();
042 */
043 protected Polygon() {
044 }
045
046 /**
047 * Create a polygon using the passed PolygonOptions, which specify the
048 * polygon's path, the stroke style for the polygon's edges, and the fill
049 * style for the polygon's interior regions. A polygon may contain one or
050 * more paths, where each path consists of an array of LatLngs. You may pass
051 * either an array of LatLngs or an MVCArray of LatLngs when constructing
052 * these paths. Arrays are converted to MVCArrays within the polygon upon
053 * instantiation.
054 *
055 * @param options
056 */
057 public final static Polygon newInstance(PolygonOptions options) {
058 return createJso(options).cast();
059 }
060
061 private final static native JavaScriptObject createJso(
062 PolygonOptions options) /*-{
063 return new $wnd.google.maps.Polygon(options);
064 }-*/;
065
066 /**
067 * Returns whether this shape can be edited by the user.
068 */
069 public final native boolean getEditable() /*-{
070 return this.getEditable();
071 }-*/;
072
073 /**
074 * Returns the map on which this shape is attached.
075 */
076 public final MapWidget getMap() {
077 return MapWidget.newInstance(getMapImpl());
078 }
079
080 private final native MapImpl getMapImpl() /*-{
081 return this.getMap();
082 }-*/;
083
084 /**
085 * Retrieves the first path.
086 */
087 public final native MVCArray<LatLng> getPath() /*-{
088 return this.getPath();
089 }-*/;
090
091 /**
092 * Retrieves the paths for this polygon.
093 */
094 public final native MVCArray<MVCArray<LatLng>> getPaths() /*-{
095 return this.getPaths();
096 }-*/;
097
098 /**
099 * If set to true, the user can edit this shape by dragging the control
100 * points shown at the vertices and on each segment.
101 *
102 * @param editable
103 */
104 public final native void setEditable(boolean editable) /*-{
105 this.setEditable(editable);
106 }-*/;
107
108 /**
109 * Renders this shape on the specified map. If map is set to null, the shape
110 * will be removed.
111 *
112 * @param mapWidget
113 */
114 public final void setMap(MapWidget mapWidget) {
115 if (mapWidget == null) {
116 setMapImpl(null);
117 } else {
118 setMapImpl(mapWidget.getJso());
119 }
120 }
121
122 private final native void setMapImpl(MapImpl impl) /*-{
123 this.setMap(impl);
124 }-*/;
125
126 /**
127 * set Options
128 *
129 * @param options
130 */
131 public final native void setOptions(PolygonOptions options) /*-{
132 this.setOptions(options);
133 }-*/;
134
135 /**
136 * Sets the first path. See PolylineOptions for more details.
137 *
138 * @param path
139 */
140 public final native void setPath(MVCArray<LatLng> path) /*-{
141 this.setPath(path);
142 }-*/;
143
144 /**
145 * Sets the first path. See PolylineOptions for more details.
146 *
147 * @param path
148 */
149 public final native void setPath(JsArray<LatLng> path) /*-{
150 this.setPath(path);
151 }-*/;
152
153 /**
154 * Sets the path for this polygon.
155 *
156 * @param paths
157 */
158 public final native void setPaths(MVCArray<LatLng> paths) /*-{
159 this.setPaths(paths);
160 }-*/;
161
162 /**
163 * Sets the path for this polygon.
164 *
165 * @param paths
166 */
167 public final native void setPathss(MVCArray<MVCArray<LatLng>> paths) /*-{
168 this.setPaths(paths);
169 }-*/;
170
171 /**
172 * Sets the path for this polygon.
173 *
174 * @param paths
175 */
176 public final native void setPaths(JsArray<LatLng> paths) /*-{
177 this.setPaths(paths);
178 }-*/;
179
180 /**
181 * Sets the path for this polygon.
182 *
183 * @param paths
184 */
185 public final native void setPathss(JsArray<JsArray<LatLng>> paths) /*-{
186 this.setPaths(paths);
187 }-*/;
188
189 /**
190 * This event is fired when the DOM click event is fired on the Polygon.
191 *
192 * @param handler
193 */
194 public final HandlerRegistration addClickHandler(ClickMapHandler handler) {
195 return MapHandlerRegistration.addHandler(this, MapEventType.CLICK,
196 handler, new ClickEventFormatter());
197 }
198
199 /**
200 * This event is fired when the DOM dblclick event is fired on the Polygon.
201 *
202 * @param handler
203 */
204 public final HandlerRegistration addDblClickHandler(
205 DblClickMapHandler handler) {
206 return MapHandlerRegistration.addHandler(this, MapEventType.DBLCLICK,
207 handler, new DblClickEventFormatter());
208 }
209
210 /**
211 * This event is fired when the DOM mousedown event is fired on the Polygon.
212 *
213 * @param handler
214 */
215 public final HandlerRegistration addMouseDownHandler(
216 MouseDownMapHandler handler) {
217 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEDOWN,
218 handler, new MouseDownEventFormatter());
219 }
220
221 /**
222 * This event is fired when the DOM mousemove event is fired on the Polygon.
223 *
224 * @param handler
225 */
226 public final HandlerRegistration addMouseMoveHandler(
227 MouseMoveMapHandler handler) {
228 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEMOVE,
229 handler, new MouseMoveEventFormatter());
230 }
231
232 /**
233 * This event is fired on Polygon mouseout.
234 *
235 * @param handler
236 */
237 public final HandlerRegistration addMouseOutMoveHandler(
238 MouseOutMapHandler handler) {
239 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOUT,
240 handler, new MouseOutEventFormatter());
241 }
242
243 /**
244 * This event is fired on Polygon mouseover.
245 *
246 * @param handler
247 */
248 public final HandlerRegistration addMouseOverHandler(
249 MouseOverMapHandler handler) {
250 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOVER,
251 handler, new MouseOverEventFormatter());
252 }
253
254 /**
255 * This event is fired when the DOM mouseup event is fired on the Polygon.
256 *
257 * @param handler
258 */
259 public final HandlerRegistration addMouseUpHandler(MouseUpMapHandler handler) {
260 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEUP,
261 handler, new MouseUpEventFormatter());
262 }
263
264 /**
265 * This event is fired when the Polygon is right-clicked on.
266 *
267 * @param handler
268 */
269 public final HandlerRegistration addRightClickHandler(
270 RightClickMapHandler handler) {
271 return MapHandlerRegistration.addHandler(this, MapEventType.RIGHTCLICK,
272 handler, new RightClickEventFormatter());
273 }
274
275 }