clusterEach
描述
¥Description
clusterEach
参数
¥Parameters
名称 | 类型 | 描述 |
---|---|---|
geojson | FeatureCollection | GeoJSON 要素 |
property | string | number | 用于创建聚类的 GeoJSON 属性键/值 |
callback | clusterEachCallback | 一个接收 (cluster, clusterValue, currentIndex) 的方法 |
返回
¥Returns
void
示例
¥Examples
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);
});
安装
¥Installation
$ npm install @turf/clusters
import { clusterEach } from "@turf/clusters";
const result = clusterEach(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.clusterEach(...);