How to limit the scope of Map browsing in Cesium Development
This article is about how to limit the scope of map browsing in Cesium development. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In the development of two-dimensional map, there are maxbounds attribute or maxextent attribute, which can limit the browsing of the map to a certain range of four-to-coordinate.
Compared with the two-dimensional map, the three-dimensional map has more parameters such as height, rotation, viewing angle and so on. The API that sets the lowest and highest viewing height in Cesium can be controlled on the viewing height. The following code is as follows:
Viewer.scene.screenSpaceCameraController.maximumZoomDistance = 100000
Viewer.scene.screenSpaceCameraController.minimumZoomDistance = 10
The API with a range of four to four has not been found and requires further development based on the existing API.
The idea is to control the scope of browsing in the pre-set range of four to real-time detection, beyond the range, let the lens return to the set range.
The real-time monitoring function uses preRender, and this event is executed frequently:
Viewer.scene.preRender.addEventListener (function () {/ / function content})
Cesium's lens field of view, which starts with computeViewRectangle, calculates a viewing field of view, and the result is west,east,north,south5 range parameters.
Let _ viewRectangle = viewer.camera.computeViewRectangle ()
Then compare the above four range parameters with the set four-to-range, and use the set four-to-range for the part out of the range. finally, the viewing range of the camera is forced to jump back to the viewing field of view to prevent it from exceeding.
However, in such a calculation, the scene has a certain jump, and the effect is not very ideal. Later, we expanded the set range of four to viewer.camera.position, limited the viewing coordinates to four to the range, and forced to jump back to the part beyond the range. Although there is a certain error in the viewing range, the overall effect is still better.
Thank you for reading! This is the end of the article on "how to limit the scope of map browsing in Cesium development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!