{
const polygon = feature.geometry.coordinates;
const list = polygon[0];
let polygonList = [];
let newPolygon = [];
newPolygon.push(list[0]);
let compareValue = list[0];
let dynamicCompareValue = list[0];
for (let i=1; i<list.length; i++) {
const current = list[i];
const previous = list[i-1];
if (Math.abs(current[0] - dynamicCompareValue[0]) > 180) {
newPolygon.push([...compareValue]);
polygonList.push(newPolygon);
dynamicCompareValue = [...current];
let alterPoint = [...current];
let alterLng = alterPoint[0];
alterLng += alterLng - compareValue[0] > 180 ? -360 :
compareValue[0] - alterLng > 180 ? 360 : 0;
newPolygon = [[...compareValue], [alterLng, dynamicCompareValue[1]]];
} else {
let alterPoint = [...current];
let alterLng = alterPoint[0];
alterLng += alterLng - compareValue[0] > 180 ? -360 :
compareValue[0] - alterLng > 180 ? 360 : 0;
alterPoint[0] = alterLng;
newPolygon.push(alterPoint);
}
}
if (newPolygon.length > 2) {
polygonList.push(newPolygon);
}
let fc = {
"type":"FeatureCollection",
"features":[]
}
for (let i=0; i<polygonList.length; i++) {
let feature = {
"type":"Feature",
"properties":{},
"geometry":{
"type":"Polygon",
"coordinates":[polygonList[i]]
}
}
fc.features.push(feature);
}
console.log(fc);
return fc;
}