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.

If the instance is disposed without also disposing the underlying source setSource(null) has to be called to remove the listener reference from the wrapped source.

Type Parameters

  • FeatureType extends FeatureLike

Hierarchy (view full)

Constructors

Properties

disposed: boolean

The object has already been disposed.

distance: number
features: Feature<Geometry>[]
geometryFunction: ((arg0: FeatureType) => Point)

Type declaration

interpolationRatio: number
loading: boolean

This source is currently loading data. Sources that defer loading to the map's tile queue never set this to true.

minDistance: number
on: VectorSourceOnSignature<EventsKey, Feature<Geometry>>
once: VectorSourceOnSignature<EventsKey, Feature<Geometry>>
projection: null | Projection
resolution: undefined | number
un: VectorSourceOnSignature<void, Feature<Geometry>>
viewRejector: ((arg0: Error) => void)
viewResolver: ((arg0: ViewOptions) => void)

Methods

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Add a single feature to the source. If you want to add a batch of features at once, call module:ol/source/Vector~VectorSource#addFeatures #addFeatures() instead. A feature will not be added to the source if feature with the same id is already there. The reason for this behavior is to avoid feature duplication when using bbox or tile loading strategies. Note: this also applies if an module:ol/Collection~Collection is used for features, meaning that if a feature with a duplicate id is added in the collection, it will be removed from it right away.

    Parameters

    Returns void

  • Protected

    Add a feature without firing a change event.

    Parameters

    Returns void

  • Add a batch of features to the source.

    Parameters

    Returns void

  • Protected

    Add features without firing a change event.

    Parameters

    Returns void

  • Protected

    Apply any properties from another object without triggering events.

    Parameters

    • source: Object

      The source object.

    Returns void

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

  • Remove all features from the source.

    Parameters

    • Optionalfast: boolean

      Skip dispatching of module:ol/source/Vector.VectorSourceEvent#event:removefeature events.

    Returns void

  • Protected

    Returns void

  • Protected

    Parameters

    • features: FeatureType[]

      Features

    • extent: Extent

      The searched extent for these features.

    Returns Feature<Geometry>

    The cluster feature.

  • Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a type property.

    Parameters

    • event: string | BaseEvent

      Event object.

    Returns undefined | boolean

    false if anyone called preventDefault on the event object or if any of the listeners returned false.

  • Clean up.

    Returns void

  • Protected

    Extension point for disposable objects.

    Returns void

  • Iterate through all features on the source, calling the provided callback with each one. If the callback returns any "truthy" value, iteration will stop and the function will return the same value. Note: this function only iterate through the feature that have a defined geometry.

    Type Parameters

    • T

    Parameters

    • callback: ((arg0: Feature<Geometry>) => T)

      Called with each feature on the source. Return a truthy value to stop iteration.

    Returns undefined | T

    The return value from the last call to the callback.

  • Iterate through all features whose geometries contain the provided coordinate, calling the callback with each feature. If the callback returns a "truthy" value, iteration will stop and the function will return the same value.

    For module:ol/render/Feature~RenderFeature features, the callback will be called for all features.

    Type Parameters

    • T_1

    Parameters

    • coordinate: Coordinate

      Coordinate.

    • callback: ((arg0: Feature<Geometry>) => T_1)

      Called with each feature whose goemetry contains the provided coordinate.

    Returns undefined | T_1

    The return value from the last call to the callback.

  • Iterate through all features whose bounding box intersects the provided extent (note that the feature's geometry may not intersect the extent), calling the callback with each feature. If the callback returns a "truthy" value, iteration will stop and the function will return the same value.

    If you are interested in features whose geometry intersects an extent, call the module:ol/source/Vector~VectorSource#forEachFeatureIntersectingExtent #forEachFeatureIntersectingExtent() method instead.

    When useSpatialIndex is set to false, this method will loop through all features, equivalent to module:ol/source/Vector~VectorSource#forEachFeature #forEachFeature().

    Type Parameters

    • T_2

    Parameters

    • extent: Extent

      Extent.

    • callback: ((arg0: Feature<Geometry>) => T_2)

      Called with each feature whose bounding box intersects the provided extent.

    Returns undefined | T_2

    The return value from the last call to the callback.

  • Iterate through all features whose geometry intersects the provided extent, calling the callback with each feature. If the callback returns a "truthy" value, iteration will stop and the function will return the same value.

    If you only want to test for bounding box intersection, call the module:ol/source/Vector~VectorSource#forEachFeatureInExtent #forEachFeatureInExtent() method instead.

    Type Parameters

    • T_3

    Parameters

    Returns undefined | T_3

    The return value from the last call to the callback.

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

  • Get the attribution function for the source.

    Returns null | Attribution

    Attribution function.

  • Returns boolean

    Attributions are collapsible.

  • Get the closest feature to the provided coordinate.

    This method is not available when the source is configured with useSpatialIndex set to false and the features in this source are of type module:ol/Feature~Feature.

    Parameters

    • coordinate: Coordinate

      Coordinate.

    • Optionalfilter: ((arg0: Feature<Geometry>) => boolean)

      Feature filter function. The filter function will receive one argument, the module:ol/Feature~Feature feature and it should return a boolean value. By default, no filtering is made.

    Returns Feature<Geometry>

    Closest feature.

  • Get the distance in pixels between clusters.

    Returns number

    Distance.

  • Get the extent of the features currently in the source.

    This method is not available when the source is configured with useSpatialIndex set to false.

    Parameters

    • Optionalextent: Extent

      Destination extent. If provided, no new extent will be created. Instead, that extent's coordinates will be overwritten.

    Returns Extent

    Extent.

  • Get a feature by its identifier (the value returned by feature.getId()). When RenderFeatures are used, getFeatureById() can return an array of RenderFeatures. This allows for handling of GeometryCollection geometries, where format readers create one RenderFeature per GeometryCollection member. Note that the index treats string and numeric identifiers as the same. So source.getFeatureById(2) will return a feature with id '2' or 2.

    Parameters

    • id: string | number

      Feature identifier.

    Returns null | Feature<Geometry>

    The feature (or null if not found).

  • Get a feature by its internal unique identifier (using getUid).

    Parameters

    • uid: string

      Feature identifier.

    Returns null | Feature<Geometry>

    The feature (or null if not found).

  • Get a snapshot of the features currently on the source in random order. The returned array is a copy, the features are references to the features in the source.

    Returns Feature<Geometry>[]

    Features.

  • Get all features whose geometry intersects the provided coordinate.

    Parameters

    • coordinate: Coordinate

      Coordinate.

    Returns Feature<Geometry>[]

    Features.

  • Get the features collection associated with this source. Will be null unless the source was configured with useSpatialIndex set to false, or with an module:ol/Collection~Collection as features.

    Returns null | Collection<Feature<Geometry>>

    The collection of features.

  • Get all features whose bounding box intersects the provided extent. Note that this returns an array of all features intersecting the given extent in random order (so it may include features whose geometries do not intersect the extent).

    When useSpatialIndex is set to false, this method will return all features.

    Parameters

    • extent: Extent

      Extent.

    • Optionalprojection: Projection

      Include features where extent exceeds the x-axis bounds of projection and wraps around the world.

    Returns Feature<Geometry>[]

    Features.

  • Get the format associated with this source.

    Returns undefined | FeatureFormat<typeof Feature>

    The feature format.

  • Returns boolean

    Use linear interpolation when resampling.

  • Get a list of object property names.

    Returns string[]

    List of property names.

  • Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.

    Parameters

    • type: string

      Type.

    Returns undefined | Listener[]

    Listeners.

  • The configured minimum distance between clusters.

    Returns number

    The minimum distance in pixels.

  • Returns boolean

    The source can have overlapping geometries.

  • Get the projection of the source.

    Returns null | Projection

    Projection.

  • Get an object of all property names and values.

    Returns {
        [x: string]: any;
    }

    Object.

    • [x: string]: any
  • Get an object of all property names and values.

    Returns null | {
        [x: string]: any;
    }

    Object.

  • Parameters

    • Optionalprojection: Projection

      Projection.

    Returns null | number[]

    Resolutions.

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

  • Get the state of the source, see import("./Source.js").State for possible states.

    Returns State

    State.

  • Get the url associated with this source.

    Returns undefined | string | FeatureUrlFunction

    The url.

  • Returns Promise<ViewOptions>

    A promise for view-related properties.

  • Returns undefined | boolean

    Wrap X.

  • Returns true if the feature is contained within the source.

    Parameters

    Returns boolean

    Has feature.

  • Parameters

    • Optionaltype: string

      Type. If not provided, true will be returned if this event target has any listeners.

    Returns boolean

    Has listeners.

  • Returns boolean

    The object has properties.

  • Returns boolean

    Is empty.

  • Parameters

    • extent: Extent

      Extent.

    • resolution: number

      Resolution.

    • projection: Projection

      Projection.

    Returns void

  • Parameters

    • key: string

      Key name.

    • oldValue: any

      Old value.

    Returns void

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Refreshes the source. The source will be cleared, and data from the server will be reloaded.

    Returns void

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Remove a single feature from the source. If you want to batch remove features, use the module:ol/source/Vector~VectorSource#removeFeatures #removeFeatures() method instead.

    Parameters

    Returns void

  • Batch remove features from the source. If you want to remove all features at once, use the module:ol/source/Vector~VectorSource#clear #clear() method instead.

    Parameters

    Returns void

  • Remove an extent from the list of loaded extents.

    Parameters

    • extent: Extent

      Extent.

    Returns void

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optionalsilent: boolean

      Update without triggering an event.

    Returns void

  • Set the attributions of the source.

    Parameters

    • attributions: undefined | AttributionLike

      Attributions. Can be passed as string, Array<string>, module:ol/source/Source~Attribution, or undefined.

    Returns void

  • Set the distance within which features will be clusterd together.

    Parameters

    • distance: number

      The distance in pixels.

    Returns void

  • Set the new loader of the source. The next render cycle will use the new loader.

    Parameters

    Returns void

  • Set the minimum distance between clusters. Will be capped at the configured distance.

    Parameters

    • minDistance: number

      The minimum distance in pixels.

    Returns void

  • Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

    Parameters

    • values: {
          [x: string]: any;
      }

      Values.

      • [x: string]: any
    • Optionalsilent: boolean

      Update without triggering an event.

    Returns void

  • Replace the wrapped source.

    Parameters

    Returns void

  • Set the state of the source.

    Parameters

    • state: State

      State.

    Returns void

  • Points the source to a new url. The next render cycle will use the new url.

    Parameters

    • url: string | FeatureUrlFunction

      Url.

    Returns void

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0: Event | BaseEvent) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optionalsilent: boolean

      Unset without triggering an event.

    Returns void

  • Update the distances and refresh the source if necessary.

    Parameters

    • distance: number

      The new distance.

    • minDistance: number

      The new minimum distance.

    Returns void