Classdesc

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.

Api

Hierarchy (view full)

Constructors

  • Parameters

    • options: Options

      Cluster options.

    Returns Cluster

Properties

disposed: boolean

The object has already been disposed.

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

Type declaration

Returns

Cluster calculation point.

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>
once: VectorSourceOnSignature<EventsKey>
projection: null | Projection
resolution: undefined | number
un: VectorSourceOnSignature<void>
viewRejector: ((arg0) => void)

Type declaration

    • (arg0): void
    • Parameters

      • arg0: Error

      Returns void

viewResolver: ((arg0) => void)

Type declaration

    • (arg0): void
    • Parameters

      • arg0: ViewOptions

      Returns 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/VectorVectorSource#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/CollectionCollection 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

    Api

  • Protected

    Add a feature without firing a change event.

    Parameters

    Returns void

  • Add a batch of features to the source.

    Parameters

    Returns void

    Api

  • 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

    Api

  • Remove all features from the source.

    Parameters

    • Optional fast: boolean

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

    Returns void

    Api

  • Protected

    Returns void

  • Protected

    Parameters

    • features: Feature<Geometry>[]

      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.

    Api

  • 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) => 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.

    Api

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

    Type Parameters

    • T_1

    Parameters

    • coordinate: Coordinate

      Coordinate.

    • callback: ((arg0) => 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) => 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.

    Api

  • 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

    • extent: Extent

      Extent.

    • callback: ((arg0) => T_3)

      Called with each feature whose geometry intersects the provided extent.

    Returns undefined | T_3

    The return value from the last call to the callback.

    Api

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

  • Get the attribution function for the source.

    Returns null | Attribution

    Attribution function.

    Api

  • Returns boolean

    Attributions are collapsible.

    Api

  • Get the closest feature to the provided coordinate.

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

    Parameters

    • coordinate: Coordinate

      Coordinate.

    • Optional filter: ((arg0) => 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.

    Api

  • Get the distance in pixels between clusters.

    Returns number

    Distance.

    Api

  • 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

    • Optional extent: Extent

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

    Returns Extent

    Extent.

    Api

  • Get a feature by its identifier (the value returned by feature.getId()). 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).

    Api

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

    Api

  • Get all features whose geometry intersects the provided coordinate.

    Parameters

    • coordinate: Coordinate

      Coordinate.

    Returns Feature<Geometry>[]

    Features.

    Api

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

    Api

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

    • Optional projection: Projection

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

    Returns Feature<Geometry>[]

    Features.

    Api

  • Get the format associated with this source.

    Returns undefined | FeatureFormat

    The feature format.

    Api

  • Returns boolean

    Use linear interpolation when resampling.

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

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

    Api

  • Returns boolean

    The source can have overlapping geometries.

  • Get the projection of the source.

    Returns null | Projection

    Projection.

    Api

  • Get an object of all property names and values.

    Returns {
        [x: string]: any;
    }

    Object.

    • [x: string]: any

    Api

  • Get an object of all property names and values.

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

    Object.

  • Parameters

    • Optional projection: 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.

    Api

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

    Returns State

    State.

    Api

  • Get the url associated with this source.

    Returns undefined | string | FeatureUrlFunction

    The url.

    Api

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

    Api

  • Parameters

    • Optional type: 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) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => 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

    Api

  • 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 remove all features at once, use the module:ol/source/Vector~VectorSource#clear #clear() method instead.

    Parameters

    Returns void

    Api

  • Remove an extent from the list of loaded extents.

    Parameters

    • extent: Extent

      Extent.

    Returns void

    Api

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • 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

    Api

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

    Parameters

    • distance: number

      The distance in pixels.

    Returns void

    Api

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

    Parameters

    • loader: FeatureLoader

      The loader to set.

    Returns void

    Api

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

    Parameters

    • minDistance: number

      The minimum distance in pixels.

    Returns void

    Api

  • 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
    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Replace the wrapped source.

    Parameters

    Returns void

    Api

  • 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

    Api

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional silent: boolean

      Unset without triggering an event.

    Returns void

    Api

  • Update the distances and refresh the source if necessary.

    Parameters

    • distance: number

      The new distance.

    • minDistance: number

      The new minimum distance.

    Returns void