centerOnRoutes method

void centerOnRoutes({
  1. List<Route>? routes,
  2. RouteDisplayMode displayMode = RouteDisplayMode.full,
  3. Rectangle<int>? screenRect,
  4. GemAnimation? animation,
})

Centers the map on multiple routes simultaneously with automatic zoom.

Positions the map to display all specified routes, automatically selecting the optimal zoom level to fit all route paths within the target screen rectangle. If no routes are provided, centers on the visible routes from MapViewRoutesCollection.

The display mode controls whether the full route paths are shown or only specific segments, useful for comparing route alternatives or showing multiple navigation options. If RouteDisplayMode.full (default) is used, the entire paths of all routes are considered for centering. If RouteDisplayMode.branches is used, only the differing segments between routes are considered.

Parameters

  • routes: List of Route objects to center on and display. If null, uses visible routes from MapViewRoutesCollection. Defaults to null
  • displayMode: Controls how routes are displayed (full paths, partial segments, etc.). Defaults to RouteDisplayMode.full
  • screenRect: Target screen rectangle in physical pixels where routes should fit, relative to the map view's top-left corner. If null, uses the entire viewport. Defaults to null. Useful for fitting within UI elements or adding margins
  • animation: Animation settings for the centering operation. If null, centering occurs instantly. Defaults to null

See also:

Implementation

void centerOnRoutes({
  final List<Route>? routes,
  final RouteDisplayMode displayMode = RouteDisplayMode.full,
  final Rectangle<int>? screenRect,
  final GemAnimation? animation,
}) {
  objectMethod(
    _pointerId,
    'MapView',
    'centerOnRoutes',
    args: <String, dynamic>{
      'routesList': (routes != null)
          ? RouteList.fromList(routes).pointerId
          : -1,
      'displayMode': displayMode.id,
      if (screenRect != null)
        'viewRc': RectType<int>.fromRectangle(screenRect),
      if (animation != null) 'animation': animation,
    },
  );
}