centerOnAreaRect method
- GeographicArea area, {
- required Rectangle<
int> viewRc, - int zoomLevel = -1,
- GemAnimation? animation,
Centers a geographic area within a specified screen rectangle region.
Positions the map to display the GeographicArea within the bounds
of a target screen rectangle viewRc. This allows precise control over which
portion of the screen displays the geographic area, useful for implementing
padding around routes or landmarks, or positioning content to avoid overlap with
UI elements put on top.
The zoom level automatically adjusts to fit the area within the specified
rectangle unless explicitly set. Smaller viewRc dimensions result in more
zoomed-out views to fit the area.
For centering with padding, calculate viewRc by adjusting viewport bounds:
subtract padding from each side using coordinate transformations. Make sure the
viewRc is measured in physical pixels relative to the map view's top-left corner.
Convert logical pixels to physical pixels using the device pixel ratio from
GemMapController.devicePixelSize.
Parameters
area: The geographic area to centerviewRc: Target screen rectangle in physical pixels where the area should be displayed, relative to the map view's top-left corner. The area will be scaled to fit within this rectanglezoomLevel: Zoom level for the centered view. Use-1for automatic selection to fit the area withinviewRc. Defaults to-1animation: Animation settings for the centering operation. Ifnull, centering occurs instantly. Defaults tonull
See also:
- centerOnArea - Center area at a single screen point
- centerOnCoordinates - Center on coordinate point
- getOptimalRoutesCenterViewport - Calculate optimal viewport for routes
- getOptimalHighlightCenterViewport - Calculate optimal viewport for highlights
Implementation
void centerOnAreaRect(
final GeographicArea area, {
required final Rectangle<int> viewRc,
final int zoomLevel = -1,
final GemAnimation? animation,
}) {
objectMethod(
_pointerId,
'MapView',
'centerOnAreaRect',
args: <String, Object?>{
'area': area,
'zoomLevel': zoomLevel,
'viewRc': RectType<int>.fromRectangle(viewRc),
if (animation != null) 'animation': animation,
},
);
}