Hi there,
I am looking for zoom in\zoom out event in cesium.
is there any?
What exactly do you mean by zoomIn/zoomOut.
The Cesium camera can move and rotate at any angle and in any direction, so the concept of zoomIn/zoomOut as it is used in a 2D map is meaningless. Zoom-in in Cesium means the camera moved in a positive direction it is pointing, and zoom out means the negative direction. It has no relation to how close you are to the Earth or how much of the map is in view.
Assuming you simply want to know when the camera moves, you can use the camera.moveStart moveEnd events, of which there is an example here: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Camera.html&label=Showcases
If you want to know how close the camera is to the surface of the Earth, you can just get the camera’s height via camera.positionCartographic.height. his provides the height relative to the ellipsoid, not the terrain.
If you can explain in more detail what you are trying to do, we can make specific suggestions.
Thanks for the answer.
The rotation of the camera in our project is disabled which means that there is no 2.5D.
By saying zoom in\zoom out i mean that the camera height has been changed.
Camera move is overspec for my situation - i just need to know when the camera height is changed.
Is there any event or any way to know this?
I still think the camera move events are the best way to handle this, just check the height in the callback. Otherwise you can listen to the preRender event and do it that way.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
var lastHeight;
scene.preRender.addEventListener(function(){
var camera = scene.camera;
var height = camera.positionCartographic.height;
if(lastHeight !== height) {
//Camera height has changed
lastHeight = height;
}
});
It seems that the height changes each time(the height from the surface changes each camera move).
Yes, that’s because the camera is rotating a fixed radius from the center of the earth, but the earth itself is an ellipsoid not a sphere. Having the camera rotate at a fixed height above the earth would create odd behavior and movement…