001 package com.google.gwt.maps.client.drawinglib;
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.events.MapEventType;
008 import com.google.gwt.maps.client.events.MapHandlerRegistration;
009 import com.google.gwt.maps.client.events.overlaycomplete.OverlayCompleteEventFormatter;
010 import com.google.gwt.maps.client.events.overlaycomplete.OverlayCompleteMapHandler;
011 import com.google.gwt.maps.client.events.overlaycomplete.circle.CircleCompleteEventFormatter;
012 import com.google.gwt.maps.client.events.overlaycomplete.circle.CircleCompleteMapHandler;
013 import com.google.gwt.maps.client.events.overlaycomplete.marker.MarkerCompleteEventFormatter;
014 import com.google.gwt.maps.client.events.overlaycomplete.marker.MarkerCompleteMapHandler;
015 import com.google.gwt.maps.client.events.overlaycomplete.polygon.PolygonCompleteEventFormatter;
016 import com.google.gwt.maps.client.events.overlaycomplete.polygon.PolygonCompleteMapHandler;
017 import com.google.gwt.maps.client.events.overlaycomplete.polyline.PolylineCompleteEventFormatter;
018 import com.google.gwt.maps.client.events.overlaycomplete.polyline.PolylineCompleteMapHandler;
019 import com.google.gwt.maps.client.events.overlaycomplete.rectangle.RectangleCompleteEventFormatter;
020 import com.google.gwt.maps.client.events.overlaycomplete.rectangle.RectangleCompleteMapHandler;
021 import com.google.gwt.maps.client.mvc.MVCObject;
022
023 /**
024 * Allows users to draw markers, polygons, polylines, rectangles, and circles on the map. The DrawingManager's drawing mode defines the type of overlay that will be created by the user. Adds a control to the map, allowing the user to switch drawing mode. This class extends MVCObject.
025 * <br><br>
026 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#DrawingManager">DrawingManager API Doc</a>
027 */
028 public class DrawingManager extends MVCObject<DrawingManager> {
029
030 /**
031 * use newInstance();
032 */
033 protected DrawingManager() {}
034
035 /**
036 * Creates a DrawingManager that allows users to draw overlays on the map, and switch between the type of overlay to be drawn with a drawing control.
037 * @param options
038 */
039 public static final DrawingManager newInstance(DrawingManagerOptions options) {
040 return createJso(options).cast();
041 }
042
043 private static native JavaScriptObject createJso(DrawingManagerOptions options) /*-{
044 return new $wnd.google.maps.drawing.DrawingManager(options);
045 }-*/;
046
047 /**
048 * Returns the DrawingManager's drawing mode.
049 */
050 public final OverlayType getDrawingMode() {
051 return OverlayType.fromValue(getDrawingModeImpl());
052 }
053
054 private final native String getDrawingModeImpl() /*-{
055 return this.getDrawingMode();
056 }-*/;
057
058 /**
059 * Changes the DrawingManager's drawing mode, which defines the type of overlay to be added on the map. Accepted values are MARKER, POLYGON, POLYLINE, RECTANGLE, CIRCLE, or null. A drawing mode of null means that the user can interact with the map as normal, and clicks do not draw anything.
060 * @param drawingMode
061 */
062 public final void setDrawingMode(OverlayType drawingMode) {
063 setDrawingModeImpl(drawingMode.value());
064 }
065
066 private final native void setDrawingModeImpl(String drawingMode) /*-{
067 this.setDrawingMode(drawingmode);
068 }-*/;
069
070 /**
071 * Attaches the DrawingManager object to the specified Map.
072 * @param mapWidget
073 */
074 public final void setMap(MapWidget mapWidget) {
075 setMapImpl(mapWidget.getJso());
076 }
077
078 private final native void setMapImpl(MapImpl map) /*-{
079 this.setMap(map);
080 }-*/;
081
082 /**
083 * Returns the Map to which the DrawingManager is attached, which is the Map on which the overlays created will be placed.
084 */
085 public final MapWidget getMap() {
086 return MapWidget.newInstance(getMapImpl());
087 }
088
089 private final native MapImpl getMapImpl() /*-{
090 return this.getMap();
091 }-*/;
092
093 /**
094 * This event is fired when the user has finished drawing a circle.
095 * @param handler
096 */
097 public final HandlerRegistration addCircleCompleteHandler(CircleCompleteMapHandler handler) {
098 return MapHandlerRegistration.addHandlerDrawing(this, MapEventType.CIRCLECOMPLETE, handler, new CircleCompleteEventFormatter());
099 }
100
101 /**
102 * This event is fired when the user has finished drawing a marker.
103 * @param handler
104 */
105 public final HandlerRegistration addMarkerCompleteHandler(MarkerCompleteMapHandler handler) {
106 return MapHandlerRegistration.addHandlerDrawing(this, MapEventType.MARKERCOMPLETE, handler, new MarkerCompleteEventFormatter());
107 }
108
109 /**
110 * This event is fired when the user has finished drawing an overlay of any type.
111 * @param handler
112 */
113 public final HandlerRegistration addOverlayCompleteHandler(OverlayCompleteMapHandler handler) {
114 return MapHandlerRegistration.addHandler(this, MapEventType.OVERLAYCOMPLETE, handler, new OverlayCompleteEventFormatter());
115 }
116
117 /**
118 * This event is fired when the user has finished drawing a polygon.
119 * @param handler
120 */
121 public final HandlerRegistration addPolygonCompleteHandler(PolygonCompleteMapHandler handler) {
122 return MapHandlerRegistration.addHandlerDrawing(this, MapEventType.POLYGONCOMPLETE, handler, new PolygonCompleteEventFormatter());
123 }
124
125 /**
126 * This event is fired when the user has finished drawing a polyline.
127 * @param handler
128 */
129 public final HandlerRegistration addPolylineCompleteHandler(PolylineCompleteMapHandler handler) {
130 return MapHandlerRegistration.addHandlerDrawing(this, MapEventType.POLYLINECOMPLETE, handler, new PolylineCompleteEventFormatter());
131 }
132
133 /**
134 * This event is fired when the user has finished drawing a rectangle.
135 * @param handler
136 */
137 public final HandlerRegistration addRectangleCompleteHandler(RectangleCompleteMapHandler handler) {
138 return MapHandlerRegistration.addHandlerDrawing(this, MapEventType.RECTANGLECOMPLETE, handler, new RectangleCompleteEventFormatter());
139 }
140
141 }