cesium 使用 GeoJsonDataSource 加载 geoJson 数据,渲染 Polygon、polyline、Text 贴地配置
原文地址:https://juejin.cn/post/7029592051154944007
export function renderPolygon(geojson: any, zoomto: Boolean = true) { const viewer = window.viewer const dataSource = new Cesium.GeoJsonDataSource() // [cesium加载geoJson数据] https://juejin.cn/post/7029592051154944007 dataSource.load(geojson, { clampToGround: true }).then(() => { viewer.dataSources.add(dataSource) const entities = dataSource.entities.values for (let i = 0; i < entities.length; i++) { const entity = entities[i] // 修改 entity 样式 entity.polygon.material = Cesium.Color.fromCssColorString('#ff0000').withAlpha(0.5) // 添加 entity 的 polyline entity.polyline = { positions: entity.polygon.hierarchy._value.positions, width: 2, material: Cesium.Color.fromCssColorString('#ffff00') } // 获取一个 entity 的中心位置 const center = Cesium.BoundingSphere.fromPoints(entity.polygon.hierarchy._value.positions).center // 设置中心位置 entity.position = center // 添加 text entity.label = { text: entity.properties.name, color: Cesium.Color.fromCssColorString('#fff'), font: 'normal 32px MicroSoft YaHei', showBackground: true, scale: 0.5, horizontalOrigin: Cesium.HorizontalOrigin.LEFT_CLICK, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, disableDepthTestDistance: 10000.0 } } if (zoomto) { viewer.zoomTo(dataSource) } }) return dataSource }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
2022-04-18 docker-compose 部署 RSS 服务订阅、安装tiny-tiny-rss、RSSHub
2018-04-18 express 设置header解决跨域问题
2017-04-18 javascript 温故而知新 getBoundingClientRect
2017-04-18 IOS与安卓的远程调试
2016-04-18 css margin居中的问题