Cesium中实现鹰眼图

鹰眼图实现

提示:这里可以添加本文要记录的大概内容:

实现右下角鹰眼地图的实现,并且与主地图同步。

一、实现效果

在这里插入图片描述

二、实现代码

1.创建Overview.js文件

完整代码如下:

import AmapMercatorTilingScheme from "../correct/AmapMercatorTilingScheme.js";
import * as Cesium from 'cesium';

class HawkEyeMap {
    constructor(viewer) {
        this._viewer = viewer;
        this._hawkEyeMap = null;
        this._init(); // 在构造函数中直接调用 _init() 方法
    }

    // 初始化函数
    _init() {
        this._hawkEyeMap = new Cesium.Viewer('hawkEyeMap', {
            geocoder: false,
            homeButton: false,
            sceneModePicker: false,
            baseLayerPicker: false,
            navigationHelpButton: false,
            animation: false,
            timeline: false,
            fullscreenButton: false,
        });
        this._hawkEyeMap.cesiumWidget.creditContainer.style.display = 'none';
        this._hawkEyeMap.scene.backgroundColor = Cesium.Color.TRANSPARENT;
        this._hawkEyeMap.imageryLayers.removeAll();
        // 鹰眼图中添加高德路网中文注记图
        this._hawkEyeMap.imageryLayers.addImageryProvider(
            new Cesium.UrlTemplateImageryProvider({
                url: "http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
                minimumLevel: 3,
                maximumLevel: 18,
                tilingScheme: new AmapMercatorTilingScheme(),
            })
        );
        // 引起事件监听的相机变化幅度
        this._viewer.camera.percentageChanged = 0.01;
        this._bindEvent();
    }

    // 绑定事件
    _bindEvent() {
        // 监听主图相机变化
        this._viewer.camera.changed.addEventListener(this._syncMap.bind(this)); 
        this._viewer.scene.preRender.addEventListener(this._syncEyeMap.bind(this)); 
    }
    _syncMap() {
        // 直接设置相机位置和姿态,而不是使用 flyTo 方法
        this._hawkEyeMap.camera.setView({
            destination: this._viewer.camera.positionWC,
            orientation: {
                heading: this._viewer.camera.heading,
                pitch: this._viewer.camera.pitch,
                roll: this._viewer.camera.roll,
            }
        });
    }
    // 同步鹰眼地图
    _syncEyeMap() {
        this._hawkEyeMap.scene.requestRender(); 
    }
}
export default HawkEyeMap;

2.对js文件进行调用与初始化

import HawkEyeMap from "../js/Overview/Overview.js"  
   
let hawkEyeMap = ref(null);
hawkEyeMap.value = new HawkEyeMap(viewer);


总结

本片文章主要在于自己学习总结、记录。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值