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:
  • Constructor Details

    • GoogleMapAdvancedMarker

      public GoogleMapAdvancedMarker()
      Instantiates a new GoogleMapAdvancedMarker.
    • GoogleMapAdvancedMarker

      public GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable)
      Instantiates a new GoogleMapAdvancedMarker.
      Parameters:
      caption - The caption to use.
      position - The position of the marker
      draggable - Can marker be dragged?
    • GoogleMapAdvancedMarker

      public GoogleMapAdvancedMarker(String caption, LatLon position, boolean draggable, String iconUrl)
      Instantiates a new GoogleMapAdvancedMarker.
      Parameters:
      caption - The caption to use.
      position - The position of the marker
      draggable - 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 marker
      draggable - Can marker be dragged?
      icon - the icon image for the marker
  • Method Details

    • addInfoWindow

      public void addInfoWindow(String htmlContent)
      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

      public LatLon getPosition()
      Returns the position of the marker.
      Returns:
      The position of the marker.
    • setPosition

      public void setPosition(LatLon position)
      Sets the position of the marker.
      Parameters:
      position - The new position of the marker.
    • getCaption

      public String getCaption()
      Gets the caption of the marker.
      Returns:
      The caption of the marker.
    • setCaption

      public void setCaption(String caption)
      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

      public String getIconUrl()
      Returns the url of the icon of the marker.
      Returns:
      the url of the icon, default null.
    • setIconUrl

      public void setIconUrl(String iconUrl)
      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

      public void setIcon(GoogleMapIcon icon)
      Sets the icon image of the marker, which is shown instead of the default pin. A MarkerIcon is shown with its url, scaled size and anchor; its size and origin are ignored, as sprites are not supported. A Symbol is shown with its SVG path.
      Parameters:
      icon - the icon image of the marker, or null to show the default pin
    • setLabel

      public void setLabel(MarkerLabel label)
      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

      public String getPinBackground()
      Returns the background color of the default pin.
      Returns:
      the background color, or null if not set
    • setPinBackground

      public void setPinBackground(String color)
      Sets the background color of the default pin.
      Parameters:
      color - a CSS color
    • getPinBorderColor

      public String getPinBorderColor()
      Returns the border color of the default pin.
      Returns:
      the border color, or null if not set
    • setPinBorderColor

      public void setPinBorderColor(String color)
      Sets the border color of the default pin.
      Parameters:
      color - a CSS color
    • getPinGlyphColor

      public String getPinGlyphColor()
      Returns the color of the default pin's glyph.
      Returns:
      the glyph color, or null if not set
    • setPinGlyphColor

      public void setPinGlyphColor(String color)
      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

      protected void onAttach(AttachEvent attachEvent)
      Checks that the map of this marker has a Map ID, which Advanced Markers require.
      Overrides:
      onAttach in class Component
      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

      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

      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