Class FeatureLayer
- All Implemented Interfaces:
Serializable
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:
-
Field Summary
Fields inherited from class com.vaadin.flow.component.map.configuration.AbstractConfigurationObject
propertyChangeSupport -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFeature(Feature feature) Adds a feature to the layer.intThe distance in pixels within which features should be clustered.intMinimum distance in pixels between clusters.TheStylethat defines how individual clusters should be rendered when clustering is enabled.The features managed by this layer.The source for this layer.getType()The unique type name of this class.booleanReturns whether clustering is enabled for this layer.voidRemoves all features from the layervoidremoveFeature(Feature feature) Removes a feature from the layervoidsetClusterDistance(int clusterDistance) Sets the distance in pixels within which features should be clustered.voidsetClusteringEnabled(boolean clusteringEnabled) Enables or disables clustering for this layer.voidsetClusterMinDistance(int clusterMinDistance) Sets the minimum distance in pixels between clusters.voidsetClusterStyle(Style clusterStyle) Sets the style for individual clusters.Methods inherited from class com.vaadin.flow.component.map.configuration.layer.VectorLayer
setSourceMethods inherited from class com.vaadin.flow.component.map.configuration.layer.Layer
getBackground, getMaxZoom, getMinZoom, getOpacity, getzIndex, isVisible, setBackground, setMaxZoom, setMinZoom, setOpacity, setVisible, setzIndexMethods inherited from class com.vaadin.flow.component.map.configuration.AbstractConfigurationObject
addChild, addNullableChild, addPropertyChangeListener, collectChanges, deepMarkAsDirty, getId, markAsDirty, notifyChange, notifyChange, removeChild, removePropertyChangeListener, setId, update
-
Constructor Details
-
FeatureLayer
public FeatureLayer()
-
-
Method Details
-
getType
Description copied from class:AbstractConfigurationObjectThe unique type name of this class. Used by the client-side synchronization mechanism to determine which OpenLayers class to synchronize into.- Overrides:
getTypein classVectorLayer
-
getSource
The source for this layer. For the feature layer this must always be aVectorSource- Overrides:
getSourcein classVectorLayer- Returns:
- the source of the layer
-
getFeatures
The features managed by this layer. This returns an immutable collection, which means it can not be modified. UseaddFeature(Feature)andremoveFeature(Feature)instead.- Returns:
- the features managed by the layer, immutable
-
addFeature
Adds a feature to the layer. When clustering is enabled, only features that extend fromPointBasedFeature, such asMarkerFeatureare supported.- Parameters:
feature- the feature to be added- Throws:
IllegalArgumentException- if clustering is enabled and the feature is not aPointBasedFeature
-
removeFeature
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 aClusterSourceinstead of a regularVectorSource.Only features that extend from
PointBasedFeature, such asMarkerFeature, 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
TheStylethat 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
Sets the style for individual clusters. This style is applied when clustering is enabled.- Parameters:
clusterStyle- the new cluster style, not null
-