globe.js
實例化
function Globe() { } var viewer Globe.prototype.Init = function () { viewer = new Cesium.Viewer("cesiumContainer", { timeline: false,//時間軸 animation: false,//動畫控制器 allowDataSourcesToSuspendAnimation: true, resolutionScale: 2, infoBox: false, targetFrameRate: 120, shadows: true, shouldAnimate: true, }); }
helloworld.html
// 鼠標事件 var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas); //實例化對象的setInputAction方法 handler.setInputAction(function (event) { var earthPosition = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid); //可以拿到笛卡爾3d坐標系 console.log(earthPosition); //可以得到笛卡爾平面坐標系 }, Cesium.ScreenSpaceEventType.LEFT_CLICK); //鼠標左鍵
//鼠標右鍵 handler.setInputAction(function (event) { var earthPosition = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid); //可以拿到笛卡爾3d坐標系 console.log(earthPosition); //可以得到笛卡爾平面坐標系 }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); //鼠標右鍵
其他鼠標事件
- 鼠標左鍵雙擊事件 Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
- 鼠標左鍵按下事件 Cesium.ScreenSpaceEventType.LEFT_DOWN
- 鼠標左鍵抬起事件 Cesium.ScreenSpaceEventType.LEFT_UP
- 鼠標中鍵單擊事件 Cesium.ScreenSpaceEventType.MIDDLE_CLICK
- 鼠標中鍵按下事件 Cesium.ScreenSpaceEventType.MIDDLE_DOWN
- 鼠標中鍵抬起事件 Cesium.ScreenSpaceEventType.MIDDLE_UP
- 鼠標移動事件 Cesium.ScreenSpaceEventType.MOUSE_MOVE
- 觸摸表面上的雙指事件的結束 Cesium.ScreenSpaceEventType.PINCH_END
- 觸摸表面上雙指移動事件 Cesium.ScreenSpaceEventType.PINCH_MOVE
- 觸摸表面上雙指事件的開始 Cesium.ScreenSpaceEventType.PINCH_START
- 鼠標右鍵單擊事件 Cesium.ScreenSpaceEventType.RIGHT_CLICK
- 鼠標右鍵按下事件 Cesium.ScreenSpaceEventType.RIGHT_DOWN
- 鼠標滾輪事件 Cesium.ScreenSpaceEventType.WHEEL