001    package com.google.gwt.maps.client;
002    
003    import com.google.gwt.ajaxloader.client.ArrayHelper;
004    import com.google.gwt.core.client.JavaScriptObject;
005    import com.google.gwt.core.client.JsArray;
006    import com.google.gwt.maps.client.base.LatLng;
007    import com.google.gwt.maps.client.controls.MapTypeControlOptions;
008    import com.google.gwt.maps.client.controls.MapTypeStyle;
009    import com.google.gwt.maps.client.controls.OverviewMapControlOptions;
010    import com.google.gwt.maps.client.controls.PanControlOptions;
011    import com.google.gwt.maps.client.controls.RotateControlOptions;
012    import com.google.gwt.maps.client.controls.ScaleControlOptions;
013    import com.google.gwt.maps.client.controls.StreetViewControlOptions;
014    import com.google.gwt.maps.client.controls.ZoomControlOptions;
015    
016    /**
017     * Map rendering options<br>
018     * <b>Note:</b> Defaults to LatLng(26.4,-9) <br>
019     * <br>
020     * See <a href=
021     * "https://developers.google.com/maps/documentation/javascript/reference#MapOptions"
022     * >MapOptions API Doc</a>
023     */
024    public class MapOptions extends JavaScriptObject {
025    
026            /**
027             * This will tell the map how to render and with with what features<br>
028             * Use newInstance();
029             */
030            protected MapOptions() {
031            }
032    
033            private static final double DEFAULT_LATLNG_LAT = 26.4d;
034            private static final double DEFAULT_LATLNG_LNG = -9d;
035    
036            /**
037             * Create a new Instance of the MapOptions This will also create a defaults
038             * center, mapTypeId and Zoom
039             * 
040             * @return MapOptions
041             */
042            public final static MapOptions newInstance() {
043                    MapOptions options = newInstanceDefault();
044                    getDefaults(options);
045                    return options;
046            }
047    
048            /**
049             * Create a new Instance of the MapOptions
050             * 
051             * @param withdefaults
052             *            - [true]= setup required defaults, center, mapTypeId and Zoom.
053             *            [false]= will not use defaults
054             * @return MapOptions
055             */
056            public final static MapOptions newInstance(boolean withdefaults) {
057                    MapOptions options = newInstanceDefault();
058                    if (withdefaults == true) {
059                            getDefaults(options);
060                    }
061                    return options;
062            }
063    
064            /**
065             * get the Required defaults, this should help prevent setup errors
066             * 
067             * @param options
068             */
069            private static void getDefaults(MapOptions options) {
070                    options.setCenter(LatLng.newInstance(DEFAULT_LATLNG_LAT,
071                                    DEFAULT_LATLNG_LNG));
072                    options.setMapTypeId(MapTypeId.ROADMAP);
073                    options.setZoom(0);
074            }
075    
076            /**
077             * setup a javascript object to store the values in
078             * 
079             * @return MapOptions
080             */
081            private final static MapOptions newInstanceDefault() {
082                    JavaScriptObject jso = JavaScriptObject.createObject();
083                    // WorkAroundUtils.removeGwtObjectId(jso); TODO Still needed?
084                    return jso.cast();
085            }
086    
087            /**
088             * set Color used for the background of the Map div. This color will be
089             * visible when tiles have not yet loaded as the user pans. This option can
090             * only be set when the map is initialized.
091             * 
092             * @param backgroundColor
093             */
094            public final native void setBackgroundColor(String backgroundColor) /*-{
095                    this.backgroundColor = backgroundColor;
096            }-*/;
097    
098            /**
099             * get Color used for the background of the Map div.
100             */
101            public final native String getBackgroundColor() /*-{
102                    return this.backgroundColor;
103            }-*/;
104    
105            /**
106             * set The initial Map center. Required.
107             * 
108             * @param center
109             *            {@link LatLng}
110             */
111            public final native void setCenter(LatLng center) /*-{
112                    this.center = center;
113            }-*/;
114    
115            /**
116             * get {@link LatLng}
117             * 
118             * @return {@link LatLng}
119             */
120            public final native LatLng getCenter() /*-{
121                    return this.center;
122            }-*/;
123    
124            /**
125             * set Enables/disables all default UI. May be overridden individually.
126             * 
127             * @param disableDefaultUI
128             */
129            public final native void setDisableDefaultUi(boolean disableDefaultUI) /*-{
130                    this.disableDefaultUI = disableDefaultUI;
131            }-*/;
132    
133            /**
134             * get Enables/disables all default UI. May be overridden individually.
135             * 
136             * @return boolean
137             */
138            public final native boolean getDisableDefaultUi() /*-{
139                    return this.disableDefaultUI;
140            }-*/;
141    
142            /**
143             * set Enables/disables zoom and center on double click. Enabled by default.
144             * 
145             * @param disableDoubleClickZoom
146             */
147            public final native void setDisableDoubleClickZoom(
148                            boolean disableDoubleClickZoom) /*-{
149                    this.disableDoubleClickZoom = disableDoubleClickZoom;
150            }-*/;
151    
152            /**
153             * get enables/disables zoom and center on double click. Enabled by default.
154             * 
155             * @return boolean
156             */
157            public final native boolean getDisableDoubleClickZoom() /*-{
158                    return this.disableDoubleClickZoom;
159            }-*/;
160    
161            /**
162             * set If false, prevents the map from being dragged. Dragging is enabled by
163             * default.
164             * 
165             * @param draggable
166             */
167            public final native void setDraggable(boolean draggable) /*-{
168                    this.draggable = draggable;
169            }-*/;
170    
171            /**
172             * get If false, prevents the map from being dragged. Dragging is enabled by
173             * default.
174             * 
175             * @return boolean
176             */
177            public final native boolean getDraggable() /*-{
178                    return this.draggable;
179            }-*/;
180    
181            /**
182             * set The name or url of the cursor to display on a draggable object.
183             * 
184             * @param draggableCursor
185             */
186            public final native void setDraggableCursor(boolean draggableCursor) /*-{
187                    this.draggableCursor = draggableCursor;
188            }-*/;
189    
190            /**
191             * get The name or url of the cursor to display on a draggable object.
192             */
193            public final native boolean getDraggableCursor() /*-{
194                    return this.draggableCursor;
195            }-*/;
196    
197            /**
198             * set The name or url of the cursor to display when an object is dragging.
199             * 
200             * @param draggingCursor
201             */
202            public final native void setDraggingCursor(boolean draggingCursor) /*-{
203                    this.draggingCursor = draggingCursor;
204            }-*/;
205    
206            /**
207             * get The name or url of the cursor to display when an object is dragging.
208             */
209            public final native boolean getDraggingCursor() /*-{
210                    return this.draggingCursor;
211            }-*/;
212    
213            /**
214             * set The heading for aerial imagery in degrees measured clockwise from
215             * cardinal direction North. Headings are snapped to the nearest available
216             * angle for which imagery is available.
217             * 
218             * @param heading
219             */
220            public final native void setHeading(int heading) /*-{
221                    this.heading = heading;
222            }-*/;
223    
224            /**
225             * get The heading for aerial imagery in degrees measured clockwise from
226             * cardinal direction North. Headings are snapped to the nearest available
227             * angle for which imagery is available.
228             * 
229             * @return int
230             */
231            public final native int getHeading() /*-{
232                    return this.heading;
233            }-*/;
234    
235            /**
236             * set If false, prevents the map from being controlled by the keyboard.
237             * Keyboard shortcuts are enabled by default.
238             * 
239             * @param keyboardShortcuts
240             */
241            public final native void setKeyboardShortcuts(boolean keyboardShortcuts) /*-{
242                    this.keyboardShortcuts = keyboardShortcuts;
243            }-*/;
244    
245            /**
246             * get If false, prevents the map from being controlled by the keyboard.
247             * Keyboard shortcuts are enabled by default.
248             * 
249             * @return boolean
250             */
251            public final native boolean getKeyboardShortcuts() /*-{
252                    return this.keyboardShortcuts;
253            }-*/;
254    
255            /**
256             * set The initial enabled/disabled state of the Map type control.
257             * 
258             * @param mapTypeControl
259             */
260            public final native void setMapTypeControl(boolean mapTypeControl) /*-{
261                    this.mapTypeControl = mapTypeControl;
262            }-*/;
263    
264            /**
265             * get The initial enabled/disabled state of the Map type control.
266             */
267            public final native boolean getMapTypeControl() /*-{
268                    return this.mapTypeControl;
269            }-*/;
270    
271            /**
272             * set The initial display options for the Map type control.
273             * 
274             * @param mapTypeControlOptions
275             */
276            public final native void setMapTypeControlOptions(
277                            MapTypeControlOptions mapTypeControlOptions) /*-{
278                    this.mapTypeControlOptions = mapTypeControlOptions;
279            }-*/;
280    
281            /**
282             * get The initial display options for the Map type control.
283             * 
284             * @return {@link MapTypeControlOptions}
285             */
286            public final native MapTypeControlOptions getMapTypeControlOptions() /*-{
287                    return this.mapTypeControlOptions;
288            }-*/;
289    
290            /**
291             * The initial Map {@link MapTypeId}. Required.
292             * 
293             * @param mapTypeId
294             *            {@link MapTypeId}
295             */
296            public final void setMapTypeId(MapTypeId mapTypeId) {
297                    setMapTypeIdJs(mapTypeId.value());
298            }
299    
300            /**
301             * The initial Map {@link MapTypeId}. Required.
302             * 
303             * @param mapTypeId
304             *            String
305             */
306            public final void setMapTypeId(String mapTypeId) {
307                    setMapTypeIdStringJs(mapTypeId);
308            }
309    
310            /**
311             * Native Use. Use setMapTypeId(MapTypeId mapTypeId). The initial Map
312             * {@link MapTypeId}. Required.
313             */
314            private final native void setMapTypeIdJs(String type) /*-{
315                    this.mapTypeId = $wnd.google.maps.MapTypeId[type];
316            }-*/;
317            
318            /**
319             * Native Use. Apply a given user defined map type string. Required.
320             */
321            private final native void setMapTypeIdStringJs(String type) /*-{
322                    this.mapTypeId = type;
323            }-*/;
324    
325            /**
326             * Get {@link MapTypeId}
327             */
328            public final MapTypeId getMapTypeId() {
329                    String type = getMapTypeIdJs();
330                    return MapTypeId.fromValue(type);
331            }
332    
333            /**
334             * Get mapTypeId string
335             */
336            public final String getMapTypeIdString() {
337                    return getMapTypeIdJs();
338            }
339    
340            /**
341             * native use. get {@link MapTypeId}
342             * 
343             * @return String
344             */
345            private final native String getMapTypeIdJs() /*-{
346                    return this.mapTypeId;
347            }-*/;
348    
349            /**
350             * set The maximum zoom level which will be displayed on the map. If
351             * omitted, or set to null, the maximum zoom from the current map type is
352             * used instead.
353             * 
354             * @param maxZoom
355             */
356            public final native void setMaxZoom(int maxZoom) /*-{
357                    this.maxZoom = maxZoom;
358            }-*/;
359    
360            /**
361             * get maxZoom
362             * 
363             * @return int
364             */
365            public final native int getMaxZoom() /*-{
366                    return this.maxZoom;
367            }-*/;
368    
369            /**
370             * set The minimum zoom level which will be displayed on the map. If
371             * omitted, or set to null, the minimum zoom from the current map type is
372             * used instead.
373             * 
374             * @param minZoom
375             */
376            public final native void setMinZoom(int minZoom) /*-{
377                    this.minZoom = minZoom;
378            }-*/;
379    
380            /**
381             * get The minimum zoom level which will be displayed on the map. If
382             * omitted, or set to null, the minimum zoom from the current map type is
383             * used instead.
384             */
385            public final native int getMinZoom() /*-{
386                    return this.minZoom;
387            }-*/;
388    
389            /**
390             * set If true, do not clear the contents of the Map div.
391             * 
392             * @param noClear
393             */
394            public final native void setNoClear(boolean noClear) /*-{
395                    this.noClear = noClear;
396            }-*/;
397    
398            /**
399             * get If true, do not clear the contents of the Map div.
400             */
401            public final native boolean getNoClear() /*-{
402                    return this.noClear;
403            }-*/;
404    
405            /**
406             * set The enabled/disabled state of the Overview Map control.
407             * 
408             * @param overviewMapControl
409             */
410            public final native void setOverviewMapControl(boolean overviewMapControl) /*-{
411                    this.overviewMapControl = overviewMapControl;
412            }-*/;
413    
414            /**
415             * get The enabled/disabled state of the Overview Map control.
416             */
417            public final native boolean getOverviewMapControl() /*-{
418                    return this.overviewMapControl;
419            }-*/;
420    
421            /**
422             * set The display options for the Overview Map control.
423             * {@link OverviewMapControlOptions}
424             * 
425             * @param overviewMapControlOptions
426             */
427            public final native void setOverviewMapControlOptions(
428                            OverviewMapControlOptions overviewMapControlOptions) /*-{
429                    this.overviewMapControlOptions = overviewMapControlOptions;
430            }-*/;
431    
432            /**
433             * get The display options for the Overview Map control.
434             * 
435             * @return {@link OverviewMapControlOptions}
436             */
437            public final native OverviewMapControlOptions getOverviewMapControlOptions() /*-{
438                    return this.overviewMapControlOptions;
439            }-*/;
440    
441            /**
442             * The enabled/disabled state of the Pan control.
443             * 
444             * @param panControl
445             */
446            public final native void setPanControl(boolean panControl) /*-{
447                    this.panControl = panControl;
448            }-*/;
449    
450            /**
451             * get The enabled/disabled state of the Pan control.
452             * 
453             * @return boolean
454             */
455            public final native boolean getPanControl() /*-{
456                    return this.panControl;
457            }-*/;
458    
459            /**
460             * sets The display options for the Pan control.
461             * 
462             * @param panControlOptions
463             *            {@link PanControlOptions}
464             */
465            public final native void setPanControlOptions(
466                            PanControlOptions panControlOptions) /*-{
467                    this.panControlOptions = panControlOptions;
468            }-*/;
469    
470            /**
471             * gets The display options for the Pan control.
472             * 
473             * @return {@link PanControlOptions}
474             */
475            public final native PanControlOptions getPanControlOptions() /*-{
476                    return this.panControlOptions;
477            }-*/;
478    
479            /**
480             * set The enabled/disabled state of the Rotate control.
481             * 
482             * @param rotateControl
483             */
484            public final native void setRotateControl(boolean rotateControl) /*-{
485                    this.rotateControl = rotateControl;
486            }-*/;
487    
488            /**
489             * get The enabled/disabled state of the Rotate control.
490             */
491            public final native boolean getRotateControl() /*-{
492                    return this.rotateControl;
493            }-*/;
494    
495            /**
496             * set The display options for the Rotate control.
497             * 
498             * @param rotateControlOptions
499             *            {@link RotateControlOptions}
500             */
501            public final native void setRotateControlOptions(
502                            RotateControlOptions rotateControlOptions) /*-{
503                    this.rotateControlOptions = rotateControlOptions;
504            }-*/;
505    
506            /**
507             * get set The display options for the Rotate control.
508             * 
509             * @return {@link RotateControlOptions}
510             */
511            public final native RotateControlOptions getRotateControlOptions() /*-{
512                    return this.rotateControlOptions;
513            }-*/;
514    
515            /**
516             * set The initial enabled/disabled state of the Scale control.
517             * 
518             * @param scaleControl
519             */
520            public final native void setScaleControl(boolean scaleControl) /*-{
521                    this.scaleControl = scaleControl;
522            }-*/;
523    
524            /**
525             * get The initial enabled/disabled state of the Scale control.
526             * 
527             * @return boolean
528             */
529            public final native boolean getScaleControl() /*-{
530                    return this.scaleControl;
531            }-*/;
532    
533            /**
534             * set The initial display options for the Scale control.
535             * 
536             * @param scaleControlOptions
537             *            {@link ScaleControlOptions}
538             */
539            public final native void setScaleControlOptions(
540                            ScaleControlOptions scaleControlOptions) /*-{
541                    this.scaleControlOptions = scaleControlOptions;
542            }-*/;
543    
544            /**
545             * get The initial display options for the Scale control.
546             * 
547             * @return {@link ScaleControlOptions}
548             */
549            public final native ScaleControlOptions getScaleControlOptions() /*-{
550                    return this.scaleOptions;
551            }-*/;
552    
553            /**
554             * set If false, disables scrollwheel zooming on the map. The scrollwheel is
555             * enabled by default.
556             * 
557             * @param scrollWheel
558             */
559            public final native void setScrollWheel(boolean scrollWheel) /*-{
560                    this.scrollWheel = scrollWheel;
561            }-*/;
562    
563            /**
564             * get If false, disables scrollwheel zooming on the map. The scrollwheel is
565             * enabled by default.
566             */
567            public final native boolean getScrollWheel() /*-{
568                    return this.scrollWheel;
569            }-*/;
570    
571            /**
572             * set A StreetViewPanorama to display when the Street View Pegman is
573             * dropped on the map. If no panorama is specified, a default
574             * StreetViewPanorama will be displayed in the map's div when the pegman is
575             * dropped.
576             * 
577             * @param streetViewControl
578             */
579            public final native void setStreetViewControl(boolean streetViewControl) /*-{
580                    this.streetViewControl = streetViewControl;
581            }-*/;
582    
583            /**
584             * get set A StreetViewPanorama to display when the Street View pegman is
585             * dropped on the map. If no panorama is specified, a default
586             * StreetViewPanorama will be displayed in the map's div when the pegman is
587             * dropped.
588             */
589            public final native boolean getStreetViewControl() /*-{
590                    return this.streetViewControl;
591            }-*/;
592    
593            /**
594             * The initial enabled/disabled state of the Street View Pegman control.
595             * This control is part of the default UI, and should be set to false when
596             * displaying a map type on which the Street View road overlay should not
597             * appear (e.g. a non-Earth map type).
598             * 
599             * @param streetViewControlOptions
600             *            {@link StreetViewControlOptions}
601             */
602            public final native void setStreetViewControlOptions(
603                            StreetViewControlOptions streetViewControlOptions) /*-{
604                    this.streetViewControlOptions = streetViewControlOptions;
605            }-*/;
606    
607            /**
608             * get The initial enabled/disabled state of the Street View Pegman control.
609             * This control is part of the default UI, and should be set to false when
610             * displaying a map type on which the Street View road overlay should not
611             * appear (e.g. a non-Earth map type).
612             * 
613             * @return {@link StreetViewControlOptions}
614             */
615            public final native StreetViewControlOptions getStreetViewControlOptions() /*-{
616                    return this.streetViewcontrolOptions;
617            }-*/;
618    
619            public final void setMapTypeStyles(MapTypeStyle[] styles) {
620                    JsArray<MapTypeStyle> arr = ArrayHelper.toJsArray(styles);
621                    setMapTypeStyles(arr);
622            }
623    
624            /**
625             * set Styles to apply to each of the default map types. Note that styles
626             * will apply only to the labels and geometry in Satellite/Hybrid and
627             * Terrain modes.
628             */
629            private final native void setMapTypeStyles(JsArray<MapTypeStyle> styles) /*-{
630                    this.styles = styles;
631            }-*/;
632    
633            /**
634             * get set Styles to apply to each of the default map types. Note that
635             * styles will apply only to the labels and geometry in Satellite/Hybrid and
636             * Terrain modes.
637             */
638            public final MapTypeStyle[] getMapTypeStyles() {
639                    JsArray<MapTypeStyle> arr = getMapTypeStylesJs();
640                    MapTypeStyle[] r = new MapTypeStyle[arr.length()];
641                    for (int i = 0; i < arr.length(); i++) {
642                            r[i] = arr.get(i);
643                    }
644                    return r;
645            }
646    
647            /**
648             * get set Styles to apply to each of the default map types. Note that
649             * styles will apply only to the labels and geometry in Satellite/Hybrid and
650             * Terrain modes.
651             */
652            private final native JsArray<MapTypeStyle> getMapTypeStylesJs() /*-{
653                    return this.styles;
654            }-*/;
655    
656            /**
657             * sets The angle of incidence of the map as measured in degrees from the
658             * viewport plane to the map plane. The only currently supported values are
659             * 0, indicating no angle of incidence (no tilt), and 45, indicating a tilt
660             * of 45&deg;. 45&deg; imagery is only available for SATELLITE and HYBRID
661             * map types, within some locations, and at some zoom levels.
662             */
663            public final native void setTilt(int tilt) /*-{
664                    this.tilt = tilt;
665            }-*/;
666    
667            /**
668             * gets The angle of incidence of the map as measured in degrees from the
669             * viewport plane to the map plane. The only currently supported values are
670             * 0, indicating no angle of incidence (no tilt), and 45, indicating a tilt
671             * of 45&deg;. 45&deg; imagery is only available for SATELLITE and HYBRID
672             * map types, within some locations, and at some zoom levels.
673             */
674            public final native int getTilt() /*-{
675                    return this.tilt;
676            }-*/;
677    
678            /**
679             * The initial Map zoom level. Required.
680             * 
681             * @param zoom
682             */
683            public final native void setZoom(int zoom) /*-{
684                    this.zoom = zoom;
685            }-*/;
686    
687            /**
688             * get Map zoom level
689             * 
690             * @return int
691             */
692            public final native int getZoom() /*-{
693                    return this.zoom;
694            }-*/;
695    
696            /**
697             * sets The enabled/disabled state of the Zoom control.
698             * 
699             * @param zoomControl
700             */
701            public final native void setZoomControl(boolean zoomControl) /*-{
702                    this.zoomControl = zoomControl;
703            }-*/;
704    
705            /**
706             * gets The enabled/disabled state of the Zoom control.
707             */
708            public final native boolean getZoomControl() /*-{
709                    return this.zoomControl;
710            }-*/;
711    
712            /**
713             * sets The display options for the Zoom control.
714             * 
715             * @param zoomControlOptions
716             */
717            public final native void setZoomControlOptions(
718                            ZoomControlOptions zoomControlOptions) /*-{
719                    this.zoomControlOptions = zoomControlOptions;
720            }-*/;
721    
722            /**
723             * gets The display options for the Zoom control.
724             */
725            public final native ZoomControlOptions getZoomControlOptions() /*-{
726                    return this.zoomControlOptions;
727            }-*/;
728    
729            
730            public final String toString2() {
731                    return "Type:"+getMapTypeIdJs()+
732                                    ", Styles:"+getMapTypeStyles();
733            }
734    }