Class: Cluster

ol/source/Cluster~Cluster


import Cluster from 'ol/source/Cluster.js';

聚类矢量数据的图层数据源。与点几何图形开箱即用。对于其他几何类型,或如果不是所有几何图形都应被考虑用于聚类,可以定义自定义 geometry函数

如果在处置实例时未同时处置底层数据源,必须调用 setSource(null) 以从包装的数据源中移除监听器引用。

new Cluster(options)

Name Type Description
attributions AttributionLike | undefined

归属信息。

distance number (defaults to 20)

在此像素距离内的要素将被聚类在一起。

minDistance number (defaults to 0)

聚类之间的最小像素距离。将被限制在配置的距离内。默认不保证最小距离。此配置可用于避免图标重叠。作为权衡,聚类要素的位置将不再是其所有要素的中心。

geometry函数 Geometry函数<要素Type> | undefined

接受一个要素作为参数并返回一个 Point 作为该要素聚类计算点的函数。当某个要素不应参与聚类时,函数应返回 null。默认值(仅在底层数据源仅包含点要素时有效)为

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

参见 getInteriorPoint 了解获取多边形聚类计算点的方法。

createCluster function | undefined

接受聚类中心 Point 和此聚类中包含的要素数组的函数。必须返回一个用于渲染的要素。默认实现为:

function(point, features) {
  return new 要素({
    geometry: point,
    features: features
  });
}
source VectorSource<要素Type> (defaults to null)

数据源。

wrapX boolean (defaults to true)

是否水平环绕世界。

触发事件:

Extends

Methods

add要素(feature) inherited

向数据源添加单个要素。如果要一次添加一批要素,请改用 #add要素s()。如果具有相同 id 的要素已存在,则不会将该要素添加到数据源。此行为的原因是避免使用 bbox 或瓦片加载策略时要素重复。注意:如果要素使用 Collection,这也适用,意味着如果添加了重复 id 的要素到集合中,它将立即被移除。

Name Type Description
feature 要素Type

要添加的要素。

add要素s(features) inherited

向数据源添加一批要素。

Name Type Description
features Array.<要素Type>

要素s to add.

增加修订计数器并分发 'change' 事件。

从数据源移除所有要素。

Name Type Description
fast boolean | undefined

跳过分发 removefeature 事件。

dispatchEvent(event){boolean | undefined} inherited

分发事件并调用所有监听此类型事件的监听器。事件参数可以是一个字符串或一个 具有 type 属性的对象。

Name Type Description
event BaseEvent | string

事件对象。

返回值:
如果有人在事件对象上调用了 preventDefault 或任何监听器返回 false,则返回 false

forEach要素(callback){T | undefined} inherited

遍历数据源上的所有要素,对每个要素调用提供的回调函数。如果回调返回任何"真值",迭代将停止并返回相同的值。注意:此函数仅遍历具有已定义几何对象的要素。

Name Type Description
callback function

对数据源中的每个要素调用。返回真值以停止遍历。

返回值:
The return value from the last call to the callback.

forEachFeatureInExtent(extent, callback){T | undefined} inherited

遍历所有边界框与提供范围相交的要素(注意要素的几何对象可能不与范围相交),对每个要素调用回调函数。如果回调返回"真值",迭代将停止并返回相同的值。

如果您对几何图形与范围相交的要素感兴趣,请改用 #forEach要素IntersectingExtent() 方法。

useSpatialIndex 设置为 false 时,此方法将遍历所有要素,等同于 #forEach要素()

Name Type Description
extent Extent

范围。

callback function

对边界框与提供的范围相交的每个要素调用。

返回值:
The return value from the last call to the callback.

forEach要素IntersectingExtent(extent, callback){T | undefined} inherited

遍历所有几何对象与提供范围相交的要素,对每个要素调用回调函数。如果回调返回"真值",迭代将停止并返回相同的值。

如果您只想测试边界框相交,请改用 #forEachFeatureInExtent() 方法。

Name Type Description
extent Extent

范围。

callback function

对几何图形与提供的范围相交的每个要素调用。

返回值:
The return value from the last call to the callback.

获取一个值。

Name Type Description
key string

键名。

返回值:
值。

获取数据源的归属函数。

返回值:
Attribution function.

getAttributionsCollapsible(){boolean} inherited

返回值:
归属信息是否可折叠。

getClosestFeatureToCoordinate(coordinate, filter){要素Type | null} inherited

获取距离指定坐标最近的要素。

当数据源配置 useSpatialIndexfalse 且此数据源中的要素类型为 要素 时,此方法不可用。

Name Type Description
coordinate Coordinate

坐标。

filter function | undefined

要素过滤函数。过滤函数将接收一个参数 feature,并应返回布尔值。默认不进行过滤。

返回值:
Closest feature (or null if none found).

getDistance(){number}

获取聚类之间的像素距离。

返回值:
Distance.

getExtent(extent){Extent | null} inherited

获取当前数据源中要素的范围。

当数据源配置 useSpatialIndexfalse 时,此方法将返回 null

Name Type Description
extent Extent | undefined

目标范围。如果提供,将不创建新范围,而是覆盖该范围的坐标。

返回值:
范围。

get要素ById(id){要素ClassOrArrayOf渲染要素s<要素Type> | null} inherited

通过标识符获取要素(feature.getId() 返回的值)。当使用 渲染要素 时,get要素ById() 可以返回 渲染要素 数组。这允许处理 GeometryCollection 几何图形,其中格式读取器为每个 GeometryCollection 成员创建一个 渲染要素。注意索引将字符串和数字标识符视为相同。因此 source.get要素ById(2) 将返回 id 为 '2'2 的要素。

Name Type Description
id string | number

要素标识符。

返回值:
The feature (or null if not found).

getFeatures(){Array.<要素Type>} inherited

获取数据源上当前要素的随机顺序快照。返回的数组是副本,要素是对数据源中要素的引用。

返回值:
要素集合。

getFeaturesAtCoordinate(coordinate){Array.<要素Type>} inherited

获取几何图形与提供的坐标相交的所有要素。

Name Type Description
coordinate Coordinate

坐标。

返回值:
要素集合。

getFeaturesCollection(){Collection<要素Type> | null} inherited

获取与此数据源关联的要素集合。除非数据源配置时将 useSpatialIndex 设置为 false,或使用 Collection 作为 features,否则将为 null。

返回值:
The collection of features.

getFeaturesInExtent(extent, projection){Array.<要素Type>} inherited

获取边界框与提供的范围相交的所有要素。注意这将以随机顺序返回与给定范围相交的所有要素的数组(因此可能包含几何图形不与范围相交的要素)。

useSpatialIndex 设置为 false 时,此方法将返回所有要素。

Name Type Description
extent Extent

范围。

projection Projection | undefined

包含范围超出投影 x 轴边界并环绕世界的要素。

返回值:
要素集合。

getFormat(){要素Format<要素Type> | null} inherited

获取与此数据源关联的格式。

返回值:
} The feature format.

getKeys(){Array.<string>} inherited

获取对象属性名列表。

返回值:
属性名列表。

getMinDistance(){number}

配置的聚类最小距离。

返回值:
The minimum distance in pixels.

getProjection(){Projection | null} inherited

获取数据源的投影。

返回值:
投影。

getProperties(){NoInfer.<Properties>} inherited

获取包含所有属性名和值的对象。

返回值:
对象。

getRevision(){number} inherited

获取此对象的版本号。 每次对象被修改时,其版本号将递增。

返回值:
版本号。

getSource(){VectorSource<要素Type> | null}

获取被包装数据源的引用。

返回值:
数据源。

获取数据源的状态,可能的状态参见 State。

返回值:
状态。

getUrl(){string | featureUrlFunction | undefined} inherited

获取url associated with this source.

返回值:
The url.

has要素(feature){boolean} inherited

返回要素是否包含在数据源中。

Name Type Description
feature 要素Type

要素。

返回值:
Has feature.

on(type, listener){EventsKey | Array<EventsKey>} inherited

监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

once(type, listener){EventsKey | Array<EventsKey>} inherited

仅监听一次特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

remove要素(feature) inherited

从数据源移除单个要素。如果要批量移除要素,请改用 #remove要素s() 方法。

Name Type Description
feature 要素Type

要移除的要素。

remove要素s(features) inherited

从数据源批量移除要素。如果要一次移除所有要素,请改用 #clear() 方法。

Name Type Description
features Array.<要素Type>

要素s to remove.

removeLoadedExtent(extent) inherited

从已加载范围列表中移除一个范围。

Name Type Description
extent Extent

范围。

set(key, value, silent) inherited

设置一个值。

Name Type Description
key string

键名。

value *

值。

silent boolean | undefined

更新但不触发事件。

setAttributions(attributions) inherited

设置数据源的归属信息。

Name Type Description
attributions AttributionLike | undefined

归属信息。可以作为字符串、Array<string>、Attribution 或 undefined 传入。

setDistance(distance)

设置要素将被聚类在一起的距离。

Name Type Description
distance number

距离(像素)。

setLoader(loader) inherited

设置数据源的新加载器。下一个渲染周期将使用新的加载器。

Name Type Description
loader 要素Loader

要设置的加载器。

setMinDistance(minDistance)

设置聚类之间的最小距离。将被限制在配置的距离内。

Name Type Description
minDistance number

最小距离(像素)。

setProperties(values, silent) inherited

设置一组键值对。 注意,这会更改任何现有属性并添加新属性(不会移除任何现有属性)。

Name Type Description
values Partial.<NoInfer.<Properties>>

值。

silent boolean | undefined

更新但不触发事件。

setSource(source)

替换包装的数据源。

Name Type Description
source VectorSource<要素Type> | null

此实例的新数据源。

将数据源指向新的 URL。下一个渲染周期将使用新的 URL。

Name Type Description
url string | featureUrlFunction

Url.

un(type, listener) inherited

取消监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

unset(key, silent) inherited

取消设置一个属性。

Name Type Description
key string

键名。

silent boolean | undefined

取消设置但不触发事件。