MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / unionFeature

Function unionFeature

test/libs/workers/TurfWorkerForTest.js:258–288  ·  view source on GitHub ↗
(featureCollection, isFirst)

Source from the content-addressed store, hash-verified

256
257//feature合并
258function unionFeature(featureCollection, isFirst) {
259 var results = [];
260 var features = featureCollection.features;
261 var featureLength = features.length;
262 var oneceTotal = 2; //两两合并 直到最后剩一个多面对象为止(分网格 合并)
263 var total = Math.round(featureLength / oneceTotal);
264 //数组顺序打乱
265 if (!isFirst) this.random(features);
266 for (var i = 0; i <= total; i++) {
267 var start = i * oneceTotal;
268 var result = featureCollection.features[start];
269 for (var j = 1; j < oneceTotal; j++) {
270 var index = start + j;
271 if (featureCollection.features[index]) {
272 try {
273 result = this.union(result, featureCollection.features[index]);
274 } catch (e) {
275 results.push(featureCollection.features[index]);
276 }
277 }
278 }
279 if (result) results.push(result);
280 }
281
282 if (results && results.length > 1) {
283 //结果还是多个 继续合并
284 return this.unionFeature(turf.featureCollection(results), false);
285 } else {
286 return results[0];
287 }
288}
289
290//数组顺序打乱
291function random(arr) {

Callers

nothing calls this directly

Calls 3

roundMethod · 0.80
pushMethod · 0.80
randomMethod · 0.45

Tested by

no test coverage detected