var viewer = new Cesium.Viewer('cesiumContainer'); viewer.entities.add({ id:'id', position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), billboard :{ image : '../images/Cesium_Logo_overlay.png' } }); var pointDraged = null; var leftDownFlag=false; viewer.screenSpaceEventHandler.setInputAction(leftDownAction, Cesium.ScreenSpaceEventType.LEFT_DOWN); viewer.screenSpaceEventHandler.setInputAction(leftUpAction, Cesium.ScreenSpaceEventType.LEFT_UP); viewer.screenSpaceEventHandler.setInputAction(mouseMoveAction, Cesium.ScreenSpaceEventType.MOUSE_MOVE); function leftDownAction(e) { console.log("左键按下"); pointDraged = viewer.scene.pick(e.position);//选取当前的entity leftDownFlag = true; if (pointDraged) { viewer.scene.screenSpaceCameraController.enableRotate = false;//锁定相机 } } function leftUpAction(e) { console.log("左键抬起"); leftDownFlag = false; pointDraged=null; viewer.scene.screenSpaceCameraController.enableRotate = true;//解锁相机 } function mouseMoveAction(e) { if (leftDownFlag === true && pointDraged != null) { console.log("鼠标移动"); var ray = viewer.camera.getPickRay(e.endPosition); var cartesian = viewer.scene.globe.pick(ray, viewer.scene); console.log(cartesian); pointDraged.id.position = new Cesium.CallbackProperty(function () { return cartesian; }, false);//此处根据具体entity来处理,也可能是pointDraged.id.position=cartesian; } }
线上测试环境:沙盘环境
到此这篇cesium在三维地图中拖拽移动实体位置的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/yd-react-native/11180.html