Skip to content

概述

GeoJSON 是 Cesium 中最常用的矢量数据格式之一,常用于描述 点、线、面、属性、样式 等信息。
Cesium 通过 GeoJsonDataSource 对其进行解析并以 实体(Entity) 的形式呈现。

javascript
import tentea from './assets/tentea.json'
const dataSource = await Cesium.GeoJsonDataSource.load(tentea, {
  markerColor: Cesium.Color.RED,
  markerSize: 60,
  markerSymbol: 'A',
})
viewer.dataSources.add(dataSource)

viewer.zoomTo(dataSource.entities).then(() => {
  viewer.camera.zoomOut(10000)
})
javascript
dataSource.entities.values.forEach((entity) => {
  entity.label = new Cesium.LabelGraphics({
    text: entity.name,
    font: '16px sans-serif',
    fillColor: Cesium.Color.WHITE,
  })
  entity.billboard = new Cesium.BillboardGraphics({
    image: '/logo-small.svg',
    pixelOffset: new Cesium.Cartesian2(0, -40),
    scale: 0.5,
  })
})
/