Cesium-primitive方式加载geojson线数据
时间: 2023-07-05 08:10:53 浏览: 432
可以通过以下步骤使用Cesium-primitive方式加载geojson线数据:
1. 使用Cesium的GeoJsonDataSource加载geojson数据:
```javascript
var dataSource = new Cesium.GeoJsonDataSource();
dataSource.load(url).then(function(){
var entities = dataSource.entities.values;
// your code here
});
```
2. 遍历entities,获取线数据的坐标信息:
```javascript
var coordinates = [];
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
if (entity.polyline) {
var positions = entity.polyline.positions.getValue();
coordinates.push(positions);
}
}
```
3. 使用Cesium的PolylineGeometry生成线的geometry:
```javascript
var geometries = [];
for (var i = 0; i < coordinates.length; i++) {
var geometry = new Cesium.PolylineGeometry({
positions: coordinates[i],
width: 5.0
});
geometries.push(geometry);
}
```
4. 使用Cesium的Primitive生成线的primitive:
```javascript
var primitives = [];
for (var i = 0; i < geometries.length; i++) {
var primitive = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: geometries[i]
}),
appearance: new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType('Color', {
color: Cesium.Color.RED
})
})
});
primitives.push(primitive);
}
viewer.scene.primitives.add(primitives);
```
以上代码可以将加载的geojson线数据以Cesium-primitive的方式显示在Cesium的场景中。
阅读全文