How to limit the boundaries the camera may travel in

Hello,

My question today is how can I define boundaries that the user can view? I would like to define a rectangle with lat/lon, or something similar, that the user must stay in. Is this possible?

I did find the ScreenSpaceCameraController documentation that allows me to define minimum and maximum zoom distance, which will be helpful, but I haven't found anything that allows me to limit lat/lon position (although I'm sure it is there somewhere)

Thanks.

You could check very frame the camera position, convert to Cartographic terms and cap it, like if (lat > maxLat) {lat = maxLat;} then convert back to Cartesian and set camera.position to that.

viewer.clock.onTick.addEventListener(function(clock)

{

//code here

});

Actually the camera object already calculates cartographic
viewer.scene.camera.positionCartographic

however you can only get the Cartographic property and not set it, you can only set camera position by using Cartesian.

Depending on the use case I would recommend either having your applications user event capture handle this. You want to keep the clock tick events as minimal as possible and since it gets called so often even an simple fetch and compare to set a boolean value could be considered costly. Better to have your keyboard or mouse event handler detect when it should stop movement.

Keyboard and 2Dmouse might not be the only sources of camera movements. The camera object does check if it has changed

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Camera.js#L395

However it seems to keep this information to itself and doesn’t share with the outside world. It would be nice if it would invoke a callback call when position has changed, and it would only be called when updatemembers is called.