cesium加载geoJson数据

2,778 阅读1分钟

添加GeoJsonDataSource:

var viewer = new Cesium.Viewer("cesiumContainer");
DataSource = Cesium.GeoJsonDataSource.load(GeoJSON, {
    stroke: Cesium.Color.RED,//相当于polygon的outlineColor
    strokeWidth: 5,//相当于polygon的outlineWidth
    clampToGround: true//是否贴地
  })
  viewer.dataSources.add(DataSource).then(function (dataSource) {
    let entities = dataSource.entities.values
	//修改entity样式
    for (let i = 0; i < entities.length; i++) {
      let entity = entities[i]
      entity.polygon.fill = false
      entity.polyline = {
        positions: entity.polygon.hierarchy._value.positions,
        width: 2,
        material: Cesium.Color.fromCssColorString('#ff0000')
      }
    }
  })

移除所有GeoJsonDataSource:

viewer.dataSources.removeAll(true)

进行定位:

viewer.zoomTo(DataSource)

官方api:

GeoJsonDataSource - Cesium Documentation

GeoJsonDataSource - Cesium Documentation

参考文章:www.cnblogs.com/lilyxusi/p/…