假设目前有geojson数据如下:
const smc={"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[119.66253898412081,30.368448359079963],[119.66243188888996,30.368413407509607],[119.66239524553978,30.368497829777414],[119.662502340849,30.36853278137794],[119.66253898412081,30.368448359079963]]]},"properties":{"OBJECTID":1,"Shape_Leng":42.0000000005,"Shape_Area":110.000000003,"FWMC":"混","FWCS":"3","YSDM":"141161","X":119.662467115,"Y":30.3684730944}}
]}
加载代码如下:
const smcPromise = Cesium.GeoJsonDataSource.load(smc,
{
clampToGround: true
}
);
smcPromise.then(dataSource => {
viewer.dataSources.add(dataSource);
const entities = dataSource.entities.values;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
entity.$name = "smc";
var color = (color = Cesium.Color.fromRandom({
alpha: 1.0
}));
entity.polygon.material = color;
entity.polygon.outline = false;
entity.polygon.extrudedHeight = 10.0;
}
viewer.flyTo(smcPromise);
});