flattenReduce
描述
¥Description
减少任何 GeoJSON 对象中的扁平要素,类似于 Array.reduce()。
¥Reduce flattened features in any GeoJSON object, similar to Array.reduce().
参数
¥Parameters
名称 | 类型 | 描述 |
---|---|---|
geojson | FeatureCollection | 特性 | GeometryObject | GeometryCollection | 特 性<GeometryCollection> | 任意 GeoJSON 对象 |
callback | flattenReduceCallback | 一个方法,该方法接受 (previousValue, currentFeature, featureIndex, multiFeatureIndex) |
initialValue? | Reducer | 用作回调函数首次调用的第一个参数的值。 |
返回
¥Returns
Reducer 简化后的值。
¥Reducer The value that results from the reduction.
示例
¥Examples
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;
},
);
安装
¥Installation
$ npm install @turf/meta
import { flattenReduce } from "@turf/meta";
const result = flattenReduce(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.flattenReduce(...);