Cesium 加载GeoJson数据,看不到实体效果

问题

我真的不知道为什么几乎每次要用Cesium加什么东西,不管是点线面还是图层,总是不顺利
要加载一个GeoJson数据,数据包含几个点,需要展示点的位置和标签名称。用以下代码,打印dataSource可以看到改动已经添加进去了,但是看不到(而且正常来说就算我不该也应该能看到默认样式的点?)

        Cesium.GeoJsonDataSource.load(pointJSON).then(dataSource => {
          let entities = dataSource.entities.values;
          entities.forEach(entity => {
            entity.label = {
              text: entity._properties.name._value
            };
            entity.point = {
                pixelSize: 5,
                color: Cesium.Color.WHITE,
            };
          });
          dataSource.name = layerName;
          viewer.dataSources.add(dataSource);
        });

分析过程

在控制台发现了以下警告信息:Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true.
image
我的数据有5个点,每个点加了一个label和一个point,所以这个警告可能是问题的线索

解决

加载选项要加clampToGround: true,标签和图形的配置也要加贴地设置。无语了……
但是point最后还是没调出来,换成了billboard

        Cesium.GeoJsonDataSource.load(pointJSON, { clampToGround: true }).then(dataSource => {
          let entities = dataSource.entities.values;
          entities.forEach(entity => {
            entity.label = {
              text: entity._properties.name._value,
              heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            };
            entity.point = {
                pixelSize: 5,
                color: Cesium.Color.WHITE,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            };
          });
          dataSource.name = layerName;
          viewer.dataSources.add(dataSource);
        });
posted @ 2023-02-04 19:24  宇宙野牛  阅读(4284)  评论(0编辑  收藏  举报