centerOnAreaRect method
- RectangleGeographicArea 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 RectangleGeographicArea 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 UI overlays.
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 center, defined by top-left and bottom-right WGS84 coordinatesviewRc: 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 RectangleGeographicArea 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,
},
);
}