Make the camera zoom to center of canvas rather than the mouse point (change from Ceisum 1.11)?

Cesium 1.11 came with this change "The camera now zooms to the point under the mouse cursor, instead of the center of the canvas".

I am wondering if it's possible to use the old method of zooming to the center of the canvas?

The problem for me is that zooming to the mouse point causes the glove to tilt upside down sometimes and if you zoom really fast with your scrollwheel, you will end up at a position you were not expecting (for my existing users who are used to the center canvas zooming).

Only relevant documentation I could find is https://cesiumjs.org/Cesium/Build/Documentation/ScreenSpaceCameraController.html?classFilter=camera

Side question: Is it possible to add an animation when zooming with your mouse scroll wheel (rather than instantly going to the next zoom level, it quickly tweens/flies in instead so it's not as confusing).

Thank you.

I can see this being configurable is a good idea.

I have just been trying the terrain server which has a older version and behaves such zooming is to the center and I must admit, it really annoyed me compaired to ol3 that also zooms to the mouse location. So I just wanted to say that I am very happy that it changed in 1.11. Just wanted to put that out there also, so we do not end up with it going back to the old behaviour, but maybe configurable instead.

Hello,

I don’t see us adding the zoom to the center functionality back in, but I’ll create an issue on GitHub to see what the rest of the team thinks about adding a flag.

Can you explain how you can make the globe tilt upside down? That would definitely be a bug we’d like to fix. I know there’s currently an issue that if you zoom to home then try to tilt with middle mouse clicking the globe will tilt the wrong way at first. Are you able to make it go upside down a different way? Thanks!

-Hannah

Making it an option will most likely not happen because almost all users want the current behavior and the camera code is already complicated enough. That being said, anything can happen as Cesium evolves and making the input more easily configurable is definitely on the long-term roadmap. So it might be an option one day.

In the short term, it’s easy enough to mimic the old behavior in your app. Something like the below should get you mostly there, although some of the scaling code for amounts may need to be tweaked. I didn’t look at the old code to see exactly what it was doing. You could also use this code to offer both in your application if that’s what is needed and provide a toggle to switch back and forth.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

viewer.scene.screenSpaceCameraController.enableZoom = false;

viewer.screenSpaceEventHandler.setInputAction(function(amount){

amount = Cesium.Math.sign(amount) * viewer.scene.camera.positionCartographic.height / Math.log(viewer.scene.camera.positionCartographic.height);

viewer.scene.camera.zoomIn(amount);

}, Cesium.ScreenSpaceEventType.WHEEL);

var rightDragging = false;

viewer.screenSpaceEventHandler.setInputAction(function(){

rightDragging = true;

}, Cesium.ScreenSpaceEventType.RIGHT_DOWN);

viewer.screenSpaceEventHandler.setInputAction(function(){

rightDragging = false;

}, Cesium.ScreenSpaceEventType.RIGHT_UP);

viewer.screenSpaceEventHandler.setInputAction(function(movement){

if(rightDragging) {

viewer.scene.camera.zoomIn(

(viewer.scene.camera.positionCartographic.height *

(movement.endPosition.y - movement.startPosition.y)) /

(Math.log(viewer.scene.camera.positionCartographic.height) * 4));

}

}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

Hope that helps.

Hello all,

not that i want to open up this a bit older idea but i really think this should be considered again.

I think it depends on the use case. I have searched how to change this because the zoom behavior when near the ground is super erratic with the new camera controls as soon as the camera has a little bit of tilt.

Maybe the new camera can be adapted for this, it defintely has its pros but for some aspects i liked the simpler camera control.

Just a thought,
kind regards,
Daniel