segmentEach
是一个 TURF 函数,用于将一个 Feature 对象或 FeatureCollection 对象的 LineString 类型的 Feature 进行线段切割。
segmentEach(FeatureCollection|Feature, callback)
参数:
FeatureCollection|Feature
: 必填,表示要切割的 Feature 对象或 FeatureCollection 对象。callback
: 必填,表示每个线段的回调函数,函数的参数为线段的 Feature 对象。返回值:
var line = turf.lineString([[126,45],[123,48],[120,45],[117,48]]);
turf.segmentEach(line, function(segment) {
console.log(segment);
});
输出结果:
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[126,45],[123,48]]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[123,48],[120,45]]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[120,45],[117,48]]
},
"properties": {}
}
Error: input must be a LineString Feature or Geometry
。Error: Missing callback
。