当前位置: 首页 > news >正文

前端~三维地图(cesium)地图遮罩蒙层

前提遮当通过geoJson行政区划边界以外的区域,主体突出行政区划范围,效果如下,相当去在一个比较大的黑色区域内挖出一个另外一个区域
在这里插入图片描述

具体相关API

在这里插入图片描述

代码实现逻辑

tips: 网上是通过geoJson 遍历获取所有行政区划的点位,但是这里已经加载了行政区划,无需再次加载,而且通过dataSource也可以遍历所有的点位,是一样的道理。

  1. 通过阿里云地理数据获取行政区划 geoJson 行政区划边界
  2. 通过cesium GeoJsonDataSource 加载行政区划边界,并设置边界样式
  3. 通过 GeoJsonDataSource 获取已经选中的行政区划边界点位
  4. 遮罩蒙层设置

第一种实现逻辑

// 加载行政区划边界
const geoBorderDataSource = new Cesium.GeoJsonDataSource()
const datasource = await geoBorderDataSource.load(`${BaseUrl}geoData/huinan_geo.json`, {stroke: Cesium.Color.fromCssColorString('#fb7014'),fill: Cesium.Color.fromAlpha(Cesium.Color.WHITE, 0),strokeWidth: 5.0})
await this.viewer.dataSources.add(datasource)
// 通过datasource 获取点位
const polygonPoints: Cesium.Cartesian3[] = []datasource.entities.values.forEach((entity) => {if (entity.polygon) {const hierarchy = entity.polygon.hierarchy.getValue(Cesium.JulianDate.now())if (hierarchy) {const positions = hierarchy.positionspolygonPoints.push(...positions)}}})
// 蒙层遮罩
this.viewer.entities.add({polygon: {hierarchy: new PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray([100, 0, 100, 89, 160, 89, 160, 0]),[new PolygonHierarchy(polygonPoints)]),// 这里是网上的写法,虽然也能实现,但是API升级之后写法有些许变化// hierarchy: {//   positions: Cesium.Cartesian3.fromDegreesArray([100, 0, 100, 89, 160, 89, 160, 0]), //外部区域//   holes: [//     {//       positions: polygonPoints//     }//   ]// },material: Cesium.Color.BLACK.withAlpha(0.2)}})

相关文章:

  • 【android bluetooth 协议分析 02】【bluetooth hal 层详解 8】【高通蓝牙hal-进程被杀之前日志收集流程】
  • AVL树介绍
  • LinkedBlockingQueue、ConcurrentLinkedQueue和ArrayBlockingQueue深度解析
  • LangChain【8】之工具包深度解析:从基础使用到高级实践
  • 2025年7月-12月【CISP】考试计划时间
  • Java并发编程实战 Day 13:Fork/Join框架与并行计算
  • 自然语言处理的发展
  • ABB输入/输出系统- S800输入/输出AI830A
  • MySQL 性能调优入门 - 慢查询分析与索引优化基础
  • 软考 系统架构设计师系列知识点之杂项集萃(84)
  • 【k8s】k8s集群搭建
  • 内容力重塑品牌增长:开源AI大模型驱动下的智能名片与S2B2C商城赋能抖音生态种草范式
  • halcon 透视矩阵
  • 加密货币钱包开发指南:多链资产管理与非托管安全范式
  • Linux 常用命令语法总结
  • 吃透 Golang 基础:使用 encoding/json 实现 Golang 数据结构与 JSON 对象的转换
  • go语言学习 第6章:错误处理
  • 《架构即未来》笔记
  • usbutils工具的使用帮助
  • Spring AI 入门:Java 开发者的生成式 AI 实践之路
  • 茶文化网站制作/网上找客户有什么渠道
  • 做外卖那些网站好/广州网站优化方式
  • 视频网站VIP卡怎么做赠品/seo快速排名系统
  • 重庆企业网站推广/公司网站怎么建立
  • 提供网站建设设计/seo是什么服务
  • 创建qq网站吗/百度云客服人工电话