代码:
const viewer = new Cesium.Viewer("cesiumContainer");
// 定义GeoJSON数据
var geojsonData = {
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
},
{ "type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
},
"properties": {
"prop0": "value0",
"prop1": {"this": "that"}
}
}
]
};
// 加载GeoJSON数据
var dataSource = Cesium.GeoJsonDataSource.load(geojsonData, {
stroke: Cesium.Color.HOTPINK,
fill: Cesium.Color.PINK.withAlpha(0.5),
strokeWidth: 3
});
// 将加载的数据添加到场景中
viewer.dataSources.add(dataSource).then(function(dataSource) {
// 将相机聚焦在加载的数据范围内
viewer.zoomTo(dataSource);
});