cesium-相机的使用

15 篇文章 0 订阅
12 篇文章 0 订阅

直接上代码

<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);
				}
			});
		}
	}
}
</script>
<style>
.el-breadcrumb__inner {
	color: #ffffff !important;
}
</style>

效果展示 

### 回答1: Cesium是一个开源的地理信息系统(GIS)库,它基于WebGL技术,通过浏览器实现高性能的三维地球和地理数据可视化。TDTJS是天地图的JavaScript API,提供了丰富的地图服务和功能。Cesium-tdtjs是将Cesium与TDTJS相结合,实现了将天地图与Cesium进行集成的功能。 使用Cesium-tdtjs,可以在Cesium的基础上使用天地图的地图服务,比如卫星图、地形图和矢量图等,通过调用TDTJS的API接口,可以实现对天地图的各种操作,如放大缩小、检索地点、绘制要素等。 Cesium-tdtjs还提供了丰富的可视化效果和交互功能。可以在三维地球上展示各种地理数据,如地形、建筑物、气象数据等,通过Cesium的强大渲染能力和TDTJS的地图显示,可以实现高度逼真的地理数据展示。同时,Cesium-tdtjs也提供了用户交互的功能,如鼠标控制、绘制路径、量测距离等,方便用户进行操作和分析。 总的来说,Cesium-tdtjs将Cesium和TDTJS结合起来,为开发者提供了一个强大的WebGIS开发平台。它可以帮助开发者快速构建高性能的三维地球和地理数据可视化应用,同时借助于天地图的丰富地图服务和功能,使应用具备更多的地理信息处理和展示能力。 ### 回答2: Cesium-tdtjs是一个兼容Cesium和天地图的JavaScript库。Cesium是一个用于创建3D地球和地理可视化应用程序的开源JavaScript库,而天地图是中国自主研发的全球数据服务平台。Cesium-tdtjs的目的是将这两个库结合起来,为开发者提供更好的创建地理可视化应用程序的工具。 Cesium-tdtjs可以在Cesium的基础上使用天地图的底图、注记和数据服务。开发者可以使用Cesium-tdtjs来加载天地图的地理数据,并在Cesium的三维空间中进行可视化展示。这个库提供了天地图的图层切换、地名搜索、鼠标交互等功能,使开发者可以更加方便地构建出功能强大的地理可视化应用程序。 通过Cesium-tdtjs,开发者可以利用Cesium的强大功能和天地图的全球数据服务,创建出令人印象深刻的地球模型和互动地理可视化应用。这个库还支持相机操作、模型加载、数据可视化等功能,使得开发者能够更加灵活地控制地球的展示效果。 总之,Cesium-tdtjs是一个结合了Cesium和天地图的JavaScript库,为开发者提供了创建地理可视化应用程序的工具。使用Cesium-tdtjs,开发者可以方便地加载天地图的数据,并在Cesium的三维空间中进行展示和交互。这个库为开发者提供了丰富的功能和灵活的控制,能够帮助开发者创建出精美而功能强大的地理可视化应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值