src/utils/area.js
@@ -4,7 +4,7 @@
export function loadAreaPolygon(url, isPolluted = false) {
   let color = new Cesium.Color(1.0, 0.0, 0.0, 0.1)
   if (isPolluted) {
      color = Cesium.Color.SKYBLUE
      color = Cesium.Color.GREEN
   }
   // 使用 GeoJsonDataSource 加载 GeoJSON 数据
   const dataSourcePromise = Cesium.GeoJsonDataSource.load(url, {
@@ -14,7 +14,7 @@
   // 获取 GeoJSON 中的第一个 Polygon feature
   return dataSourcePromise.then(function (dataSource) {
      viewer.dataSources.add(dataSource)
      console.log("dataSource", dataSource)
      // console.log("dataSource", dataSource)
      // 获取 GeoJSON 中的第一个 Polygon feature
      areaDataSource.push(dataSource)
@@ -25,7 +25,7 @@
      // return areaPrimitive
      const polygonEntity = dataSource.entities.values
      console.log("polygonEntity", polygonEntity)
      // console.log("polygonEntity", polygonEntity)
      const distanceDisplayCondition = new Cesium.DistanceDisplayCondition(1000, 50000000)
      polygonEntity.forEach(entity => {
         // console.log("entity", entity)
@@ -140,17 +140,29 @@
}
export function clearAreaPolygon() {
   if (Array.isArray(areaPrimitives)) {
      areaPrimitives.forEach(item => {
         viewer.scene.primitives.remove(item)
      })
      areaPrimitives = []
   }
   if (Array.isArray(areaDataSource)) {
      areaDataSource.forEach(dataSource => {
         dataSource.show = false
      })
   }
    // 1. 清除通过 viewer.entities 添加的实体
    if (Array.isArray(areaDataSource)) {
        areaDataSource.forEach(dataSource => {
            // 移除数据源中的所有实体
            dataSource.entities.values.forEach(entity => {
                viewer.entities.remove(entity);
            });
            // 移除数据源本身
            viewer.dataSources.remove(dataSource);
        });
        areaDataSource = [];
    }
    // 2. 清除通过 viewer.scene.primitives 添加的图元
    if (Array.isArray(areaPrimitives)) {
        areaPrimitives.forEach(primitive => {
            viewer.scene.primitives.remove(primitive);
        });
        areaPrimitives = [];
    }
    // 3. 强制场景重绘
    viewer.scene.requestRender();
}
export function initAreaLine() {
@@ -211,7 +223,7 @@
      dataSource.name = name
      // viewer.dataSources.add(dataSource)
      // 获取 GeoJSON 中的第一个 Polygon feature
      console.log("dataSource", dataSource)
      // console.log("dataSource", dataSource)
      const polygonEntity = dataSource.entities.values
      areaLineEntities.push(...polygonEntity)