All Implemented Interfaces:
Serializable

public class FeatureLayer extends VectorLayer
Layer that allows to conveniently display a number of geographic features. A Feature can be anything that should be displayed on top of a map, such as points of interest, vehicles or people.

The layer is a high-level abstraction built on top of VectorLayer, and uses a VectorSource by default.

Clustering of point-based features can be enabled using setClusteringEnabled(boolean). When clustering is enabled, only features that extend from PointBasedFeature, such as MarkerFeature can be added to the layer. Enabling clustering will switch the layer's source to a ClusterSource.

See Also:
  • Constructor Details

    • FeatureLayer

      public FeatureLayer()
  • Method Details

    • getType

      public String getType()
      Description copied from class: AbstractConfigurationObject
      The unique type name of this class. Used by the client-side synchronization mechanism to determine which OpenLayers class to synchronize into.
      Overrides:
      getType in class VectorLayer
    • getSource

      public VectorSource getSource()
      The source for this layer. For the feature layer this must always be a VectorSource
      Overrides:
      getSource in class VectorLayer
      Returns:
      the source of the layer
    • getFeatures

      public List<Feature> getFeatures()
      The features managed by this layer. This returns an immutable collection, which means it can not be modified. Use addFeature(Feature) and removeFeature(Feature) instead.
      Returns:
      the features managed by the layer, immutable
    • addFeature

      public void addFeature(Feature feature)
      Adds a feature to the layer. When clustering is enabled, only features that extend from PointBasedFeature, such as MarkerFeature are supported.
      Parameters:
      feature - the feature to be added
      Throws:
      IllegalArgumentException - if clustering is enabled and the feature is not a PointBasedFeature
    • removeFeature

      public void removeFeature(Feature feature)
      Removes a feature from the layer
      Parameters:
      feature - the feature to be removed
    • removeAllFeatures

      public void removeAllFeatures()
      Removes all features from the layer
    • isClusteringEnabled

      public boolean isClusteringEnabled()
      Returns whether clustering is enabled for this layer.
      Returns:
      true if clustering is enabled, false otherwise
    • setClusteringEnabled

      public void setClusteringEnabled(boolean clusteringEnabled)
      Enables or disables clustering for this layer. When clustering is enabled, the layer will use a ClusterSource instead of a regular VectorSource.

      Only features that extend from PointBasedFeature, such as MarkerFeature, are supported for clustering. When enabling clustering, any existing features that are not point based will be removed from the layer's source.

      Parameters:
      clusteringEnabled - true to enable clustering, false to disable
    • getClusterDistance

      public int getClusterDistance()
      The distance in pixels within which features should be clustered. Default is 50 pixels.

      Only applies when clustering is enabled.

      Returns:
      the distance in pixels within which features should be clustered
    • setClusterDistance

      public void setClusterDistance(int clusterDistance)
      Sets the distance in pixels within which features should be clustered.

      Only applies when clustering is enabled.

      Parameters:
      clusterDistance - the distance in pixels within which features should be clustered
    • getClusterMinDistance

      public int getClusterMinDistance()
      Minimum distance in pixels between clusters. Will be capped at the configured distance. By default, no minimum distance is guaranteed. This config can be used to avoid overlapping icons. As a trade-off, the cluster feature's position will no longer be the center of all its features. Default is 50 pixels.

      Only applies when clustering is enabled.

      Returns:
      the minimum distance between clusters in pixels
    • setClusterMinDistance

      public void setClusterMinDistance(int clusterMinDistance)
      Sets the minimum distance in pixels between clusters.

      Only applies when clustering is enabled.

      Parameters:
      clusterMinDistance - the minimum distance between clusters in pixels
    • getClusterStyle

      public Style getClusterStyle()
      The Style that defines how individual clusters should be rendered when clustering is enabled. By default, uses an image of a circle with text displaying the number of features in the cluster. Non-clustered features are rendered using their own style.
      Returns:
      the current cluster style
    • setClusterStyle

      public void setClusterStyle(Style clusterStyle)
      Sets the style for individual clusters. This style is applied when clustering is enabled.
      Parameters:
      clusterStyle - the new cluster style, not null