Cesium 加载面数据 点数据 label
Cesium 加载geojosn 数据
export const cesiumUtils = { viewer: null, dataSourceArr: [], addDataSource(geojsonData, config) { Cesium.GeoJsonDataSource.load(geojsonData, { stroke: Cesium.Color.HOTPINK, fill: Cesium.Color.PINK, strokeWidth: 3 }).then((dataSource) => { const tmpDataSource = new Cesium.CustomDataSource(Date.now().toString()); const entities = dataSource.entities.values; for (let index = 0; index < entities.length; index++) { const element = entities[index]; let polyPositions = element.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions; let polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; const pos = element.polygon.hierarchy.getValue().positions; let newEntity = new Cesium.Entity({ position:polyCenter, polygon: { hierarchy: element.polygon.hierarchy.getValue(), classificationType: Cesium.ClassificationType.BOTH, material: Cesium.Color.fromCssColorString(config.color).withAlpha(0.1), }, polyline: { positions: [...pos, pos[0]], clampToGround: true, material: Cesium.Color.fromCssColorString(config.color).withAlpha(1), width: 3 }, label:{ heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, text: config.name, font: "14px 宋体", distanceDisplayCondition: new Cesium.DistanceDisplayCondition( 0.0, 5000000.0 ), fillColor: Cesium.Color.WHITE, outlineColor: Cesium.Color.WHITE, showBorder:false, style: Cesium.LabelStyle.FILL_AND_OUTLINE, verticalOrigin: Cesium.VerticalOrigin.TOP, pixelOffset: new Cesium.Cartesian2(0, -50), disableDepthTestDistance: Number.POSITIVE_INFINITY, } }) tmpDataSource.entities.add(newEntity) } this.viewer.dataSources.add(tmpDataSource); this.dataSourceArr.push(tmpDataSource); }); }, clearDataSource() { for (let i = 0; i < this.dataSourceArr.length; i++) { const element = this.dataSourceArr[i]; this.viewer.dataSources.remove(element, true); } this.dataSourceArr = []; }, };
注意问题
如果geojson 数据有z值设置贴地会不起作用
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~