Cesium 分屏对比效果实现

实现原理

初始化两个view:viewer0,viewer1

然后给两个viewer添加鼠标事件,当拖动viewer0的时候把相关参数传递给viewer1,

反之,将viewer1的地图事件传递给viewer0即可实现两个球体的分屏联动效果

实现效果

实现代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <script src="Cesium/Cesium.js"></script>
    <link rel="stylesheet"
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论
要在 Vue2 中实现 Cesium分屏效果,可以使用 Cesium 的 `Viewer` 对象,并将其放置在 Vue 组件的 `mounted` 钩子中。 具体方法如下: 1. 在 `mounted` 钩子中创建两个 `Viewer` 对象,分别代表左右两个屏幕。 2. 将两个 `Viewer` 对象的 `container` 属性设置为不同的 DOM 元素,以实现分屏效果。 3. 在 `destroyed` 钩子中销毁两个 `Viewer` 对象,释放内存。 示例代码如下: ```vue <template> <div class="cesium-container"> <div class="cesium-left"></div> <div class="cesium-right"></div> </div> </template> <script> import * as Cesium from "cesium"; export default { mounted() { // 创建左右两个 Viewer 对象 this.viewerLeft = new Cesium.Viewer("cesium-left"); this.viewerRight = new Cesium.Viewer("cesium-right"); // 设置左右两个 Viewer 对象的属性 this.viewerLeft.scene.globe.enableLighting = false; this.viewerRight.scene.globe.enableLighting = false; // 设置左右两个 Viewer 对象的 container 属性 this.viewerLeft.container = "cesium-left"; this.viewerRight.container = "cesium-right"; }, destroyed() { // 销毁左右两个 Viewer 对象 this.viewerLeft.destroy(); this.viewerRight.destroy(); }, }; </script> <style scoped> .cesium-container { display: flex; height: 100%; } .cesium-left { flex: 1; height: 100%; } .cesium-right { flex: 1; height: 100%; } </style> ``` 注意:在上述示例代码中,代码中的 `cesium-container` 、 `cesium-left` 、 `cesium-right` 分别代表 DOM 元素的 class 名称,需要在 CSS 样式表中定义相应的样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一碗老面i

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值