Polygon与multiPolygon添加到Cesium
为了逻辑清晰,我把代码分成了如下几部分,亲测可用
1)首先区分是polygon还是multiPolygon,若为multpolygon,则首先把multpolygon拆分为多个polygon,然后循环,把polygon字符串上球
addMultiPolygon(polygonString) {
this.clearAll(); // 清空球上实体
// polygonString 可能以multiPolygon,或者polygon开头
// 若字符串以MulitPolyGon开头
if (polygonString.startsWith("MULTIPOLYGON")) {
let polyganList = this.multPolyganToList(polygonString); // 把multipolygon处理成多个polygon
polyganList.forEach((polygon)=>{
this.addPolygon(polygon);
})
this.viewer.zoomTo(this.viewer.entities);
}
else {
this.addPolygon(polygonString);
this.viewer.zoomTo(this.viewer.entities);
}
},
2)把mulitPolygon字符串处理成polygon字符串数组
// 把multiPolygon处理成多个polygon
multPolyganToList(data) {
let ployganStringList = [];
let tempData = data.slice(16,data.length-3)