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.
我的数据有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);
});
分类:
前端开发 / Cesium
, 前端开发
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~