You can change the geographic area shown on the map through interaction with the map, using mouse or touch. You can also change it programmatically using the MapNavigator of the Map.

The human input controllers for mouse and touch interaction also use the MapNavigator to manipulate the extent of the map.

MapNavigator offers these map operations:

You can animate each operation.

Panning and centering a map

  • Center the map on a model or world location

  • Move the map in one direction by a specific number of pixels or world units

This example shows how to translate, or move, the map by a certain number of pixels:

Program: Panning with the Map’s MapNavigator
const auto& viewMapTransformation = map->getViewMapTransformation();
auto mapPoint = viewMapTransformation.viewToMap(Map::LocationMode::ClosestSurface, fromLocationPixels);
if (mapPoint) {
map->getMapNavigator().newPanAction().from(*mapPoint).toLocation(toLocationPixels).pan();
}

Zooming a map or setting a scale

  • Zoom in or zoom out by a certain factor

  • Set the scale of the map

Rotating a map

  • Rotate the map by a delta angle relative to the current rotation

  • Adapt the camera pitch or roll in 3D

Fitting a view to a layer or area

Use the MapNavigator::newFitAction function to make sure that the visible map covers a certain area. You can pass an extent as a Bounds shape in any model or map reference.

This example fits on a given bounds:

Program: Fitting on a certain area
map->getMapNavigator().newFitAction().bounds(bounds).fitMarginPercent(5).fit();

Constraining the camera