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
offers these map operations:
-
Panning and centering
-
Scaling to zoom in and out
-
Rotating
-
Fitting to a layer or area
You can animate each operation.
Panning and centering a map
Use the MapNavigator::newPanAction
function to:
-
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:
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
Use the MapNavigator::newZoomAction
function to:
-
Zoom in or zoom out by a certain factor
-
Set the scale of the map
Rotating a map
Use the MapNavigator::newRotateAction
function to:
-
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:
map->getMapNavigator().newFitAction().bounds(bounds).fitMarginPercent(5).fit();
Constraining the camera
See the dedicated article.