首页 > 其他分享 >cesium-flyto

cesium-flyto

时间:2024-04-19 16:27:47浏览次数:27  
标签:Cartesian3 viewer var Cesium camera cesium flyto Math

cesium-flyto

cesium-flyto

行走在路上 行走在路上 浮生浪迹笑明月,千愁散尽一剑轻。   1 人赞同了该文章

在到达指定位置,flyto的效果还是不错的

viewer.camera.flyTo({
		destination: Cesium.Cartesian3.fromDegrees(113.05265738392063, 22.626603971034342, 100.0), // 设置位置
		orientation: {
			heading: Cesium.Math.toRadians(20.0), // 方向
			pitch: Cesium.Math.toRadians(-0.0),// 倾斜角度
			roll: 0
		},
		duration: 5, // 设置飞行持续时间,默认会根据距离来计算
		complete: function () {
			// 到达位置后执行的回调函数
		},
		cancle: function () {
			// 如果取消飞行则会调用此函数
		},
		pitchAdjustHeight: -90, // 如果摄像机飞越高于该值,则调整俯仰俯仰的俯仰角度,并将地球保持在视口中。
		maximumHeight: 5000, // 相机最大飞行高度
		flyOverLongitude: 100, // 如果到达目的地有2种方式,设置具体值后会强制选择方向飞过这个经度(这个,很好用)
	});

各种效果如下:

<template>
	<div id="cesiumContainer" style="height: 100vh;"></div>
	<div id="toolbar" style="position: fixed;top:20px;left:220px;">
		<el-breadcrumb>
			<el-breadcrumb-item>场景设置实例</el-breadcrumb-item>
			<el-breadcrumb-item>相机</el-breadcrumb-item>
		</el-breadcrumb>
		<el-row class="mb-4" style="margin-top: 15px">
			<el-button type="primary" @click="flyInACity">飞行进城市</el-button>
			<el-button type="primary" @click="flyToSanDiego">飞行圣迭哥</el-button>
			<el-button type="primary" @click="flyToLocation">飞行到当前</el-button>
			<el-button type="primary" @click="flyToHeadingPitchRoll">飞行控制角度</el-button>
			<el-button type="primary" @click="flyToRectangle">飞行到正方形</el-button>
			<el-button type="primary" @click="viewRectangle">打开到正方形</el-button>
			<el-button type="primary" @click="setReferenceFrame">设置相机参考</el-button>
			<el-button type="primary" @click="setHeadingPitchRoll">设置相机角度</el-button>
			<el-button type="primary" @click="viewInICRF">设置地球自转</el-button>
			<el-button type="primary" @click="cameraEvents">相机移动事件</el-button>
		</el-row>
		<el-row class="mb-4" style="margin-top: 15px">
			<el-button type="primary" @click="cameraChanges">相机发生变化</el-button>
			<el-button type="primary" @click="flyOverLongitude">从洛杉矶经欧洲飞往东京</el-button>
			<el-button type="primary" @click="flyOverLongitudeWithPitch">夸张飞行时向下看</el-button>
		</el-row>
	</div>
	<div id="toolbar" style="position: fixed;top:150px;left:220px;color: #fff;">
		<div id="viewChanged">View Changed</div>
		<div id="cameraChanged">Camera Changed</div>
	</div>
</template>
<script>
import * as Cesium from "cesium";
import InitCesiumHide from "../js/InitCesiumHide.js";

export default {
	name: 'cesium24001',
	data() {
		return {
			viewer: undefined,
			scene: undefined
		}
	},
	mounted() {
		let initCesium = new InitCesiumHide('cesiumContainer')
		this.viewer = initCesium.initViewer({});
		//去除版权信息
		this.viewer._cesiumWidget._creditContainer.style.display = "none";
		this.scene = this.viewer.scene;
		let clock = this.scene.clock;

	},
	methods: {
		flyOverLongitudeWithPitch() {
			this.losAngelesToTokyo(true);
		},
		flyOverLongitude(adjustPitch) {
			this.losAngelesToTokyo();
		},
		losAngelesToTokyo(adjustPitch) {
			var camera = this.scene.camera;
			// 东京
			var tokyoOptions = {
				destination: Cesium.Cartesian3.fromDegrees(139.8148, 35.7142, 20000.0),
				orientation: {
					heading: Cesium.Math.toRadians(15.0),
					pitch: Cesium.Math.toRadians(-60),
					roll: 0.0
				},
				duration: 20,
				flyOverLongitude: Cesium.Math.toRadians(60.0)
			};
			// 洛杉矶
			var laOptions = {
				destination: Cesium.Cartesian3.fromDegrees(-117.729, 34.457, 10000.0),
				duration: 5,
				orientation: {
					heading: Cesium.Math.toRadians(-15.0),
					pitch: -Cesium.Math.PI_OVER_FOUR,
					roll: 0.0
				}
			};

			laOptions.complete = function () {
				setTimeout(function () {
					camera.flyTo(tokyoOptions);
				}, 1000);
			};

			if (adjustPitch) {
				tokyoOptions.pitchAdjustHeight = 1000;
				laOptions.pitchAdjustHeight = 1000;
			}

			camera.flyTo(laOptions);
		},
		cameraChanges() {
			var cameraChanged = document.getElementById('cameraChanged');
			var i = 0;
			//相机发生变化时触发
			let removeChanged = this.viewer.camera.changed.addEventListener(function (percentage) {
				++i;
				cameraChanged.innerText = 'Camera Changed: ' + i + ', ' + percentage.toFixed(6);
				cameraChanged.style.display = 'block';
			});
		},
		cameraEvents() {
			var viewChanged = document.getElementById('viewChanged');
			var camera = this.viewer.camera;
			camera.moveStart.addEventListener(function () {
				viewChanged.style.display = 'block';
			});
			camera.moveEnd.addEventListener(function () {
				viewChanged.style.display = 'none';
			});
		},
		icrf(scene, time) {
			if (this.scene.mode !== Cesium.SceneMode.SCENE3D) {
				return;
			}
			// 计算一个旋转矩阵,在给定时间将一个点或向量从国际天文参考坐标系  time计算旋转矩阵的时间
			var icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);
			if (Cesium.defined(icrfToFixed)) {
				var camera = this.viewer.camera;
				var offset = Cesium.Cartesian3.clone(camera.position);
				var transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed);
				camera.lookAtTransform(transform, offset);
			}
		},
		viewInICRF() {
			this.viewer.camera.flyHome(0);

			this.viewer.clock.multiplier = 3 * 60 * 60;

			// 实时更新执行
			this.scene.postUpdate.addEventListener(this.icrf);
			this.scene.globe.enableLighting = true;
		},
		setHeadingPitchRoll() {
			var camera = this.viewer.camera;
			camera.setView({
				destination: Cesium.Cartesian3.fromDegrees(-75.5847, 40.0397, 1000.0),
				orientation: {
					heading: -Cesium.Math.PI_OVER_TWO,
					pitch: -Cesium.Math.PI_OVER_FOUR,
					roll: 0.0
				}
			});
		},
		setReferenceFrame() {
			var center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
			var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);

			// View in east-north-up frame
			var camera = this.viewer.camera;
			camera.constrainedAxis = Cesium.Cartesian3.UNIT_Z;
			camera.lookAtTransform(transform, new Cesium.Cartesian3(-120000.0, -120000.0, 120000.0));

			// Show reference frame.  Not required.
			this.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
				modelMatrix: transform,
				length: 100000.0
			}));
		},
		viewRectangle() {
			var west = -77.0;
			var south = 38.0;
			var east = -72.0;
			var north = 42.0;

			var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);
			this.viewer.camera.setView({
				destination: rectangle
			});

			// Show the rectangle.  Not required; just for show.
			this.viewer.entities.add({
				rectangle: {
					coordinates: rectangle,
					fill: false,
					outline: true,
					outlineColor: Cesium.Color.WHITE
				}
			});
		},
		flyToRectangle() {
			var west = -90.0;
			var south = 38.0;
			var east = -87.0;
			var north = 40.0;
			var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);

			this.viewer.camera.flyTo({
				destination: rectangle
			});

			// Show the rectangle.  Not required; just for show.
			this.viewer.entities.add({
				rectangle: {
					coordinates: rectangle,
					fill: false,
					outline: true,
					outlineColor: Cesium.Color.WHITE
				}
			});
		},
		flyToHeadingPitchRoll() {
			this.viewer.camera.flyTo({
				destination: Cesium.Cartesian3.fromDegrees(-122.22, 46.12, 5000.0),
				orientation: {
					heading: Cesium.Math.toRadians(20.0),
					pitch: Cesium.Math.toRadians(-35.0),
					roll: 0.0
				}
			});
		},
		flyToLocation() {
			// Create callback for browser's geolocation
			function fly(position) {
				console.log(position)
				this.viewer.camera.flyTo({
					destination: Cesium.Cartesian3.fromDegrees(position.coords.longitude, position.coords.latitude, 1000.0)
				});
			}

			// Ask browser for location, and fly there.
			navigator.geolocation.getCurrentPosition(fly);
		},
		flyToSanDiego() {
			this.viewer.camera.flyTo({
				destination: Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
			});
		},
		flyInACity() {
			let camera = this.scene.camera;
			camera.flyTo({
				destination: Cesium.Cartesian3.fromDegrees(-73.98580932617188, 40.74843406689482, 363.34038727246224),
				complete: function () {
					setTimeout(function () {
						camera.flyTo({
							destination: Cesium.Cartesian3.fromDegrees(-73.98585975679403, 40.75759944127251, 186.50838555841779),
							orientation: {
								heading: Cesium.Math.toRadians(200.0),
								pitch: Cesium.Math.toRadians(-50.0)
							},
							easingFunction: Cesium.EasingFunction.LINEAR_NONE
						});
					}, 1000);
				}
			});
		}
	}
}

 

发布于 2024-03-06 09:44・IP 属地山东 三维 GIS CesiumJS

标签:Cartesian3,viewer,var,Cesium,camera,cesium,flyto,Math
From: https://www.cnblogs.com/sexintercourse/p/18146212

相关文章

  • GIS融合之路(六)-Cesium的雨雪风雷电效果
    终于来到系列第六篇了,也来到大家最喜闻乐见天气效果系列传送门:山海鲸可视化:GIS融合之路(一)技术选型CesiumJS/loaders.gl/iTowns?山海鲸可视化:GIS融合之路(二)CesiumJS和ThreeJS深度缓冲区整合山海鲸可视化:GIS融合之路(三)CesiumJS和ThreeJS相机同步山海鲸可视化:GIS融合之路(四)如何......
  • 基于canvas 或 svg绘制并生成base64 用于cesium billboard 渲染 替代label
    原因cesium的label样式不太好修改canvas生成functionlabelContent(showData){constmyConvas=document.createElement("canvas");constscale=1;//获取2d的上线文开始设置相关属性myConvas.width=150myConvas.height=65;letcont......
  • cesium 视角锁定 视角跟随 第三人称视角跟随
    描述:场景中有一个车辆,场景视角跟随车辆一、第三人称视角跟随原理:根据车辆位置和朝向,建立局部坐标系,并让相机看向这个位置letcenter=this.trackedEntity.position.getValue(viewer.clock.currentTime);letorientation=t......
  • cesium 地图旋转 整个场景旋转 开场动画
    设置camera旋转能实现整个场景的旋转,多用于开场动画开始旋转functiononTickCallback(){viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z,-0.02);}viewer.clock.onTick.addEventListener(onTickCallback);停止旋转view......
  • cesium 加载mapbox底图 黑色主题底图 84底图
    cesium提供MapboxStyleImageryProvider,加载mapbox的影像图层,底图是84坐标系。viewer.imageryLayers.addImageryProvider(newCesium.MapboxStyleImageryProvider({styleId:'dark-v11',accessToken:'mapbox的to......
  • cesium三维地图
    基础地图初始化constviewer=newViewer(mapRef.value,{animation:false,//时间动画控件timeline:false,//时间轴selectionIndicator:false,infoBox:false,baseLayerPicker:false,terrainProvider:createWorldTerrain()})颜色Cesium.Color.R......
  • Cesium 根据飞机航线计算飞机的Heading(偏航角)、Pitch(俯仰角)、Roll(翻滚角)
    需求设置飞机的一些坐标位置(经纬度高度),插值得到更多的坐标位置,然后飞机按照这些坐标集合形成的航线飞行,飞机的朝向、俯仰角以及飞机转弯时的翻转角根据坐标集合计算得出,而不需要手动设置heading、pitch、roll。坐标插值不知道为什么,可能是飞行速度变化太大,我用Cesium自带的插......
  • cesium内存泄漏问题优化
    在vue开发SPA实际项目中,不止涉及到使用cesium可视化的大屏一个界面,在切换页面或者关闭该功能、弹框后,cesium加载的模型,图层,实体等等信息会缓存到电脑的显存中,但是切回cesium界面的时候,又会重新进入页面的挂载周期,进行新的cesium实例的渲染,显存占用会越来越大,达到临界值后,页面会......
  • Cesium的相机(2)
    本节主讲相机的Heading\Pitch和Roll。Cesium的相机主要是通过局部坐标的偏航角、俯仰角和翻滚角确定相机姿态的。上一节我们知道,Cesium在获取这三个角度的时候,会将以地球球心为原点的地心地固坐标ECEF转为ENU东北天坐标系,ENU坐标系中,X轴指向正东,Y轴指向正北,Z轴指向天顶。所谓的......
  • 【Cesium源码系列】Cesium的相机(1)
    Cesium相机内部保存着相机的基本信息,主要有以下几个属性:_transform:对外只读,变换矩阵_invTransform:对外只读,变换矩阵的逆_actualTransform:对内,实际变换矩阵_actualInvTransform:对内,实际变换矩阵的逆position:对外,相机的位置_position:对内,相机的位置_positionWC:对外只读,相机......