cesium 分屏对比 多窗同步

本文介绍了一种实现双视图同步的方法,通过监听左右视图的移动事件,并在移动时更新另一个视图的相机位置来保持同步。此外,还提供了一个用于获取当前相机位置及其旋转角度的函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不说废话, 代码

		// 视图同步
		this.leftViewer.eventManager.addCameraMoveListener(e => {
			if (this.isLeft() && this.synchronous) {
				const viewPoint = this.leftViewer.getViewPoint()
				this.rightViewer.baseViewer.camera.setView({
					destination: viewPoint.position,
					orientation: viewPoint.orientation
				})
			}
		})

		this.rightViewer.eventManager.addCameraMoveListener(e => {
			if (!this.isLeft() && this.synchronous) {
				const viewPoint = this.rightViewer.getViewPoint()
				this.leftViewer.baseViewer.camera.setView({
					destination: viewPoint.position,
					orientation: viewPoint.orientation
				})
			}
		})

获取相机位置

	/**
	 * 获取相机位置及旋转角度
	 * @return {{orientation: {heading: number, roll: number, pitch: number}, position: Cesium.Cartesian3}}
	 */
	getViewPoint() {
		return {
			position: this.baseViewer.camera.position.clone(),
			orientation: {
				heading: this.baseViewer.camera.heading,
				pitch: this.baseViewer.camera.pitch,
				roll: this.baseViewer.camera.roll
			}
		}
	}

监听move, 看鼠标在哪边

		// 记忆是哪一边在操作
		this.leftViewer.eventManager.addEventListener(EventConstant.MOUSE_MOVE, e => {
			this.currentOperation = ManyWindowViewer.LEFT_VIEWER
		})

		this.rightViewer.eventManager.addEventListener(EventConstant.MOUSE_MOVE, e => {
			this.currentOperation = ManyWindowViewer.RIGHT_VIEWER
		})


	/**
	 * 是否操纵左边
	 * @return {boolean}
	 */
	isLeft() {
		return this.currentOperation === ManyWindowViewer.LEFT_VIEWER
	}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值