001 package com.google.gwt.maps.client.overlays; 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.base.LatLng; 008 import com.google.gwt.maps.client.events.MapEventType; 009 import com.google.gwt.maps.client.events.MapHandlerRegistration; 010 import com.google.gwt.maps.client.events.animation.AnimationChangeEventFormatter; 011 import com.google.gwt.maps.client.events.animation.AnimationChangeMapHandler; 012 import com.google.gwt.maps.client.events.click.ClickEventFormatter; 013 import com.google.gwt.maps.client.events.click.ClickMapHandler; 014 import com.google.gwt.maps.client.events.clickable.ClickableChangeEventFormatter; 015 import com.google.gwt.maps.client.events.clickable.ClickableChangeMapHandler; 016 import com.google.gwt.maps.client.events.cursor.CursorChangeEventFormatter; 017 import com.google.gwt.maps.client.events.cursor.CursorChangeMapHandler; 018 import com.google.gwt.maps.client.events.dblclick.DblClickEventFormatter; 019 import com.google.gwt.maps.client.events.dblclick.DblClickMapHandler; 020 import com.google.gwt.maps.client.events.drag.DragEventFormatter; 021 import com.google.gwt.maps.client.events.drag.DragMapHandler; 022 import com.google.gwt.maps.client.events.dragend.DragEndEventFormatter; 023 import com.google.gwt.maps.client.events.dragend.DragEndMapHandler; 024 import com.google.gwt.maps.client.events.draggable.DraggableChangeEventFormatter; 025 import com.google.gwt.maps.client.events.draggable.DraggableChangeMapHandler; 026 import com.google.gwt.maps.client.events.dragstart.DragStartEventFormatter; 027 import com.google.gwt.maps.client.events.dragstart.DragStartMapHandler; 028 import com.google.gwt.maps.client.events.flat.FlatChangeEventFormatter; 029 import com.google.gwt.maps.client.events.flat.FlatChangeMapHandler; 030 import com.google.gwt.maps.client.events.icon.IconChangeEventFormatter; 031 import com.google.gwt.maps.client.events.icon.IconChangeMapHandler; 032 import com.google.gwt.maps.client.events.mousedown.MouseDownEventFormatter; 033 import com.google.gwt.maps.client.events.mousedown.MouseDownMapHandler; 034 import com.google.gwt.maps.client.events.mouseout.MouseOutEventFormatter; 035 import com.google.gwt.maps.client.events.mouseout.MouseOutMapHandler; 036 import com.google.gwt.maps.client.events.mouseover.MouseOverEventFormatter; 037 import com.google.gwt.maps.client.events.mouseover.MouseOverMapHandler; 038 import com.google.gwt.maps.client.events.mouseup.MouseUpEventFormatter; 039 import com.google.gwt.maps.client.events.mouseup.MouseUpMapHandler; 040 import com.google.gwt.maps.client.events.projection.ProjectionChangeEventFormatter; 041 import com.google.gwt.maps.client.events.projection.ProjectionChangeMapHandler; 042 import com.google.gwt.maps.client.events.rightclick.RightClickEventFormatter; 043 import com.google.gwt.maps.client.events.rightclick.RightClickMapHandler; 044 import com.google.gwt.maps.client.events.shadow.ShadowChangeEventFormatter; 045 import com.google.gwt.maps.client.events.shadow.ShadowChangeMapHandler; 046 import com.google.gwt.maps.client.events.shape.ShapeChangeEventFormatter; 047 import com.google.gwt.maps.client.events.shape.ShapeChangeMapHandler; 048 import com.google.gwt.maps.client.events.title.TitleChangeEventFormatter; 049 import com.google.gwt.maps.client.events.title.TitleChangeMapHandler; 050 import com.google.gwt.maps.client.events.visible.VisibleChangeEventFormatter; 051 import com.google.gwt.maps.client.events.visible.VisibleChangeMapHandler; 052 import com.google.gwt.maps.client.events.zindex.ZindexChangeEventFormatter; 053 import com.google.gwt.maps.client.events.zindex.ZindexChangeMapHandler; 054 import com.google.gwt.maps.client.mvc.MVCObject; 055 import com.google.gwt.maps.client.streetview.StreetViewPanoramaImpl; 056 import com.google.gwt.maps.client.streetview.StreetViewPanoramaWidget; 057 058 /** 059 * Creates a marker with the options specified. If a map is specified, the marker is added to the map upon construction. Note that the position must be set for the marker to display. 060 * This class extends MVCObject. 061 * <br><br> 062 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#Marker">Marker API Doc</a> 063 */ 064 public class Marker extends MVCObject<Marker> { 065 066 /** 067 * Creates a marker with the options specified. If a map is specified, the marker is added to the map upon construction. Note that the position must be set for the marker to display. 068 * use newInstance(); 069 */ 070 protected Marker() {} 071 072 /** 073 * Creates a marker with the options specified. If a map is specified, the marker is added to the map upon construction. Note that the position must be set for the marker to display. 074 * @param options {@link MarkerOptions} 075 */ 076 public static Marker newInstance(MarkerOptions options) { 077 return createJso(options).cast(); 078 } 079 080 private static final native JavaScriptObject createJso(MarkerOptions options) /*-{ 081 return new $wnd.google.maps.Marker(options); 082 }-*/; 083 084 /** 085 * get animation 086 */ 087 public final Animation getAnimation() { 088 String animation = getAnimationImpl(); 089 if (animation == null) { 090 return null; 091 } 092 return Animation.fromValue(animation); 093 } 094 095 private final native String getAnimationImpl() /*-{ 096 return this.getAnimation(); 097 }-*/; 098 099 /** 100 * get Clickable 101 */ 102 public final native boolean getClickable() /*-{ 103 return this.getClickable(); 104 }-*/; 105 106 /** 107 * get Cursor 108 */ 109 public final native String getCursor() /*-{ 110 return this.getCursor(); 111 }-*/; 112 113 /** 114 * get Draggable 115 */ 116 public final native boolean getDraggable() /*-{ 117 return this.getDraggable(); 118 }-*/; 119 120 /** 121 * get Flat 122 */ 123 public final native boolean getFlat() /*-{ 124 return this.getFlat(); 125 }-*/; 126 127 /** 128 * get Icon (if its a string use this) 129 */ 130 public final native String getIcon_String() /*-{ 131 return this.getIcon(); 132 }-*/; 133 134 /** 135 * get Icon (if it is a marker image) 136 */ 137 public final native MarkerImage getIcon_MarkerImage() /*-{ 138 return this.getIcon(); 139 }-*/; 140 141 public final MapWidget getMap() { 142 return MapWidget.newInstance(getMapImpl()); 143 } 144 145 private final native MapImpl getMapImpl() /*-{ 146 return this.getMap(); 147 }-*/;; 148 149 /** 150 * get Map (if it is a pano) 151 */ 152 public final StreetViewPanoramaWidget getMap_StreetViewPanorama() { 153 return StreetViewPanoramaWidget.newInstance(getMap_StreetViewPanoramaImpl()); 154 } 155 156 private final native StreetViewPanoramaImpl getMap_StreetViewPanoramaImpl() /*-{ 157 return this.getMap(); 158 }-*/; 159 160 /** 161 * get Position 162 */ 163 public final native LatLng getPosition() /*-{ 164 return this.getPosition(); 165 }-*/; 166 167 /** 168 * get Shadow (if it is a String) 169 */ 170 public final native String getShadow_String() /*-{ 171 return this.getShadow(); 172 }-*/; 173 174 /** 175 * get Shadow (if it is a MarkerImage) 176 */ 177 public final native MarkerImage getShadow_MarkerImage() /*-{ 178 return this.getShadow(); 179 }-*/; 180 181 /** 182 * get Shape 183 */ 184 public final native MarkerShape getShape() /*-{ 185 return this.getShape(); 186 }-*/; 187 188 /** 189 * get Title 190 */ 191 public final native String getTitle() /*-{ 192 return this.getTitle(); 193 }-*/; 194 195 /** 196 * get Visible 197 */ 198 public final native boolean getVisible() /*-{ 199 return this.getVisible(); 200 }-*/; 201 202 /** 203 * get Z Index 204 */ 205 public final native int getZindex() /*-{ 206 return this.getZIndex(); 207 }-*/; 208 209 /** 210 * set Animation 211 * @param animation 212 */ 213 public final void setAnimation(Animation animation) { 214 setAnimationImpl(animation.value()); 215 } 216 217 private final native void setAnimationImpl(String animation) /*-{ 218 this.setAnimation(animation); 219 }-*/; 220 221 /** 222 * set Clickable 223 * @param clickable 224 */ 225 public final native void setClickable(boolean clickable) /*-{ 226 this.setClickable(clickable); 227 }-*/; 228 229 /** 230 * set Cursor 231 * @param cursor 232 */ 233 public final native void setCursor(String cursor) /*-{ 234 this.setCursor(cursor); 235 }-*/; 236 237 /** 238 * set Draggable 239 * @param draggable 240 */ 241 public final native void setDraggable(boolean draggable) /*-{ 242 this.setDraggable(draggable); 243 }-*/; 244 245 /** 246 * set Flat 247 * @param flat 248 */ 249 public final native void setFlat(boolean flat) /*-{ 250 this.setFlat(flat); 251 }-*/; 252 253 /** 254 * set Icon 255 * @param icon 256 */ 257 public final native void setIcon(String icon) /*-{ 258 this.setIcon(icon); 259 }-*/; 260 261 /** 262 * set Icon 263 * @param icon 264 */ 265 public final native void setIcon(MarkerImage icon) /*-{ 266 this.setIcon(icon); 267 }-*/; 268 269 /** 270 * set Map 271 * @param mapWidget 272 */ 273 public final void setMap(MapWidget mapWidget) { 274 if (mapWidget == null) { 275 close(); 276 } else { 277 setMapImpl(mapWidget.getJso()); 278 } 279 } 280 281 private final native void setMapImpl(MapImpl map) /*-{ 282 this.setMap(map); 283 }-*/; 284 285 /** 286 * set Map 287 * @param pano 288 */ 289 public final void setMap(StreetViewPanoramaWidget pano) { 290 setMapImpl(pano.getJso()); 291 } 292 293 private final native void setMapImpl(StreetViewPanoramaImpl pano) /*-{ 294 this.setMap(pano); 295 }-*/; 296 297 /** 298 * set Options 299 * @param options 300 */ 301 public final native void setOptions(MarkerOptions options) /*-{ 302 this.setOptions(options); 303 }-*/; 304 305 /** 306 * set Position 307 * @param latlng 308 */ 309 public final native void setPosition(LatLng latlng) /*-{ 310 this.setPosition(latlng); 311 }-*/; 312 313 /** 314 * set Shadow 315 * @param shadow 316 */ 317 public final native void setShadow(String shadow) /*-{ 318 this.setShadow(shadow); 319 }-*/; 320 321 /** 322 * set MarkerImage 323 * @param markerImage 324 */ 325 public final native void setShadow(MarkerImage markerImage) /*-{ 326 this.setShadow(markerImage); 327 }-*/; 328 329 /** 330 * set Shape 331 * @param shape 332 */ 333 public final native void setShape(MarkerShape shape) /*-{ 334 this.setShape(shape); 335 }-*/; 336 337 /** 338 * set Title 339 * @param title 340 */ 341 public final native void setTitle(String title) /*-{ 342 this.setTitle(title); 343 }-*/; 344 345 /** 346 * set Visible 347 * @param visible 348 */ 349 public final native void setVisible(boolean visible) /*-{ 350 this.setVisible(visible); 351 }-*/; 352 353 /** 354 * set Z index 355 * @param number 356 */ 357 public final native void setZindex(int number) /*-{ 358 this.setZIndex(number); 359 }-*/; 360 361 /** 362 * The maximum default z-index that the API will assign to a marker. You may set a higher z-index to bring a marker to the front. 363 */ 364 public final native int getMax_Zindex() /*-{ 365 return $wnd.google.maps.Marker.MAX_ZINDEX; 366 }-*/; 367 368 /** 369 * This event is fired when the marker's animation property changes. 370 * @param handler 371 */ 372 public final HandlerRegistration addAnimationChangeHandler(AnimationChangeMapHandler handler) { 373 return MapHandlerRegistration.addHandler(this, MapEventType.ANIMATION_CHANGED, handler, new AnimationChangeEventFormatter()); 374 } 375 376 /** 377 * This event is fired when the marker icon was clicked. 378 * @param handler 379 */ 380 public final HandlerRegistration addClickHandler(ClickMapHandler handler) { 381 return MapHandlerRegistration.addHandler(this, MapEventType.CLICK, handler, new ClickEventFormatter()); 382 } 383 384 /** 385 * This event is fired when the marker's clickable property changes. 386 * @param handler 387 */ 388 public final HandlerRegistration addClickableChangeHandler(ClickableChangeMapHandler handler) { 389 return MapHandlerRegistration.addHandler(this, MapEventType.CLICKABLE_CHANGED, handler, new ClickableChangeEventFormatter()); 390 } 391 392 /** 393 * This event is fired when the marker's cursor property changes. 394 * @param handler 395 */ 396 public final HandlerRegistration addCursorChangeHandler(CursorChangeMapHandler handler) { 397 return MapHandlerRegistration.addHandler(this, MapEventType.CURSOR_CHANGED, handler, new CursorChangeEventFormatter()); 398 } 399 400 /** 401 * This event is fired when the marker icon was double clicked. 402 * @param handler 403 */ 404 public final HandlerRegistration addDblClickHandler(DblClickMapHandler handler) { 405 return MapHandlerRegistration.addHandler(this, MapEventType.DBLCLICK, handler, new DblClickEventFormatter()); 406 } 407 408 /** 409 * This event is repeatedly fired while the user drags the marker. 410 * @param handler 411 */ 412 public final HandlerRegistration addDragHandler(DragMapHandler handler) { 413 return MapHandlerRegistration.addHandler(this, MapEventType.DRAG, handler, new DragEventFormatter()); 414 } 415 416 /** 417 * This event is fired when the user stops dragging the marker. 418 * @param handler 419 */ 420 public final HandlerRegistration addDragEndHandler(DragEndMapHandler handler) { 421 return MapHandlerRegistration.addHandler(this, MapEventType.DRAGEND, handler, new DragEndEventFormatter()); 422 } 423 424 /** 425 * This event is fired when the marker's draggable property changes. 426 * @param handler 427 */ 428 public final HandlerRegistration addDraggableChangeHandler(DraggableChangeMapHandler handler) { 429 return MapHandlerRegistration.addHandler(this, MapEventType.DRAGGABLE_CHANGED, handler, new DraggableChangeEventFormatter()); 430 } 431 432 /** 433 * This event is fired when the user starts dragging the marker. 434 * @param handler 435 */ 436 public final HandlerRegistration addDragStartHandler(DragStartMapHandler handler) { 437 return MapHandlerRegistration.addHandler(this, MapEventType.DRAGSTART, handler, new DragStartEventFormatter()); 438 } 439 440 /** 441 * This event is fired when the marker's flat property changes. 442 * @param handler 443 */ 444 public final HandlerRegistration addFlatChangeHandler(FlatChangeMapHandler handler) { 445 return MapHandlerRegistration.addHandler(this, MapEventType.FLAT_CHANGED, handler, new FlatChangeEventFormatter()); 446 } 447 448 /** 449 * This event is fired when the marker icon property changes. 450 * @param handler 451 */ 452 public final HandlerRegistration addIconChangeHandler(IconChangeMapHandler handler) { 453 return MapHandlerRegistration.addHandler(this, MapEventType.ICON_CHANGED, handler, new IconChangeEventFormatter()); 454 } 455 456 /** 457 * This event is fired for a mousedown on the marker. 458 * @param handler 459 */ 460 public final HandlerRegistration addMouseDownHandler(MouseDownMapHandler handler) { 461 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEDOWN, handler, new MouseDownEventFormatter()); 462 } 463 464 /** 465 * This event is fired when the mouse leaves the area of the marker icon. 466 * @param handler 467 */ 468 public final HandlerRegistration addMouseOutMoveHandler(MouseOutMapHandler handler) { 469 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOUT, handler, new MouseOutEventFormatter()); 470 } 471 472 /** 473 * This event is fired when the mouse enters the area of the marker icon. 474 * @param handler 475 */ 476 public final HandlerRegistration addMouseOverHandler(MouseOverMapHandler handler) { 477 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEOVER, handler, new MouseOverEventFormatter()); 478 } 479 480 /** 481 * This event is fired for a mouseup on the marker. 482 * @param handler 483 */ 484 public final HandlerRegistration addMouseUpHandler(MouseUpMapHandler handler) { 485 return MapHandlerRegistration.addHandler(this, MapEventType.MOUSEUP, handler, new MouseUpEventFormatter()); 486 } 487 488 /** 489 * This event is fired when the marker position property changes. 490 * @param handler 491 */ 492 public final HandlerRegistration addProjectionChangeHandler(ProjectionChangeMapHandler handler) { 493 return MapHandlerRegistration.addHandler(this, MapEventType.PROJECTION_CHANGED, handler, new ProjectionChangeEventFormatter()); 494 } 495 496 /** 497 * This event is fired for a rightclick on the marker. 498 * @param handler 499 */ 500 public final HandlerRegistration addRightClickHandler(RightClickMapHandler handler) { 501 return MapHandlerRegistration.addHandler(this, MapEventType.RIGHTCLICK, handler, new RightClickEventFormatter()); 502 } 503 504 /** 505 * This event is fired when the marker's shadow property changes. 506 * @param handler 507 */ 508 public final HandlerRegistration addShadowChangeHandler(ShadowChangeMapHandler handler) { 509 return MapHandlerRegistration.addHandler(this, MapEventType.SHADOW_CHANGED, handler, new ShadowChangeEventFormatter()); 510 } 511 512 /** 513 * This event is fired when the marker's shape property changes. 514 * @param handler 515 */ 516 public final HandlerRegistration addShapeChangeHandler(ShapeChangeMapHandler handler) { 517 return MapHandlerRegistration.addHandler(this, MapEventType.SHAPE_CHANGED, handler, new ShapeChangeEventFormatter()); 518 } 519 520 /** 521 * This event is fired when the marker title property changes. 522 * @param handler 523 */ 524 public final HandlerRegistration addTitleChangeHandler(TitleChangeMapHandler handler) { 525 return MapHandlerRegistration.addHandler(this, MapEventType.TITLE_CHANGED, handler, new TitleChangeEventFormatter()); 526 } 527 528 /** 529 * This event is fired when the marker's visible property changes. 530 * @param handler 531 */ 532 public final HandlerRegistration addVisibleChangeHandler(VisibleChangeMapHandler handler) { 533 return MapHandlerRegistration.addHandler(this, MapEventType.VISIBLE_CHANGED, handler, new VisibleChangeEventFormatter()); 534 } 535 536 /** 537 * This event is fired when the marker's zIndex property changes. 538 * @param handler 539 */ 540 public final HandlerRegistration addZindexChangeHandler(ZindexChangeMapHandler handler) { 541 return MapHandlerRegistration.addHandler(this, MapEventType.ZINDEX_CHANGED, handler, new ZindexChangeEventFormatter()); 542 } 543 544 /** 545 * close the marker 546 */ 547 public final native void close() /*-{ 548 this.setMap(); 549 }-*/; 550 551 }