Share via


Constraining camera movement

Just got a good question:  what if I want to prevent the camera from moving outside certain bounds, for example to restrict altitude?

Technically it may be best to implement your own CameraController, so that you can make sure the restrictions are done smoothly for all cases.  But for many cases a simple mechanism will do.  Here it is:

this.Host.CameraControllers.CameraChanged += new CameraControllerManager.CameraChangedEventHandler(CameraControllers_CameraChanged);

void CameraControllers_CameraChanged(Microsoft.MapPoint.Rendering3D.Cameras.PredictiveCamera camera)

{

   if (camera.Viewpoint.Position.Altitude > 10000)

   {

      camera.Viewpoint.Position.Altitude = 10000;

   }

}