onClick(viewer) { //获取被点击的canvas var canvas= new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); canvas.setInputAction(function (event) { var earthPosition = viewer.camera.pickEllipsoid(event.position,viewer.scene.globe.ellipsoid); var cartographic = Cesium.Cartographic.fromCartesian(earthPosition, viewer.scene.globe.ellipsoid, new Cesium.Cartographic()); var lat=Cesium.Math.toDegrees(cartographic.latitude); var lng=Cesium.Math.toDegrees(cartographic.longitude); var height=cartographic.height; console.log(`经度:${lng},纬度:${lat},高度:${height}`); }, Cesium.ScreenSpaceEventType.LEFT_CLICK); },
Cesium点击地图获取经纬度
Cesium是基于webGl的优秀GIS框架,这里介绍点击Cesium地图任意位置,获取点击点的经纬度以及高度: