Cesium加载geoJson 格式的图斑方法:
// 首次进来判断是否存在图斑
if(this.geoSource) {
this.Global.viewer.dataSources.remove(this.Global.viewer.dataSources.getByName('图斑')[0])
}
let geoData = {
"type": "FeatureCollection", "features": [
{ "type": "Feature", "geometry": { "type": "Polygon", "coordinates": this.coordinates}, "properties": { "Id": 0 } }
]}
this.geoSource = Cesium.GeoJsonDataSource.load(geoData,{
stroke:Cesium.Color.YELLOW,
fill:Cesium.Color.YELLOW.withAlpha(0.5),
strokeWidth: 8,
clampToGround: true //是否贴地
})
this.geoSource.then((res) => {
this.Global.viewer.dataSources.add(res);
res.name = '图斑'
})
补充geoJson 可是作为示例
{type": "FeatureCollection", "features": [
{ "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [
[
[
114.14252662700005,
35.68635368300005
],
[
114.14277076700012,
35.685392380000053
],
[
114.14137077300006,
35.685319900000025
],
[
114.14035987900002,
35.685838699000044
],
[
114.14057350200005,
35.686693192000064
],
[
114.14252662700005,
35.68635368300005
]
]
]}, "properties": { "Id": 0 } }
]}