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 MapNavigatorMapNavigatorMapNavigator of the MapMapMap.

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

MapNavigatorMapNavigatorMapNavigator 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();
}
var viewMapTransformation = _map.GetViewMapTransformation();
var mapPoint = viewMapTransformation.ViewToMap(Map.LocationMode.ClosestSurface, fromViewLocation);
if (mapPoint != null)
{
    _mapNavigator.NewPanAction().From(mapPoint).ToLocation(toViewLocation).Pan();
}
Map.ViewMapTransformation viewMapTransformation = map.getViewMapTransformation();
Point mapPoint = viewMapTransformation.viewToMap(Map.LocationMode.ClosestSurface, fromLocationPixels);
if (mapPoint != null) {
  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::newFitActionMapNavigator::newFitActionMapNavigator::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();
_mapNavigator.NewFitAction().Bounds(bounds).FitMarginPercent(5).Fit();
map.getMapNavigator().newFitAction().bounds(bounds).fitMarginPercent(5).fit();

Constraining the camera