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     * A polyline is a linear overlay of connected line segments on the map. This
032     * class extends MVCObject. <br>
033     * <br>
034     * See <a href=
035     * "https://developers.google.com/maps/documentation/javascript/reference#Polyline"
036     * >Polyline API Doc</a>
037     */
038    public class Polyline extends MVCObject<Polyline> {
039    
040            /**
041             * use newInstance();
042             * 
043             */
044            protected Polyline() {
045            }
046    
047            /**
048             * Create a polyline using the passed PolylineOptions, which specify both
049             * the path of the polyline and the stroke style to use when drawing the
050             * polyline. You may pass either an array of LatLngs or an MVCArray of
051             * LatLngs when constructing a polyline, though simple arrays are converted
052             * to MVCArrays within the polyline upon instantiation.
053             * 
054             * @param options
055             *            {@link PolylineOptions}
056             */
057            public static final Polyline newInstance(PolylineOptions options) {
058                    return createJso(options).cast();
059            }
060    
061            private static native JavaScriptObject createJso(PolylineOptions options) /*-{
062                    return new $wnd.google.maps.Polyline(options);
063            }-*/;
064    
065            /**
066             * Returns whether this shape can be edited by the user.
067             */
068            public final native boolean getEditable() /*-{
069                    return this.getEditable();
070            }-*/;
071    
072            /**
073             * Returns the map on which this shape is attached.
074             */
075            public final MapWidget getMap() {
076                    return MapWidget.newInstance(getMapImpl());
077            }
078    
079            private final native MapImpl getMapImpl() /*-{
080                    return this.getMap();
081            }-*/;
082    
083            /**
084             * Retrieves the first path.
085             */
086            public final native MVCArray<LatLng> getPath() /*-{
087                    return this.getPath();
088            }-*/;
089    
090            /**
091             * If set to true, the user can edit this shape by dragging the control
092             * points shown at the vertices and on each segment.
093             * 
094             * @param editable
095             */
096            public final native void setEditable(boolean editable) /*-{
097                    this.setEditable(editable);
098            }-*/;
099    
100            /**
101             * Renders this shape on the specified map. If map is set to null, the shape
102             * will be removed.
103             * 
104             * @param mapWidget
105             */
106            public final void setMap(MapWidget mapWidget) {
107                    if (mapWidget == null) {
108                            setMapImpl(null);
109                    } else {
110                            setMapImpl(mapWidget.getJso());
111                    }
112            }
113    
114            private final native void setMapImpl(MapImpl impl) /*-{
115                    this.setMap(impl);
116            }-*/;
117    
118            /**
119             * set Options
120             * 
121             * @param options
122             */
123            public final native void setOptions(PolylineOptions options) /*-{
124                    this.setOptions(options);
125            }-*/;
126    
127            /**
128             * Sets the first path. See {@link PolylineOptions} for more details.
129             * 
130             * @param path
131             */
132            public final native void setPath(MVCArray<LatLng> path) /*-{
133                    this.setPath(path);
134            }-*/;
135    
136            /**
137             * Sets the first path. See {@link PolylineOptions} for more details.
138             * 
139             * @param path
140             */
141            public final native void setPath(JsArray<LatLng> path) /*-{
142                    this.setPath(path);
143            }-*/;
144    
145            /**
146             * This event is fired when the DOM click event is fired on the Polyline.
147             * 
148             * @param handler
149             */
150            public final HandlerRegistration addClickHandler(ClickMapHandler handler) {
151                    return MapHandlerRegistration.addHandler(this, MapEventType.CLICK,
152                                    handler, new ClickEventFormatter());
153            }
154    
155            /**
156             * This event is fired when the DOM dblclick event is fired on the Polyline.
157             * 
158             * @param handler
159             */
160            public final HandlerRegistration addDblClickHandler(
161                            DblClickMapHandler handler) {
162                    return MapHandlerRegistration.addHandler(this, MapEventType.DBLCLICK,
163                                    handler, new DblClickEventFormatter());
164            }
165    
166            /**
167             * This event is fired when the DOM mousedown event is fired on the
168             * Polyline.
169             * 
170             * @param handler
171             */
172            public final HandlerRegistration addMouseDownHandler(
173                            MouseDownMapHandler handler) {
174                    return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEDOWN,
175                                    handler, new MouseDownEventFormatter());
176            }
177    
178            /**
179             * This event is fired when the DOM mousemove event is fired on the
180             * Polyline.
181             * 
182             * @param handler
183             */
184            public final HandlerRegistration addMouseMoveHandler(
185                            MouseMoveMapHandler handler) {
186                    return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEMOVE,
187                                    handler, new MouseMoveEventFormatter());
188            }
189    
190            /**
191             * This event is fired on Polyline mouseout.
192             * 
193             * @param handler
194             */
195            public final HandlerRegistration addMouseOutMoveHandler(
196                            MouseOutMapHandler handler) {
197                    return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOUT,
198                                    handler, new MouseOutEventFormatter());
199            }
200    
201            /**
202             * This event is fired on Polyline mouseover.
203             * 
204             * @param handler
205             */
206            public final HandlerRegistration addMouseOverHandler(
207                            MouseOverMapHandler handler) {
208                    return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOVER,
209                                    handler, new MouseOverEventFormatter());
210            }
211    
212            /**
213             * This event is fired when the DOM mouseup event is fired on the Polyline.
214             * 
215             * @param handler
216             */
217            public final HandlerRegistration addMouseUpHandler(MouseUpMapHandler handler) {
218                    return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEUP,
219                                    handler, new MouseUpEventFormatter());
220            }
221    
222            /**
223             * This event is fired when the Polyline is right-clicked on.
224             * 
225             * @param handler
226             */
227            public final HandlerRegistration addRightClickHandler(
228                            RightClickMapHandler handler) {
229                    return MapHandlerRegistration.addHandler(this, MapEventType.RIGHTCLICK,
230                                    handler, new RightClickEventFormatter());
231            }
232    
233    }