cesium 监听滚轮获取屏幕四角坐标,视角高度,缩放等级

文章介绍了如何在Cesium地图库中获取视图范围的四个角落的经纬度,并实现了一个屏幕空间事件处理器,当用户滚动鼠标时触发回调函数,输出经纬度信息。
摘要由CSDN通过智能技术生成
//获取四角经纬度
export const fourWind = () => {
    // 获取当前视图范围
    var extent = viewer.camera.computeViewRectangle();

    // 提取四个角的经纬度
    var southwest = Cesium.Rectangle.southwest(extent);
    var southeast = Cesium.Rectangle.southeast(extent);
    var northeast = Cesium.Rectangle.northeast(extent);
    var northwest = Cesium.Rectangle.northwest(extent);
    return northwest
    // 打印经纬度信息
    console.log("Southwest Corner: " + Cesium.Math.toDegrees(southwest.longitude) + ", " + Cesium.Math.toDegrees(southwest.latitude));
    console.log("Southeast Corner: " + Cesium.Math.toDegrees(southeast.longitude) + ", " + Cesium.Math.toDegrees(southeast.latitude));
    console.log("Northeast Corner: " + Cesium.Math.toDegrees(northeast.longitude) + ", " + Cesium.Math.toDegrees(northeast.latitude));
    console.log("Northwest Corner: " + Cesium.Math.toDegrees(northwest.longitude) + ", " + Cesium.Math.toDegrees(northwest.latitude));
}

//监听鼠标滚轮事件
export const ScreenSpaceEventHandler = (callback) => {

    const handle3D = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handle3D.setInputAction(() => {
        console.log(fourWind(), 'yi1')
           // var level = Math.ceil(viewer.camera.positionCartographic.height);
        // console.log(level,'缩放等级')
         // var height = viewer.camera.positionCartographic.height;
        // console.log(height,'高度')
        callback(fourWind())
    }, Cesium.ScreenSpaceEventType.WHEEL);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值