欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cesium(坐标转换)

程序员文章站 2022-05-27 14:37:54
...
var viewer = new Cesium.Viewer('cesiumContainer');
    var screen;//屏幕坐标
    var world;//世界坐标
    var Geography;//地理坐标
    
    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction(function(movement){
        //1、屏幕坐标转世界坐标
        world = viewer.scene.globe.pick(viewer.camera.getPickRay(movement.endPosition),viewer.scene);
        console.log('世界坐标',world)
        //2、世界坐标转屏幕坐标
        screen = Cesium.SceneTransforms.wgs84ToWindowCoordinates( viewer.scene, world);
        console.log('屏幕坐标',screen)
        //3、世界坐标转地理坐标(经纬度)
        Geography = viewer.scene.globe.ellipsoid.cartesianToCartographic(world);
        Geography = [Cesium.Math.toDegrees(Geography.longitude), Cesium.Math.toDegrees(Geography.latitude)];
        console.log('地理坐标',Geography);
        //4、地理坐标(经纬度)转世界坐标
        world = Cesium.Cartesian3.fromDegrees(Geography[0], Geography[1]);
        console.log('世界坐标',world);
        
    },Cesium.ScreenSpaceEventType.MOUSE_MOVE);

 

相关标签: cesium