The camera attached to the MapScene defines the section of the map that is rendered when a frame is drawn. It controls the viewport, handles user interactions, and provides methods for programmatic navigation.
The camera is your primary tool for controlling what users see on the map.
// Set minimum zoom levelcamera->setMinZoom(5.0);// Set maximum zoom levelcamera->setMaxZoom(18.0);// Get constraintsdouble minZoom = camera->getMinZoom();double maxZoom = camera->getMaxZoom();
Zoom levels typically range from 0 (world view) to 20+ (street level), matching standard web map zoom conventions.
// Rotate map (angle in radians)camera->setRotation(M_PI / 4, true); // 45 degrees, animated// Get current rotationfloat rotation = camera->getRotation();// Enable/disable rotation by usercamera->setRotationEnabled(true);// Enable snap to north (auto-rotate to 0 when close)camera->setSnapToNorthEnabled(true);
// Define bounds in map coordinatesRectCoord mapBounds( Coord(systemId, minX, minY, 0.0), Coord(systemId, maxX, maxY, 0.0));camera->setBounds(mapBounds);// Get current boundsRectCoord bounds = camera->getBounds();// Check if coordinate is in boundsbool inBounds = camera->isInBounds(someCoord);
// Get currently visible areaRectCoord visibleRect = camera->getVisibleRect();// Get visible area adjusted for paddingRectCoord paddedRect = camera->getPaddingAdjustedVisibleRect();
class MyCameraListener : public MapCameraListenerInterface {public: void onCameraChanged() override { // Camera position or zoom changed } void onBoundsChanged() override { // Camera bounds changed }};auto listener = std::make_shared<MyCameraListener>();camera->addListener(listener);// Remove listener when donecamera->removeListener(listener);
The camera integrates with the touch handler for gesture recognition:
// The camera interprets touch events passed by the TouchHandler// Default gestures include:// - Pan: Move the camera// - Pinch: Zoom in/out// - Rotate: Rotate the map (if enabled)// - Double-tap: Zoom in
The Maps Core includes a DefaultTouchHandler that recognizes standard gestures.
// Get VP matrix (double precision)auto vpMatrixD = camera->getLastVpMatrixD();// Get VP matrix (float precision)auto vpMatrix = camera->getLastVpMatrix();// Get inverse VP matrixauto inverseVpMatrix = camera->getLastInverseVpMatrix();// Get view bounds from last VP matrixauto viewBounds = camera->getLastVpMatrixViewBounds();// Get rotation from last VP matrixauto rotation = camera->getLastVpMatrixRotation();// Get zoom from last VP matrixauto zoom = camera->getLastVpMatrixZoom();
Use animated movements for better user experience. Set animated to true for position, zoom, and rotation changes.
Bounds Constraints
Set appropriate bounds to prevent users from panning to empty areas. Use setBoundsRestrictWholeVisibleRect(true) to keep the entire visible area within bounds.
Zoom Limits
Configure min/max zoom based on your data. Prevent zooming too far in (where there’s no data) or too far out (where content is too small).
Performance
Cache coordinate conversions when possible. Converting coordinates repeatedly in update loops can impact performance.