centerOnAreaRect method

void centerOnAreaRect(
  1. GeographicArea area, {
  2. required Rectangle<int> viewRc,
  3. int zoomLevel = -1,
  4. 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 center
  • viewRc: 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 rectangle
  • zoomLevel: Zoom level for the centered view. Use -1 for automatic selection to fit the area within viewRc. Defaults to -1
  • animation: Animation settings for the centering operation. If null, centering occurs instantly. Defaults to null

See also:

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,
    },
  );
}