我开发时用的最多的一个方法,为的是获得具体点的坐标和记录当前相机视角,一部分代码是什么意思我也忘了,反正好用就行;
var arrLoc = []; var pickPosition = { x: null, y: null } var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); //定义事件 handler.setInputAction(function (movement) { // screenLocation.x = movement.position.x; // screenLocation.y = movement.position.y; var cartesian = viewer.camera.pickEllipsoid( movement.position, scene.globe.ellipsoid ); if (cartesian) { var cartographic = Cesium.Cartographic.fromCartesian(cartesian); var longitudeString = Cesium.Math.toDegrees( cartographic.longitude ).toFixed(2); //要更高的精度就修改保留的小数位数 var latitudeString = Cesium.Math.toDegrees( cartographic.latitude ).toFixed(2); //同上 pickPosition.x = longitudeString; pickPosition.y = latitudeString; let cf = { x: parseFloat(pickPosition.x), y: parseFloat(pickPosition.y) } console.log(cf) //鼠标点击位置 var a = { position: viewer.camera.position, heading: viewer.camera.heading, pitch: viewer.camera.pitch } console.log(a) //当前视角 } }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接