Class: Cluster

ol/source/Cluster~Cluster


import Cluster from 'ol/source/Cluster';

Layer source to cluster vector data. Works out of the box with point geometries. For other geometry types, or if not all geometries should be considered for clustering, a custom geometryFunction can be defined.

new Cluster(options)

source/Cluster.js, line 46
Name Type Description
options

Cluster options.

Name Type Default Description
attributions module:ol/source/Source~AttributionLike

Attributions.

distance number 20

Minimum distance in pixels between clusters.

extent module:ol/extent~Extent

Extent.

geometryFunction function

Function that takes an module:ol/Feature as argument and returns an module:ol/geom/Point as cluster calculation point for the feature. When a feature should not be considered for clustering, the function should return null. The default, which works when the underyling source contains point features only, is

function(feature) {
  return feature.getGeometry();
}

See module:ol/geom/Polygon~Polygon#getInteriorPoint for a way to get a cluster calculation point for polygons.

projection module:ol/proj~ProjectionLike

Projection.

source module:ol/source/Vector~VectorSource

Source.

wrapX boolean true

Whether to wrap the world horizontally.

Methods

getDistance(){number}

source/Cluster.js, line 102

Get the distance in pixels between clusters.

Returns:
Distance.

getSource(){module:ol/source/Vector~VectorSource}

source/Cluster.js, line 111

Get a reference to the wrapped source.

Returns:
Source.

setDistance(distance)

source/Cluster.js, line 133

Set the distance in pixels between clusters.

Name Type Description
distance number

The distance in pixels.