美文网首页
vue+cesium获取经纬度,高度,海拔

vue+cesium获取经纬度,高度,海拔

作者: 我喜欢吃辣椒 | 来源:发表于2020-07-16 10:36 被阅读0次
            let self = this
            let scene = viewer.scene
            let handler3D = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
            handler3D.setInputAction(function(movement) {
                let pick = new Cesium.Cartesian2(movement.endPosition.x, movement.endPosition.y)
                if (pick) {
                    let cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(pick), viewer.scene)
                    if (cartesian) {
                        //世界坐标转地理坐标(弧度)
                        let cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian)
                        if (cartographic) {
                            //海拔
                            let height = viewer.scene.globe.getHeight(cartographic)
                            //视角海拔高度
                            let he = Math.sqrt(
                                viewer.scene.camera.positionWC.x * viewer.scene.camera.positionWC.x +
                                    viewer.scene.camera.positionWC.y * viewer.scene.camera.positionWC.y +
                                    viewer.scene.camera.positionWC.z * viewer.scene.camera.positionWC.z
                            )
                            let he2 = Math.sqrt(
                                cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z
                            )
                            //地理坐标(弧度)转经纬度坐标
                            let point = [
                                (cartographic.longitude / Math.PI) * 180,
                                (cartographic.latitude / Math.PI) * 180,
                            ]
                            if (!height) {
                                height = 0
                            }
                            if (!he) {
                                he = 0
                            }
                            if (!he2) {
                                he2 = 0
                            }
                            if (!point) {
                                point = [0, 0]
                            }

                            self.viewHeight = (he - he2).toFixed(1) //视高
                            self.lot = point[0].toFixed(6) //经度
                            self.lat = point[1].toFixed(6)//纬度
                            self.elevation = height.toFixed(2)//海拔
                        }
                    }
                }
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
效果图

相关文章

网友评论

      本文标题:vue+cesium获取经纬度,高度,海拔

      本文链接:https://www.haomeiwen.com/subject/tqtphktx.html