Last active
May 26, 2020 23:01
-
-
Save scothis/c9f2695f03380ca5dd96 to your computer and use it in GitHub Desktop.
Cesium.js zoom to camera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var eventHandler, mousePosition; | |
viewer.scene.screenSpaceCameraController.enableZoom = false; | |
eventHandler = new ScreenSpaceEventHandler(viewer.scene.canvas); | |
eventHandler.setInputAction(function (event) { | |
mousePosition = event.endPosition; | |
}, ScreenSpaceEventType.MOUSE_MOVE); | |
eventHandler.setInputAction(function (wheelZoomAmount) { | |
var cameraHeight, directionToZoom, zoomAmount; | |
if (mousePosition) { | |
cameraHeight = viewer.scene.globe.ellipsoid.cartesianToCartographic(viewer.camera.position).height || Number.MAX_VALUE; | |
directionToZoom = viewer.camera.getPickRay(mousePosition).direction; | |
zoomAmount = wheelZoomAmount * cameraHeight / 1000; | |
viewer.camera.move(directionToZoom, zoomAmount); | |
} | |
}, ScreenSpaceEventType.WHEEL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment