Cesium 绘制更新网格数据

news/2024/11/18 10:10:02/文章来源:https://www.cnblogs.com/xiaoqiyaozou/p/18551807

一、源码

import type { Viewer, Primitive, Material } from "cesium";const cesiumUtils = {viewer: <Viewer | null>null,rainPrimitive: <Primitive | null>null,interValIndex: 0,playIndex: 1,//播放材质索引isPlayIng: false,isPauseIng: false,setStatus: (options: any): void => { },imgArr: <Array<string>>[],m4DataArr: <Array<Array<string>>>[],gridmaterial: new Cesium.Material({fabric: {type: Cesium.Material.GridType,uniforms: {color: new Cesium.Color(0.0, 1.0, 1.0, 1.0),cellAlpha: 0.1,lineCount: new Cesium.Cartesian2(8.0, 8.0),lineThickness: new Cesium.Cartesian2(1.0, 1.0),lineOffset: new Cesium.Cartesian2(0.0, 0.0),},},}),gradientColors: ["#FF0000", // 红色"#FF3333","#FF6666","#FF9999","#FFCCCC","#CCFFFF", // 淡蓝色"#99CCFF","#6699FF","#3366FF","#0000FF", // 蓝色
    ],gradientColors2: ["rgba(0,0,255,0.1)","rgba(0,0,255,0.21)","rgba(0,0,255,0.3)","rgba(0,0,255,0.3)","rgba(0,255,255,0.9)","rgba(0,255,255,1)","rgba(0,255,255,1)","rgba(0,255,255,1)","rgba(0,255,255,0.1)","rgba(0,0,255,0.1)",],drawMesh(dataArr: Array<string>) {const baseInfo = dataArr[0].split(" ");const width = Number(baseInfo[16]) - 1;const height = Number(baseInfo[17]) - 1;let startLon = Number(baseInfo[12]);let endLon = Number(baseInfo[13]);let startLat = Number(baseInfo[14]);let endLat = Number(baseInfo[15]);let isNumber = 2;const canvas = document.createElement("canvas");canvas.width = width * isNumber;canvas.height = height * isNumber;let ctx = canvas.getContext("2d") as CanvasRenderingContext2D;this.imgArr = []for (let i = 0; i < width; i++) {for (let j = 0; j < height; j++) {const startX = i * isNumber;const startY = j * isNumber;let color = "rgba(128,128,128,0.3)"if (Math.random() < 0.95) {color = "rgba(128,128,128,0.3)"} else {color = "rgba(128,128,128,1)"}// this.gradientColors[Number((Math.sin(index)).toFixed(0))];ctx.fillStyle = color;ctx.fillRect(startX, startY, isNumber, isNumber);}}let img = canvas.toDataURL("image/png");this.imgArr.push(img)let instance = new Cesium.GeometryInstance({geometry: new Cesium.RectangleGeometry({rectangle: Cesium.Rectangle.fromDegrees(startLon,startLat,endLon,endLat),vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,}),});let rectangleAppearance = new Cesium.EllipsoidSurfaceAppearance({material: Cesium.Material.fromType("Image", {image: img,}),});let viewer = this.viewer as Viewerthis.rainPrimitive = viewer.scene.primitives.add(new Cesium.GroundPrimitive({geometryInstances: instance,appearance: rectangleAppearance,}));},setMateiral(dataArr: Array<string>) {const baseInfo = dataArr[0].split(" ");const width = Number(baseInfo[16]) - 1;const height = Number(baseInfo[17]) - 1;let isNumber = 2;const canvas = document.createElement("canvas");canvas.width = width * isNumber;canvas.height = height * isNumber;let ctx = canvas.getContext("2d") as CanvasRenderingContext2D;for (let i = 0; i < width; i++) {for (let j = 0; j < height; j++) {const startX = i * isNumber;const startY = j * isNumber;let color = "rgba(128,128,128,0.3)"if (Math.random() < 0.95) {color = "rgba(128,128,128,0.3)"} else {color = "rgba(128,128,128,1)"}// this.gradientColors[Number((Math.sin(index)).toFixed(0))];ctx.fillStyle = color;ctx.fillRect(startX, startY, isNumber, isNumber);}}let img = canvas.toDataURL("image/png");this.imgArr.push(img);},setPrimitive(dataArr: Array<string>, firstFrame: string) {const baseInfo = dataArr[0].split(" ");let startLon = Number(baseInfo[12]);let endLon = Number(baseInfo[13]);let startLat = Number(baseInfo[14]);let endLat = Number(baseInfo[15]);let instance = new Cesium.GeometryInstance({geometry: new Cesium.RectangleGeometry({rectangle: Cesium.Rectangle.fromDegrees(startLon,startLat,endLon,endLat),vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,}),});let rectangleAppearance = new Cesium.MaterialAppearance({material: new Cesium.Material({fabric: {type: 'Image',uniforms: {image: firstFrame}}}),})let viewer = this.viewer as Viewerthis.rainPrimitive = viewer.scene.primitives.add(new Cesium.GroundPrimitive({geometryInstances: instance,appearance: rectangleAppearance,}));},updateMaterial(material: any) {let primitive = this.rainPrimitive as Primitiveprimitive.appearance.material.uniforms['image'] = material},startPlay(setStatus: (options: any) => void) {let that = this;this.isPlayIng = trueconsole.log(that.imgArr.length);if (this.imgArr.length > 0 && this.rainPrimitive != null) {this.interValIndex = setInterval(() => {const material = that.imgArr[that.playIndex];that.updateMaterial(material)that.playIndex = that.playIndex + 1console.log(that.playIndex);let options = {step: that.playIndex / that.imgArr.length,isPlayIng: this.isPlayIng,isPauseIng: this.isPauseIng}setStatus(options)this.setStatus = setStatusif (that.playIndex == that.imgArr.length) {clearInterval(this.interValIndex)}}, 3000)}},pauseOrPlay() {if (this.isPlayIng &&this.playIndex!=this.imgArr.length) {if (!this.isPauseIng) {clearInterval(this.interValIndex)this.isPauseIng = true;let options = {step: this.playIndex / this.imgArr.length,isPlayIng: this.isPlayIng,isPauseIng: this.isPauseIng}this.setStatus(options)} else {this.isPauseIng = falsethis.startPlay(this.setStatus)}}},async setM4Data(urlArr: Array<string>) {this.m4DataArr = [];for (let i = 0; i < urlArr.length; i++) {const element = urlArr[i];let m4Data = await getM4Data(element);this.m4DataArr.push(m4Data)}},async initBaseData(urlArrr: Array<string>, viewer: Viewer) {this.viewer = viewerawait this.setM4Data(urlArrr)this.m4DataArr.forEach(x => {this.setMateiral(x)})this.setPrimitive(this.m4DataArr[0], this.imgArr[0])return true;},restorePlay() {clearInterval(this.interValIndex);this.playIndex = 1this.isPlayIng = false;this.isPauseIng = falseif (this.rainPrimitive != null) {this.viewer?.scene.primitives.remove(this.rainPrimitive)this.rainPrimitive = null}this.setStatus({isPauseIng: false,isPlayIng: false,step: 0})}
};//获取最大值
function geRenderData(dataArr: any) {let maxValue = 0;let renderData = []for (let i = 1; i < dataArr.length; i++) {const element = dataArr[i];const tmpArr = element.trim().split("      ")let rowArr = []for (let j = 0; j < tmpArr.length; j++) {const res = Number(tmpArr[j]);if (res > maxValue) {maxValue = res}rowArr.push(res)}renderData.push(rowArr)}return {maxValue,renderData}
}
//获取数据
async function getM4Data(url: string) {const fetchData = await fetch(url);const data = await fetchData.text();const dataArr = data.split("\n");return dataArr;
}export { getM4Data, cesiumUtils };

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/836038.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

京准电钟:GPS北斗卫星时间同步系统的应用

京准电钟:GPS北斗卫星时间同步系统的应用京准电钟:GPS北斗卫星时间同步系统的应用 京准电钟:GPS北斗卫星时间同步系统的应用 京准电子官微——ahjzsz 【摘要】本文介绍了电力系统目前所采用的时间同步方案技术的局限性以及存在的问题。在此基础上,提出了使用在标准以太网中…

react项目中使用threejs加载glb文件

安装threejs yarn add three首先创建 renderModel.js文件 import * as THREE from three import { GLTFLoader } from three/examples/jsm/loaders/GLTFLoader.js import { DRACOLoader } from three/examples/jsm/loaders/DRACOLoader.js import { OrbitControls } from three…

网络性能评估工具Iperf详解

摘自:https://www.cnblogs.com/machangwei-8/p/16922788.html 参考:https://www.51cto.com/article/454889.html发端:iperf -u -c <收端IP> -i 1 -b 800m -t 999 -l 1400 收端:iperf -u -s -i 1 目录一、网络性能评估工具Iperf1、Iperf能做什么二、Iperf的安装与使用…

提升开发效率的秘密:IT团队都在用哪些项目管理工具?

在当今的数字化时代,IT团队的角色已经从传统的技术支持转变为企业发展的战略推动力。随着企业业务的快速扩展,IT项目的复杂性也在增加。如何高效地管理项目、协调团队协作、以及快速响应变化,成为每个IT团队都必须面对的问题。而一个优秀的项目管理工具,不仅能帮助团队提升…

【PCIE716-0】基于PCIe总线架构的XC7Z100 FPGA高性能实时信号处理平台

板卡概述 PCIE716-0是一款基于PCIe总线架构的XC7Z100 FPGA高性能实时信号处理平台。该平台采用Xilinx的ZYNQ SOC系列产品XC7Z100作为主处理器。 该平台的PL端具有1个FMC(HPC)接口,1路PCIe x8主机接口,支持1路UART串口、支持1组64位DDR3 SDRAM大容量缓存、支持1路1000BASE-T…

给网站免费升级https协议

给网站免费升级HTTPS协议,可以通过申请并部署免费的SSL证书来实现。以下是一个详细的步骤指南:一、申请免费SSL证书 选择证书颁发机构: 可以选择像JoySSL这样的公益项目,它提供免费、自动化的SSL/TLS证书颁发服务,适用于各种规模的网站。 免费SSL证书申请入口 提交申请: …

在阿里云快速启动Appsmith搭建前端页面

什么是Appsmith Appsmith是一个开源的低代码开发平台,它使得开发者能够快速地构建内部工具、业务管理系统、CRM系统等。Appsmith通过提供一系列预建的UI组件(如表格、图表、表单等),以及对数据库、API调用的直接支持,简化了开发过程。开发者可以使用这些组件和服务来构建复…

【Anaconda3 2023.03软件下载与安装教程】

1、安装包 Anaconda3py 2023(64bit): 链接:https://pan.quark.cn/s/f77de1704504 提取码:z7k2 2、安装教程 1) 下载解压软件安装包,双击Setup.exe安装,弹窗安装对话框2) 点击Next3) 点击I Agree4) 默认,点击Next5) 选择安装目录,建议…

MoD:轻量化、高效、强大的新型卷积结构 | ACCV24

来源:晓飞的算法工程笔记 公众号,转载请注明出处论文: CNN Mixture-of-Depths论文地址:https://arxiv.org/abs/2409.17016创新点提出新的卷积轻量化结构MoD,在卷积块(Conv-Blocks)内通过动态选择特征图中的关键通道进行集中处理,提高效率。 CNN MoD保留了静态计算图,这…

【Android Studio 2022软件下载与安装教程】

1、安装包 Android Studio 2022: 链接:https://pan.quark.cn/s/9821141ab2c7 提取码:aTaw 2、安装教程 1) 解压下载安装包,双击Setup.exe安装,弹窗安装对话框2) 点击下一步3) 默认,点击下一步4) 选择安装目录,建议选择C盘之外,点击下一步5)…

当然不是草台班子-冲刺日志6

作业所属课程 软件工程2024作业要求 2024秋软工实践团队作业-第三次( Alpha冲刺)作业目标 alpha冲刺完成项目核心功能团队名称 当然不是草台班子团队成员学号 姓名102201427 侯丽珂102201426 郑嘉祺102201241 戴康怡102201218 肖晗涵112200328 谢李东292300304 陈鹭102201242…

教你对接电商拍图识款接口

在网上购物时候,不止可以通过名称搜索商品,也可以拍照上传图片搜索商品。比如某宝上拍个图片就能搜索到对应的商品。腾讯、阿里都提供了类似的图像搜索服务,这类服务原理都差不多:在一个具体的图库上,新增或者删除图片。 通过图片搜索相似的图片。本文对接的是腾讯云的图像…