Class MarkerFeature

  • 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:
    Serialized Form
    • Field Detail

      • 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
      • POINT_ICON

        public static final Icon POINT_ICON
        An alternative icon that displays a point
    • Constructor Detail

      • 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. The coordinates must be in the same projection as the View.getProjection() and Source.getProjection().
        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.The coordinates must be in the same projection as the View.getProjection() and Source.getProjection().

        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 Detail

      • 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