001 package com.google.gwt.maps.client; 002 003 import com.google.gwt.core.client.JavaScriptObject; 004 import com.google.gwt.dom.client.Element; 005 import com.google.gwt.event.shared.HandlerRegistration; 006 import com.google.gwt.maps.client.base.LatLng; 007 import com.google.gwt.maps.client.base.LatLngBounds; 008 import com.google.gwt.maps.client.controls.ControlPosition; 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.bounds.BoundsChangeEventFormatter; 012 import com.google.gwt.maps.client.events.bounds.BoundsChangeMapHandler; 013 import com.google.gwt.maps.client.events.center.CenterChangeEventFormatter; 014 import com.google.gwt.maps.client.events.center.CenterChangeMapHandler; 015 import com.google.gwt.maps.client.events.click.ClickEventFormatter; 016 import com.google.gwt.maps.client.events.click.ClickMapHandler; 017 import com.google.gwt.maps.client.events.dblclick.DblClickEventFormatter; 018 import com.google.gwt.maps.client.events.dblclick.DblClickMapHandler; 019 import com.google.gwt.maps.client.events.drag.DragEventFormatter; 020 import com.google.gwt.maps.client.events.drag.DragMapHandler; 021 import com.google.gwt.maps.client.events.dragend.DragEndEventFormatter; 022 import com.google.gwt.maps.client.events.dragend.DragEndMapHandler; 023 import com.google.gwt.maps.client.events.dragstart.DragStartEventFormatter; 024 import com.google.gwt.maps.client.events.dragstart.DragStartMapHandler; 025 import com.google.gwt.maps.client.events.heading.HeadingChangeEventFormatter; 026 import com.google.gwt.maps.client.events.heading.HeadingChangeMapHandler; 027 import com.google.gwt.maps.client.events.idle.IdleEventFormatter; 028 import com.google.gwt.maps.client.events.idle.IdleMapHandler; 029 import com.google.gwt.maps.client.events.maptypeid.MapTypeIdChangeEventFormatter; 030 import com.google.gwt.maps.client.events.maptypeid.MapTypeIdChangeMapHandler; 031 import com.google.gwt.maps.client.events.mousemove.MouseMoveEventFormatter; 032 import com.google.gwt.maps.client.events.mousemove.MouseMoveMapHandler; 033 import com.google.gwt.maps.client.events.mouseout.MouseOutEventFormatter; 034 import com.google.gwt.maps.client.events.mouseout.MouseOutMapHandler; 035 import com.google.gwt.maps.client.events.mouseover.MouseOverEventFormatter; 036 import com.google.gwt.maps.client.events.mouseover.MouseOverMapHandler; 037 import com.google.gwt.maps.client.events.projection.ProjectionChangeEventFormatter; 038 import com.google.gwt.maps.client.events.projection.ProjectionChangeMapHandler; 039 import com.google.gwt.maps.client.events.resize.ResizeEventFormatter; 040 import com.google.gwt.maps.client.events.resize.ResizeMapHandler; 041 import com.google.gwt.maps.client.events.rightclick.RightClickEventFormatter; 042 import com.google.gwt.maps.client.events.rightclick.RightClickMapHandler; 043 import com.google.gwt.maps.client.events.tiles.TilesLoadedEventFormatter; 044 import com.google.gwt.maps.client.events.tiles.TilesLoadedMapHandler; 045 import com.google.gwt.maps.client.events.tilt.TiltChangeEventFormatter; 046 import com.google.gwt.maps.client.events.tilt.TiltChangeMapHandler; 047 import com.google.gwt.maps.client.events.zoom.ZoomChangeEventFormatter; 048 import com.google.gwt.maps.client.events.zoom.ZoomChangeMapHandler; 049 import com.google.gwt.maps.client.maptypes.MapTypeRegistry; 050 import com.google.gwt.maps.client.maptypes.Projection; 051 import com.google.gwt.maps.client.maptypes.StyledMapType; 052 import com.google.gwt.maps.client.mvc.MVCArray; 053 import com.google.gwt.maps.client.mvc.MVCObject; 054 import com.google.gwt.maps.client.streetview.StreetViewPanoramaImpl; 055 056 /** 057 * Creates a new map inside of the given HTML container, which is typically a DIV element 058 * <br><br> 059 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#Map">Map API Doc</a> 060 */ 061 public class MapImpl extends MVCObject<MapImpl> { 062 063 /** 064 * Creates a new map inside of the given HTML container, which is typically a DIV element. 065 */ 066 protected MapImpl() {} 067 068 /** 069 * Creates a new map inside of the given HTML container, which is typically a DIV element. 070 * @param element - map dom element container, like a div 071 * @param options - {@link MapOptions} 072 * @return {@link MapImpl} 073 */ 074 public final static MapImpl newInstance(Element element, MapOptions options) { 075 return createJso(element, options); 076 } 077 078 /** 079 * private native method 080 * @param id - dom element id 081 * @param {@link MapOptions} 082 */ 083 private final static native MapImpl createJso(Element element, MapOptions options) /*-{ 084 return new $wnd.google.maps.Map(element, options); 085 }-*/; 086 087 /** 088 * Sets the viewport to contain the given bounds. 089 * @param bounds {@link LatLngBounds} 090 */ 091 public final native void fitBounds(LatLngBounds bounds) /*-{ 092 this.fitBounds(bounds); 093 }-*/; 094 095 /** 096 * Returns the lat/lng bounds of the current viewport. If the map is not yet initialized (i.e. the mapType is still null), or center and zoom have not been set then the result is null or undefined. 097 * @return {@link LatLngBounds} 098 */ 099 public final native LatLngBounds getBounds() /*-{ 100 return this.getBounds(); 101 }-*/; 102 103 /** 104 * return map center in coordinates 105 */ 106 public final native LatLng getCenter() /*-{ 107 return this.getCenter(); 108 }-*/; 109 110 /** 111 * Get map's containing element 112 */ 113 public final native Element getDiv() /*-{ 114 return this.getDiv(); 115 }-*/; 116 117 /** 118 * Returns the compass heading of aerial imagery. The heading value is measured in degrees (clockwise) from cardinal direction North. 119 * @return int 120 */ 121 public final native int getHeading() /*-{ 122 return this.getHeading() || 0; 123 }-*/; 124 125 /** 126 * gets {@link MapTypeId} 127 * @return {@link MapTypeId} 128 */ 129 public final MapTypeId getMapTypeId() { 130 return MapTypeId.fromValue(getMapTypeIdImpl()); 131 } 132 133 private final native String getMapTypeIdImpl() /*-{ 134 return this.getMapTypeId(); 135 }-*/; 136 137 /** 138 * Returns the current Projection. If the map is not yet initialized (i.e. the mapType is still null) then the result is null. Listen to projection_changed and check its value to ensure it is not null. 139 * @return {@link Projection} 140 */ 141 public final native Projection getProjection() /*-{ 142 return this.getProjection(); 143 }-*/; 144 145 /** 146 * Returns the default StreetViewPanorama bound to the map, which may be a default panorama embedded within the map, or the panorama set using setStreetView(). Changes to the map's streetViewControl will be reflected in the display of such a bound panorama. 147 * @return {@link StreetViewPanoramaImpl} 148 */ 149 public final native StreetViewPanoramaImpl getStreetView() /*-{ 150 return this.getStreetView(); 151 }-*/; 152 153 /** 154 * gets Returns the angle of incidence for aerial imagery (available for SATELLITE and HYBRID map types) measured in degrees from the viewport plane to the map plane. A value of 0 indicates no angle of incidence (no tilt) while 45° imagery will return a value of 45. 155 */ 156 public final native int getTilt() /*-{ 157 return this.getTilt(); 158 }-*/; 159 160 /** 161 * get zoom 162 */ 163 public final native int getZoom() /*-{ 164 return this.getZoom(); 165 }-*/; 166 167 /** 168 * Changes the center of the map by the given distance in pixels. If the distance is less than both the width and height of the map, the transition will be smoothly animated. Note that the map coordinate system increases from west to east (for x values) and north to south (for y values). 169 * @param x 170 * @param y 171 */ 172 public final native void panBy(int x, int y) /*-{ 173 this.panBy(x, y); 174 }-*/; 175 176 /** 177 * Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition will be smoothly animated. 178 * @param latLng 179 */ 180 public final native void panTo(LatLng latLng) /*-{ 181 this.panTo(latLng); 182 }-*/; 183 184 /** 185 * Pans the map by the minimum amount necessary to contain the given LatLngBounds. It makes no guarantee where on the map the bounds will be, except that as much of the bounds as possible will be visible. The bounds will be positioned inside the area bounded by the map type and navigation (pan, zoom, and Street View) controls, if they are present on the map. If the bounds is larger than the map, the map will be shifted to include the northwest corner of the bounds. If the change in the map's position is less than both the width and height of the map, the transition will be smoothly animated. 186 * @param latLngBounds 187 */ 188 public final native void panToBounds(LatLngBounds latLngBounds) /*-{ 189 this.panToBounds(latLngBounds); 190 }-*/; 191 192 /** 193 * set center 194 * @param latlng 195 */ 196 public final native void setCenter(LatLng latlng) /*-{ 197 this.setCenter(latlng); 198 }-*/; 199 200 /** 201 * Sets the compass heading for aerial imagery measured in degrees from cardinal direction North. 202 * @param heading 203 */ 204 public final native void setHeading(int heading) /*-{ 205 this.setHeading(heading); 206 }-*/; 207 208 /** 209 * set MapTypeId 210 * @param mapTypeId 211 */ 212 public final void setMapTypeId(MapTypeId mapTypeId) { 213 setMapTypeIdImpl(mapTypeId.name()); 214 } 215 216 private final native void setMapTypeIdImpl(String mapTypeId) /*-{ 217 this.setMapTypeId(mapTypeId); 218 }-*/; 219 220 /** 221 * set MapOptions 222 * @param options 223 */ 224 public final native void setOptions(MapOptions options) /*-{ 225 this.setOptions(options); 226 }-*/; 227 228 /** 229 * Sets the angle of incidence for aerial imagery (available for SATELLITE and HYBRID map types) measured in degrees from the viewport plane to the map plane. The only supported values are 0, indicating no angle of incidence (no tilt), and 45 indicating a tilt of 45°. 230 * @param panorama 231 */ 232 public final native void setStreetView(StreetViewPanoramaImpl panorama) /*-{ 233 this.setStreetView(panorama); 234 }-*/; 235 236 /** 237 * Sets the angle of incidence for aerial imagery (available for SATELLITE and HYBRID map types) measured in degrees from the viewport plane to the map plane. The only supported values are 0, indicating no angle of incidence (no tilt), and 45 indicating a tilt of 45°. 238 * @param tilt 239 */ 240 public final native void setTilt(int tilt) /*-{ 241 this.setTilt(tilt); 242 }-*/; 243 244 /** 245 * sets map zoom 246 * @param zoom 247 */ 248 public final native void setZoom(int zoom) /*-{ 249 this.setZoom(zoom); 250 }-*/; 251 252 /** 253 * TODO 254 * sets Additional controls to attach to the map. To add a control to the map, add the control's <code><div></code> to the MVCArray corresponding to the ControlPosition where it should be rendered. 255 * @param controls 256 */ 257 public final native void setControls(MVCArray<Element> controls) /*-{ 258 this.controls = controls; 259 }-*/; 260 261 /** 262 * sets Additional controls to attach to the map. To add a control to the map, add the control's <code><div></code> to the MVCArray corresponding to the ControlPosition where it should be rendered. 263 * @param controlPosition 264 * @param element 265 */ 266 public final void setControls(ControlPosition controlPosition, Element element) { 267 setControls(controlPosition.value(), element); 268 } 269 270 private final native void setControls(int controlPosition, Element element) /*-{ 271 this.controls[controlPosition].push(element); 272 }-*/; 273 274 /** 275 * TODO 276 * gets Additional controls to attach to the map. To add a control to the map, add the control's <code><div></code> to the MVCArray corresponding to the ControlPosition where it should be rendered. 277 */ 278 public final native MVCArray<Element> getControls() /*-{ 279 return controls; 280 }-*/; 281 282 /** 283 * TODO 284 * sets A registry of MapType instances by string ID. 285 * @param mapTypes 286 */ 287 public final native void setMapTypesRegistry(MapTypeRegistry mapTypes) /*-{ 288 this.mapTypes = mapTypes; 289 }-*/; 290 291 /** 292 * Set the custom map type into the map's registry 293 * @param mapTypeId 294 * @param styledType 295 */ 296 public final native void setCustomMapType(String mapTypeId, StyledMapType styledType) /*-{ 297 this.mapTypes.set(mapTypeId, styledType); 298 }-*/; 299 300 /** 301 * gets A registry of MapType instances by string ID. 302 */ 303 public final native MapTypeRegistry getMapTypeRegistry() /*-{ 304 return this.mapTypes; 305 }-*/; 306 307 /** 308 * TODO 309 * sets Additional map types to overlay. 310 * @param overlayMapTypes 311 */ 312 public final native void setOverlayMapTypes(MVCArray<JavaScriptObject> overlayMapTypes) /*-{ 313 this.overlayMapTypes = overlayMapTypes; 314 }-*/; 315 316 /** 317 * TODO 318 * gets Additional map types to overlay. 319 */ 320 public final native MVCArray<JavaScriptObject> getOverlayMapTypes() /*-{ 321 return this.overlayMapTypes; 322 }-*/; 323 324 /** 325 * This event is fired when the viewport bounds have changed. 326 * @param handler {@link BoundsChangeMapHandler} 327 * @return {@link MapHandlerRegistration} 328 */ 329 public final HandlerRegistration addBoundsChangeHandler(BoundsChangeMapHandler handler) { 330 return MapHandlerRegistration.addHandler(this, MapEventType.BOUNDS_CHANGED, handler, new BoundsChangeEventFormatter()); 331 } 332 333 /** 334 * This event is fired when the map center property changes. 335 * @param handler {@link CenterChangeMapHandler} 336 * @return {@link MapHandlerRegistration} 337 */ 338 public final HandlerRegistration addCenterChangeHandler(CenterChangeMapHandler handler) { 339 return MapHandlerRegistration.addHandler(this, MapEventType.CENTER_CHANGED, handler, new CenterChangeEventFormatter()); 340 } 341 342 /** 343 * This event is fired when the user clicks on the map (but not when they click on a marker or infowindow). 344 * @param handler {@link ClickMapHandler} 345 * @return {@link MapHandlerRegistration} 346 */ 347 public final HandlerRegistration addClickHandler(ClickMapHandler handler) { 348 return MapHandlerRegistration.addHandler(this, MapEventType.CLICK, handler, new ClickEventFormatter()); 349 } 350 351 /** 352 * This event is fired when the user double-clicks on the map. Note that the click event will also fire, right before this one. 353 * @param handler {@link DblClickMapHandler} 354 * @return {@link MapHandlerRegistration} 355 */ 356 public final HandlerRegistration addDblClickHandler(DblClickMapHandler handler) { 357 return MapHandlerRegistration.addHandler(this, MapEventType.DBLCLICK, handler, new DblClickEventFormatter()); 358 } 359 360 /** 361 * This event is repeatedly fired while the user drags the map. 362 * @param handler {@link DragMapHandler} 363 * @return {@link MapHandlerRegistration} 364 */ 365 public final HandlerRegistration addDragHandler(DragMapHandler handler) { 366 return MapHandlerRegistration.addHandler(this, MapEventType.DRAG, handler, new DragEventFormatter()); 367 } 368 369 /** 370 * This event is fired when the user stops dragging the map. 371 * @param handler {@link DragEndMapHandler} 372 * @return {@link MapHandlerRegistration} 373 */ 374 public final HandlerRegistration addDragEndHandler(DragEndMapHandler handler) { 375 return MapHandlerRegistration.addHandler(this, MapEventType.DRAGEND, handler, new DragEndEventFormatter()); 376 } 377 378 /** 379 * This event is fired when the user starts dragging the map. 380 * @param handler {@link DragStartMapHandler} 381 * @return {@link MapHandlerRegistration} 382 */ 383 public final HandlerRegistration addDragStartHandler(DragStartMapHandler handler) { 384 return MapHandlerRegistration.addHandler(this, MapEventType.DRAGSTART, handler, new DragStartEventFormatter()); 385 } 386 387 /** 388 * This event is fired when the map heading property changes. 389 * @param handler {@link HeadingChangeMapHandler} 390 * @return {@link MapHandlerRegistration} 391 */ 392 public final HandlerRegistration addHeadingChangeHandler(HeadingChangeMapHandler handler) { 393 return MapHandlerRegistration.addHandler(this, MapEventType.HEADING_CHANGED, handler, new HeadingChangeEventFormatter()); 394 } 395 396 /** 397 * This event is fired when the map becomes idle after panning or zooming. 398 * @param handler {@link IdleMapHandler} 399 * @return {@link MapHandlerRegistration} 400 */ 401 public final HandlerRegistration addIdleHandler(IdleMapHandler handler) { 402 return MapHandlerRegistration.addHandler(this, MapEventType.IDLE, handler, new IdleEventFormatter()); 403 } 404 405 /** 406 * This event is fired when the mapTypeId property changes. 407 * @param handler {@link MapTypeIdChangeMapHandler} 408 * @return {@link MapHandlerRegistration} 409 */ 410 public final HandlerRegistration addMapTypeIdChangeHandler(MapTypeIdChangeMapHandler handler) { 411 return MapHandlerRegistration.addHandler(this, MapEventType.MAPTYPEID_CHANGED, handler, new MapTypeIdChangeEventFormatter()); 412 } 413 414 /** 415 * This event is fired whenever the user's mouse moves over the map container. 416 * @param handler {@link MouseMoveMapHandler} 417 * @return {@link MapHandlerRegistration} 418 */ 419 public final HandlerRegistration addMouseMoveHandler(MouseMoveMapHandler handler) { 420 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEMOVE, handler, new MouseMoveEventFormatter()); 421 } 422 423 /** 424 * This event is fired when the user's mouse exits the map container. 425 * @param handler {@link MouseOutMapHandler} 426 * @return {@link MapHandlerRegistration} 427 */ 428 public final HandlerRegistration addMouseOutMoveHandler(MouseOutMapHandler handler) { 429 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOUT, handler, new MouseOutEventFormatter()); 430 } 431 432 /** 433 * This event is fired when the user's mouse enters the map container. 434 * @param handler {@link MouseOverMapHandler} 435 * @return {@link MapHandlerRegistration} 436 */ 437 public final HandlerRegistration addMouseOverHandler(MouseOverMapHandler handler) { 438 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOVER, handler, new MouseOverEventFormatter()); 439 } 440 441 /** 442 * This event is fired when the projection has changed. 443 * @param handler {@link ProjectionChangeMapHandler} 444 * @return {@link MapHandlerRegistration} 445 */ 446 public final HandlerRegistration addProjectionChangeHandler(ProjectionChangeMapHandler handler) { 447 return MapHandlerRegistration.addHandler(this, MapEventType.PROJECTION_CHANGED, handler, new ProjectionChangeEventFormatter()); 448 } 449 450 /** 451 * Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, 'resize') . 452 * @param handler {@link ResizeMapHandler} 453 * @return {@link MapHandlerRegistration} 454 */ 455 public final HandlerRegistration addResizeHandler(ResizeMapHandler handler) { 456 return MapHandlerRegistration.addHandler(this, MapEventType.RESIZE, handler, new ResizeEventFormatter()); 457 } 458 459 /** 460 * This event is fired when the DOM contextmenu event is fired on the map container. 461 * @param handler {@link RightClickMapHandler} 462 * @return {@link MapHandlerRegistration} 463 */ 464 public final HandlerRegistration addRightClickHandler(RightClickMapHandler handler) { 465 return MapHandlerRegistration.addHandler(this, MapEventType.RIGHTCLICK, handler, new RightClickEventFormatter()); 466 } 467 468 /** 469 * This event is fired when the visible tiles have finished loading. 470 * @param handler {@link TilesLoadedMapHandler} 471 * @return {@link MapHandlerRegistration} 472 */ 473 public final HandlerRegistration addTilesLoadedHandler(TilesLoadedMapHandler handler) { 474 return MapHandlerRegistration.addHandler(this, MapEventType.TILESLOADED, handler, new TilesLoadedEventFormatter()); 475 } 476 477 /** 478 * This event is fired when the map tilt property changes. 479 * @param handler {@link TiltChangeMapHandler} 480 * @return {@link MapHandlerRegistration} 481 */ 482 public final HandlerRegistration addTiltChangeHandler(TiltChangeMapHandler handler) { 483 return MapHandlerRegistration.addHandler(this, MapEventType.TILT_CHANGED, handler, new TiltChangeEventFormatter()); 484 } 485 486 /** 487 * This event is fired when the map zoom property changes. 488 * @param handler {@link ZoomChangeMapHandler} 489 * @return {@link MapHandlerRegistration} 490 */ 491 public final HandlerRegistration addZoomChangeHandler(ZoomChangeMapHandler handler) { 492 return MapHandlerRegistration.addHandler(this, MapEventType.ZOOM_CHANGED, handler, new ZoomChangeEventFormatter()); 493 } 494 495 }