featureEach
是一个Turf.js库中的函数,它能够对GeoJSON要素中的每个要素进行迭代,并将其作为参数传递给回调函数。该函数可以用于对要素进行处理、修改和过滤等操作。
turf.featureEach(features, callback)
features
:Feature
| FeatureCollection
类型的GeoJSON要素,包括各种几何类型的地理要素callback
:回调函数,该函数将被应用于GeoJSON要素的每个要素const points = turf.featureCollection([
turf.point([0, 0]),
turf.point([10, 10]),
turf.point([20, 20])
]);
turf.featureEach(points, (currentFeature, featureIndex) => {
console.log(`Feature ${featureIndex}:`, currentFeature);
});
输出结果:
Feature 0: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0]}}
Feature 1: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[10,10]}}
Feature 2: {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[20,20]}}