Skip to content

KBE3D / KBCore / turf / clusterEach

函数: clusterEach()

clusterEach<G, P>(geojson: FeatureCollection<G, P>, property: string | number, callback: (cluster: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void): void

Function

clusterEach

类型参数

G

G extends Geometry

P

P extends GeoJsonProperties = GeoJsonProperties

参数

geojson

FeatureCollection<G, P>

GeoJSON Features

property

GeoJSON property key/value used to create clusters

string | number

callback

(cluster: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void

a method that takes (cluster, clusterValue, currentIndex)

返回

void

示例

ts
var geojson = turf.featureCollection([
    turf.point([0, 0]),
    turf.point([2, 4]),
    turf.point([3, 6]),
    turf.point([5, 1]),
    turf.point([4, 2])
]);

// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);

// Iterate over each cluster
turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue, currentIndex) {
    //= cluster
    //= clusterValue
    //= currentIndex
})

// Calculate the total number of clusters
var total = 0
turf.clusterEach(clustered, 'cluster', function () {
    total++;
});

// Create an Array of all the values retrieved from the 'cluster' property
var values = []
turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue) {
    values.push(clusterValue);
});

KBE3D @3.0.0 Copyright © 2024-present KBE3D