描述
归约任何 GeoJSON 对象中的展平要素,类似于 Array.reduce()。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| geojson | FeatureCollection | Feature | GeometryObject | GeometryCollection | Feature<GeometryCollection> | 任何 GeoJSON 对象 |
| callback | flattenReduceCallback | 接收 (previousValue, currentFeature, featureIndex, multiFeatureIndex) 的方法 |
| initialValue? | Reducer | 作为回调函数第一个参数首次调用的值。 |
返回值
Reducer 归约结果值。
示例
javascript
var features = turf.featureCollection([
turf.point([26, 37], { foo: "bar" }),
turf.multiPoint(
[
[40, 30],
[36, 53],
],
{ hello: "world" },
),
]);
turf.flattenReduce(
features,
function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
//=previousValue
//=currentFeature
//=featureIndex
//=multiFeatureIndex
return currentFeature;
},
);安装
javascript
$ npm install @turf/meta
import { flattenReduce } from "@turf/meta";
const result = flattenReduce(...);javascript
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.flattenReduce(...);