com.vaadin.flow.component.map.configuration.feature.

All Implemented Interfaces:

Serializable

public class MarkerFeature extends PointBasedFeature

A convenience class for displaying icons or images, such as markers, at a specific location on the map.

Technically this is a Feature that uses a Point geometry for representation, and a visual Style configured to use an Icon.

The class provides a default marker icon if no custom icon is provided.

See Also:

  • Field Details

    • PIN_ICON

      public static final Icon PIN_ICON

      The default icon used for markers, which is a pin pointing at a location on the map. This is a static icon and does not support customization.

    • POINT_ICON

      public static final Icon POINT_ICON

      An alternative icon that displays a point. This is a static icon and does not support customization.

  • Constructor Details

    • MarkerFeature

      public MarkerFeature()

      Creates a new marker feature displaying a default marker icon.

    • MarkerFeature

      public MarkerFeature(Coordinate coordinates)

      Creates a new marker feature located at the specified coordinates, displaying a default marker icon. Coordinates must be specified in the map's user projection, which by default is EPSG:4326, also referred to as GPS coordinates. If the user projection has been changed using Map.setUserProjection(String), then coordinates must be specified in that projection instead.

      Parameters:

      coordinates - the coordinates that locate the feature

    • MarkerFeature

      public MarkerFeature(Coordinate coordinates, Icon icon)

      Creates a new marker feature located at the specified coordinates, displaying the specified custom icon. Coordinates must be specified in the map's user projection, which by default is EPSG:4326, also referred to as GPS coordinates. If the user projection has been changed using Map.setUserProjection(String), then coordinates must be specified in that projection instead.

      NOTE: Icon instances should be reused between features in order to optimize memory-usage in the client-side component / browser. Creating a new instance of an icon for each feature is considered bad practice.

      Parameters:

      coordinates - the coordinates that locate the feature

      icon - the icon to display the feature

  • Method Details

    • getIcon

      public Icon getIcon()

      The icon used to visually display the marker feature. By default, this is a default marker icon provided by the component.

      CAUTION: Be careful when modifying the returned icon. Icon instances can, and should always be, reused between multiple markers. Modifying an icon can also affect other marker features. Instead of modifying the icon, consider preparing a set of distinct icons, and then using setIcon(Icon).

      Returns:

      the current icon

    • setIcon

      public void setIcon(Icon icon)

      Sets the icon used to visually display the marker feature.

      NOTE: Icon instances should be reused between features in order to optimize memory-usage in the client-side component / browser. Creating a new instance of an icon for each feature is considered bad practice.

      Parameters:

      icon - the new icon, not null