For standard operations like zooming and panning, the MapNavigator
API is enough. For an illustration, see here.
3D maps offer you a lot of freedom, though, and sometimes you need full control over the positioning of your camera.
The Camera
API offers such fine-grained camera control.
Note that this API operates at a lower level than the MapNavigator
API.
With the MapNavigator
API, you navigate both 2D and 3D maps in any reference, using the same API calls.
The Camera
API is specific to the camera type you are using, either an OrthographicCamera
or a PerspectiveCamera
.
This example demonstrates how you use the Camera
API to configure a new eye point, and pitch, roll, and yaw:
//Create a new eye point, defined in a WGS 84 reference
const wgs84Reference = getReference("CRS:84");
const eye = createPoint(wgs84Reference, [-132, 34, 3700]);
//Define new pitch, yaw and rolls
const yaw = 163;
const pitch = -45;
const roll = 0;
//When the map is a 3D map, the camera will be a perspective camera
if (map.camera instanceof PerspectiveCamera) {
//Update the camera
const lookFrom = map.camera.asLookFrom();
lookFrom.eye = eye;
lookFrom.yaw = yaw;
lookFrom.pitch = pitch;
lookFrom.roll = roll;
map.camera = map.camera.lookFrom(lookFrom);
}