• cesium 获取 bbox、获取四至、获取边界、获取左上角经纬度、获取 extend、获取界面四边的经纬度


    const getViewExtend = () => {
        let params = {}
        let extend = viewer.camera.computeViewRectangle()
        if (typeof extend === 'undefined') {
            //2D下会可能拾取不到坐标,extend返回undefined,因此作如下转换
            let canvas = viewer.scene.canvas
            let upperLeft = new Cesium.Cartesian2(0, 0) //canvas左上角坐标转2d坐标
            let lowerRight = new Cesium.Cartesian2(canvas.clientWidth, canvas.clientHeight) //canvas右下角坐标转2d坐标
    
            let ellipsoid = viewer.scene.globe.ellipsoid
            let upperLeft3 = viewer.camera.pickEllipsoid(upperLeft, ellipsoid) //2D转3D世界坐标
    
            let lowerRight3 = viewer.camera.pickEllipsoid(lowerRight, ellipsoid) //2D转3D世界坐标
    
            let upperLeftCartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(upperLeft3) //3D世界坐标转弧度
            let lowerRightCartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(lowerRight3) //3D世界坐标转弧度
    
            let minx = Cesium.Math.toDegrees(upperLeftCartographic.longitude) //弧度转经纬度
            let maxx = Cesium.Math.toDegrees(lowerRightCartographic.longitude) //弧度转经纬度
    
            let miny = Cesium.Math.toDegrees(lowerRightCartographic.latitude) //弧度转经纬度
            let maxy = Cesium.Math.toDegrees(upperLeftCartographic.latitude) //弧度转经纬度
    
            console.log('经度:' + minx + '----' + maxx)
            console.log('纬度:' + miny + '----' + maxy)
    
            params.minx = minx
            params.maxx = maxx
            params.miny = miny
            params.maxy = maxy
        } else {
            //3D获取方式
            params.maxx = Cesium.Math.toDegrees(extend.east)
            params.maxy = Cesium.Math.toDegrees(extend.north)
    
            params.minx = Cesium.Math.toDegrees(extend.west)
            params.miny = Cesium.Math.toDegrees(extend.south)
        }
    
        // 返回屏幕所在经纬度范围
        return params
    }
    
    // 获取四至坐标
    const { minx, miny, maxx, maxy } = getViewExtend()
    
    // bbox 
    const bbox = [minx, miny, maxx, maxy].join(',')
    
    console.log(bbox)
  • 相关阅读:
    iOS推送证书从申请到使用
    leetcode
    C++測量一段代码的执行时时间
    UIView的几个枚举定义
    在CDialog::OnInitDialog设置DEFAULT-BUTTON的注意事项
    转:VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径
    COM学习笔记
    关于StdAfx.h和StdAfx.cpp
    解决:CWnd::SetWindowText报Assertion failure
    四种DLL:NON-MFC DLL, Regular DLL Statically/Dynamically Linked to MFC, MFC Extension DLL
  • 原文地址:https://www.cnblogs.com/CyLee/p/16003588.html
Copyright © 2020-2023  润新知