Class GoogleMapAdvancedMarker
java.lang.Object
com.vaadin.flow.component.Component
com.flowingcode.vaadin.addons.googlemaps.GoogleMapAdvancedMarker
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,Serializable
@Tag("google-map-advanced-marker")
@JsModule("@flowingcode/google-map/google-map-advanced-marker.js")
public class GoogleMapAdvancedMarker
extends Component
A marker of the Google Map based on Google's Advanced Markers (
AdvancedMarkerElement),
the replacement for the deprecated markers used by GoogleMapMarker. Both kinds of
markers can be used on the same map.
Advanced Markers require the map to have a Map ID (see GoogleMap.setMapId(String)),
set before the map is shown. Otherwise, an IllegalStateException is thrown when the
marker is attached.
These GoogleMapMarker features are not available, as Advanced Markers have no
equivalent: animation, optimization, icon sprites, a label together with an icon, and the font
and CSS class of a label.
- Since:
- 2.7.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEvent that is called on marker's drag end.static classEvent called on marker's click.static classEvent called on marker's right click. -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new GoogleMapAdvancedMarker.GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable) Instantiates a new GoogleMapAdvancedMarker.GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable, GoogleMapIcon icon) Instantiates a new GoogleMapAdvancedMarker.GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable, String iconUrl) Instantiates a new GoogleMapAdvancedMarker. -
Method Summary
Modifier and TypeMethodDescriptionaddClickListener(ComponentEventListener<GoogleMapAdvancedMarker.GoogleMapAdvancedMarkerClickEvent> listener) Adds a click event listener to a marker.Adds a DragEndEvent listener.voidaddInfoWindow(String htmlContent) Sets the content of the info window that is shown when the marker is clicked.addRightClickListener(ComponentEventListener<GoogleMapAdvancedMarker.GoogleMapAdvancedMarkerRightClickEvent> listener) Adds a right click event listener to a marker.Gets the caption of the marker.Returns the url of the icon of the marker.longReturns the background color of the default pin.Returns the border color of the default pin.Returns the color of the default pin's glyph.doubleReturns the scale of the default pin.Returns the position of the marker.booleanChecks if the marker is draggable.booleanprotected voidonAttach(AttachEvent attachEvent) Checks that the map of this marker has a Map ID, which Advanced Markers require.voidsetCaption(String caption) Sets the caption of the marker.voidsetDraggable(boolean draggable) Enables/disables dragging of the marker.voidsetIcon(GoogleMapIcon icon) Sets the icon image of the marker, which is shown instead of the default pin.voidsetIconUrl(String iconUrl) Sets the url of the icon of the marker, which is shown instead of the default pin.voidsetIdentifier(long id) voidsetInfoWindowVisible(boolean visible) voidsetLabel(MarkerLabel label) Sets the label of the marker, which is shown in the default pin.voidsetPinBackground(String color) Sets the background color of the default pin.voidsetPinBorderColor(String color) Sets the border color of the default pin.voidsetPinGlyphColor(String color) Sets the color of the default pin's glyph (the circle in its center).voidsetPinScale(double scale) Sets the scale of the default pin.voidsetPosition(LatLon position) Sets the position of the marker.Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Constructor Details
-
GoogleMapAdvancedMarker
public GoogleMapAdvancedMarker()Instantiates a new GoogleMapAdvancedMarker. -
GoogleMapAdvancedMarker
Instantiates a new GoogleMapAdvancedMarker.- Parameters:
caption- The caption to use.position- The position of the markerdraggable- Can marker be dragged?
-
GoogleMapAdvancedMarker
Instantiates a new GoogleMapAdvancedMarker.- Parameters:
caption- The caption to use.position- The position of the markerdraggable- Can marker be dragged?iconUrl- the icon url as a string
-
GoogleMapAdvancedMarker
public GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable, GoogleMapIcon icon) Instantiates a new GoogleMapAdvancedMarker.- Parameters:
caption- The caption to use.position- The position of the markerdraggable- Can marker be dragged?icon- the icon image for the marker
-
-
Method Details
-
addInfoWindow
Sets the content of the info window that is shown when the marker is clicked.- Parameters:
htmlContent- the HTML content of the info window
-
isInfoWindowVisible
@Synchronize(value={"google-map-marker-open","google-map-marker-close"}, property="open") public boolean isInfoWindowVisible() -
setInfoWindowVisible
public void setInfoWindowVisible(boolean visible) -
getPosition
Returns the position of the marker.- Returns:
- The position of the marker.
-
setPosition
Sets the position of the marker.- Parameters:
position- The new position of the marker.
-
getCaption
Gets the caption of the marker.- Returns:
- The caption of the marker.
-
setCaption
Sets the caption of the marker.- Parameters:
caption- The new caption of the marker.
-
isDraggable
public boolean isDraggable()Checks if the marker is draggable.- Returns:
- true, if it is draggable
-
setDraggable
public void setDraggable(boolean draggable) Enables/disables dragging of the marker.- Parameters:
draggable- Set to true to enable dragging.
-
getIconUrl
Returns the url of the icon of the marker.- Returns:
- the url of the icon, default null.
-
setIconUrl
Sets the url of the icon of the marker, which is shown instead of the default pin.- Parameters:
iconUrl- The new url of the icon.
-
setIcon
Sets the icon image of the marker, which is shown instead of the default pin. AMarkerIconis shown with its url, scaled size and anchor; its size and origin are ignored, as sprites are not supported. ASymbolis shown with its SVG path.- Parameters:
icon- the icon image of the marker, or null to show the default pin
-
setLabel
Sets the label of the marker, which is shown in the default pin. Only the text and the color of the label are used: its font options and CSS class name are ignored. The label is not shown when the marker has an icon.- Parameters:
label- the new marker's label, or null to remove it
-
getPinBackground
Returns the background color of the default pin.- Returns:
- the background color, or null if not set
-
setPinBackground
Sets the background color of the default pin.- Parameters:
color- a CSS color
-
getPinBorderColor
Returns the border color of the default pin.- Returns:
- the border color, or null if not set
-
setPinBorderColor
Sets the border color of the default pin.- Parameters:
color- a CSS color
-
getPinGlyphColor
Returns the color of the default pin's glyph.- Returns:
- the glyph color, or null if not set
-
setPinGlyphColor
Sets the color of the default pin's glyph (the circle in its center).- Parameters:
color- a CSS color
-
getPinScale
public double getPinScale()Returns the scale of the default pin.- Returns:
- the scale, 1 if not set
-
setPinScale
public void setPinScale(double scale) Sets the scale of the default pin.- Parameters:
scale- the scale, e.g. 1.5 for a pin 50% larger than the default
-
onAttach
Checks that the map of this marker has a Map ID, which Advanced Markers require.- Overrides:
onAttachin classComponent- Throws:
IllegalStateException- if the map has no Map ID
-
getIdentifier
public long getIdentifier() -
setIdentifier
public void setIdentifier(long id) -
addDragEndEventListener
public Registration addDragEndEventListener(ComponentEventListener<GoogleMapAdvancedMarker.DragEndEvent> listener) Adds a DragEndEvent listener. The listener is called when a marker's drag ends.- Parameters:
listener- a drag end event listener- Returns:
- a handle that can be used for removing the listener
-
addClickListener
public Registration addClickListener(ComponentEventListener<GoogleMapAdvancedMarker.GoogleMapAdvancedMarkerClickEvent> listener) Adds a click event listener to a marker.- Parameters:
listener- a click event listener- Returns:
- a handle that can be used for removing the listener
-
addRightClickListener
public Registration addRightClickListener(ComponentEventListener<GoogleMapAdvancedMarker.GoogleMapAdvancedMarkerRightClickEvent> listener) Adds a right click event listener to a marker. On touch devices, a touch-and-hold on the marker fires it too.- Parameters:
listener- a right click event listener- Returns:
- a handle for the listener
-