The MapCameraInterface provides comprehensive control over camera position, zoom, rotation, and viewport boundaries. Understanding these controls is essential for creating intuitive map interactions.
// Move to a coordinate with animationCoord newPosition(EPSG3857, longitude, latitude, 0.0);camera->moveToCenterPosition(newPosition, true);// Move without animationcamera->moveToCenterPosition(newPosition, false);
// Get current zoomdouble currentZoom = camera->getZoom();// Set new zoom levelcamera->setZoom(15.0, true); // Animatedcamera->setZoom(15.0, false); // Instant
// Restrict entire visible rect (default: false)// When true: entire viewport must be within bounds// When false: only center point must be within boundscamera->setBoundsRestrictWholeVisibleRect(true);
Add padding to the viewport to account for UI elements:
// Set padding in pixelscamera->setPaddingLeft(20.0f);camera->setPaddingRight(20.0f);camera->setPaddingTop(100.0f); // e.g., for top navigation barcamera->setPaddingBottom(80.0f); // e.g., for bottom controls
Padding affects the “logical” center of the viewport. Use it to ensure important map content isn’t obscured by UI overlays.
// Convert pixels to map unitsdouble distancePx = 100.0;double mapUnits = camera->mapUnitsFromPixels(distancePx);// Get current scaling factordouble scale = camera->getScalingFactor();// Get screen densityfloat ppi = camera->getScreenDensityPpi();
When the user taps a search result or selects a point of interest, use animated camera movements (animated = true) for a smooth, professional experience.
Set appropriate bounds for your use case
For city-specific apps, restrict bounds to prevent users from panning to irrelevant areas. For global apps, use world bounds.
Account for UI overlays with padding
Always set viewport padding to match your UI layout, ensuring map content isn’t hidden behind navigation bars or control panels.
Validate zoom limits match your data
Set minZoom to the lowest zoom level where your map data is meaningful, and maxZoom to your highest detail level to prevent rendering artifacts.