利用cesium模拟台风移动路径——以利奇马台风为例

2024-09-02 19:08

本文主要是介绍利用cesium模拟台风移动路径——以利奇马台风为例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

根据cesium官网示例(https://sandcastle.cesium.com/?src=Interpolation.html)改造为台风移动轨迹,台风数据从台风路径实时发布系统获取。模拟台风移动路径从台风发生地开始,动态移动至台风消亡地,之后从起点又开始循环移动。采用实体ellipse模拟台风的旋转,给椭圆背景material贴图,使用CallbackProperty设置rotation和stRotation逆时针转动。

<!DOCTYPE html>
<html lang="en">
<head><!-- Use correct character set. --><meta charset="utf-8"><!-- Tell IE to use the latest, best version. --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!-- Make the application on mobile take up the full browser screen and disable user scaling. --><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"><title>typhoon path</title><script src="../js/jquery-3.3.1.min.js"></script><script src="../js/require.min.js" data-main="../js/main"></script><style>@import url(../../build/Cesium/Widgets/widgets.css);@import url(../css/main.css);</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>var viewer;function onload(Cesium) {var url = 'http://{s}.tianditu.com/img_w/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer=img&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles&tk=fb0dd2b4158b2f9d4bec0aaaf9722801';viewer = new Cesium.Viewer('cesiumContainer', {imageryProvider: new Cesium.WebMapTileServiceImageryProvider({url: url,layer: 'img',style: 'default',format: 'tiles',tileMatrixSetID: 'w',credit: new Cesium.Credit('天地图全球影像服务'),subdomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],maximumLevel: 18}),baseLayerPicker: false,selectionIndicator: false,infoBox: false,animation: false, // 动画timeline: false, // 时间线navigationHelpButton: false, // 关闭帮助控件fullscreenButton: false, // 关闭全屏显示geocoder : false // 关闭搜索控件});viewer._cesiumWidget._creditContainer.style.display = "none"; // 去除水印viewer.scene.globe.enableLighting = false; // 关闭日照viewer.scene.globe.depthTestAgainstTerrain = true; // 开启地形探测(地形之下的不可见)viewer.scene.globe.showGroundAtmosphere = false; // 关闭大气层var imageryLayers = viewer.imageryLayers;var url2 = 'http://{s}.tianditu.com/cia_w/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer=cia&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles&tk=fb0dd2b4158b2f9d4bec0aaaf9722801';var labelImagery = new Cesium.WebMapTileServiceImageryProvider({url: url2,layer: 'cia',style: 'default',format: 'tiles',tileMatrixSetID: 'w',credit: new Cesium.Credit('天地图全球影像中文注记服务'),subdomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7']});imageryLayers.addImageryProvider(labelImagery);var scene = viewer.scene;var camera = viewer.scene.camera;// 初始位置var initViewLocation = {destination : Cesium.Cartesian3.fromDegrees(112.951085, 28.148327, 1000),duration : 0, // 旋转速度 数值越大越慢orientation : { // 朝北向下俯视heading : 5.857107801269642,pitch : -0.02842342271796139, // 相机间距roll : 0.0  // 相机滚动}}$.get("../data/json/typhoonData.json", null, function(data){console.log(data)var typhoonName = "利奇马";var result = [];if (data.length > 0) {for(let i = 0; i < data.length; i++){if(typhoonName===data[i].name){const points = data[i].pointsfor(let p=0; p<points.length; p++){const d = {'FID' : points[p].time,'serial': p+1,'fLongitude': points[p].lng,'fLatitude': points[p].lat}result.push(d);}}}typhoonFlytoPath(viewer, result, typhoonName)}})}function typhoonFlytoPath(viewer, positions, typhoonName){// 允许飞行动画viewer.clock.shouldAnimate = true;// 设定模拟时间的界限const start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16));const stop = Cesium.JulianDate.addSeconds(start, positions.length, new Cesium.JulianDate());viewer.clock.startTime = start.clone();viewer.clock.stopTime = stop.clone();viewer.clock.currentTime = start.clone();viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //末尾循环// 飞行速度,值越大速度越快,multiplier为0停止移动viewer.clock.multiplier = 3;// viewer.timeline.zoomTo(start, stop);// 计算飞行时间和位置const property = computeFlight(start, positions)var rotation = Cesium.Math.toRadians(30);function getRotationValue() {rotation += -0.03;return rotation;}const typhoonEntity = viewer.entities.add({name : '台风路径',availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({start : start,stop : stop})]),position : property,orientation : new Cesium.VelocityOrientationProperty(property), // 根据位置移动自动计算方向ellipse : {semiMinorAxis : 35000.0,semiMajorAxis : 35000.0,height: 0.0,fill: true,outlineColor: Cesium.Color.RED,outlineWidth: 5,outline : false,rotation: new Cesium.CallbackProperty(getRotationValue, false),stRotation: new Cesium.CallbackProperty(getRotationValue, false),material: new Cesium.ImageMaterialProperty({image: "../images/typhoon.gif",transparent: true})},point : {pixelSize : 10,color : Cesium.Color.TRANSPARENT,outlineColor : Cesium.Color.YELLOW,outlineWidth : 4},label : {text: typhoonName,font : '18px sans-serif',pixelOffset : new Cesium.Cartesian2(0.0, 50)},path : {resolution : 1,material : new Cesium.PolylineGlowMaterialProperty({glowPower : 0.9,color : Cesium.Color.YELLOW}),width : 3}})// 设置飞行视角viewer.trackedEntity = undefined;viewer.flyTo(typhoonEntity,{duration: 2,offset : {heading : Cesium.Math.toRadians(0.0),pitch : Cesium.Math.toRadians(-90),range : 1500000}})// 飞行视角追踪var preUpdateHandler = function(){if(typhoonEntity){const center = typhoonEntity.position.getValue(viewer.clock.currentTime);const hpr = new Cesium.HeadingPitchRange(Cesium.Math.toRadians(0.0), Cesium.Math.toRadians(-90), 1500000)if(center){viewer.camera.lookAt(center, hpr)}}}viewer.scene.preUpdate.addEventListener(preUpdateHandler)// viewer.zoomTo(typhoonEntity, new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90), 15000));// 设置插值函数为拉格朗日算法typhoonEntity.position.setInterpolationOptions({interpolationDegree : 3,interpolationAlgorithm : Cesium.LagrangePolynomialApproximation});}function computeFlight(start, positions){const property = new Cesium.SampledPositionProperty();for(let i=0; i<positions.length; i++){const time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());const position = Cesium.Cartesian3.fromDegrees(parseFloat(positions[i].fLongitude), parseFloat(positions[i].fLatitude), Cesium.Math.nextRandomNumber() * 500 + 1750);property.addSample(time, position);}return property;}
</script>
</body>

效果如下
在这里插入图片描述

这篇关于利用cesium模拟台风移动路径——以利奇马台风为例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1130817

相关文章

Linux修改pip和conda缓存路径的几种方法

《Linux修改pip和conda缓存路径的几种方法》在Python生态中,pip和conda是两种常见的软件包管理工具,它们在安装、更新和卸载软件包时都会使用缓存来提高效率,适当地修改它们的缓存路径... 目录一、pip 和 conda 的缓存机制1. pip 的缓存机制默认缓存路径2. conda 的缓

Qt把文件夹从A移动到B的实现示例

《Qt把文件夹从A移动到B的实现示例》本文主要介绍了Qt把文件夹从A移动到B的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录如何移动一个文件? 如何移动文件夹(包含里面的全部内容):如何删除文件夹:QT 文件复制,移动(

Windows系统下如何查找JDK的安装路径

《Windows系统下如何查找JDK的安装路径》:本文主要介绍Windows系统下如何查找JDK的安装路径,文中介绍了三种方法,分别是通过命令行检查、使用verbose选项查找jre目录、以及查看... 目录一、确认是否安装了JDK二、查找路径三、另外一种方式如果很久之前安装了JDK,或者在别人的电脑上,想

Python中Windows和macOS文件路径格式不一致的解决方法

《Python中Windows和macOS文件路径格式不一致的解决方法》在Python中,Windows和macOS的文件路径字符串格式不一致主要体现在路径分隔符上,这种差异可能导致跨平台代码在处理文... 目录方法 1:使用 os.path 模块方法 2:使用 pathlib 模块(推荐)方法 3:统一使

一文教你解决Python不支持中文路径的问题

《一文教你解决Python不支持中文路径的问题》Python是一种广泛使用的高级编程语言,然而在处理包含中文字符的文件路径时,Python有时会表现出一些不友好的行为,下面小编就来为大家介绍一下具体的... 目录问题背景解决方案1. 设置正确的文件编码2. 使用pathlib模块3. 转换路径为Unicod

CSS模拟 html 的 title 属性(鼠标悬浮显示提示文字效果)

《CSS模拟html的title属性(鼠标悬浮显示提示文字效果)》:本文主要介绍了如何使用CSS模拟HTML的title属性,通过鼠标悬浮显示提示文字效果,通过设置`.tipBox`和`.tipBox.tipContent`的样式,实现了提示内容的隐藏和显示,详细内容请阅读本文,希望能对你有所帮助... 效

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

Python重命名文件并移动到对应文件夹

《Python重命名文件并移动到对应文件夹》在日常的文件管理和处理过程中,我们可能会遇到需要将文件整理到不同文件夹中的需求,下面我们就来看看如何使用Python实现重命名文件并移动到对应文件夹吧... 目录检查并删除空文件夹1. 基本需求2. 实现代码解析3. 代码解释4. 代码执行结果5. 总结方法补充在

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

python获取当前文件和目录路径的方法详解

《python获取当前文件和目录路径的方法详解》:本文主要介绍Python中获取当前文件路径和目录的方法,包括使用__file__关键字、os.path.abspath、os.path.realp... 目录1、获取当前文件路径2、获取当前文件所在目录3、os.path.abspath和os.path.re