centerOnRoute method

void centerOnRoute(
  1. Route route, {
  2. Rectangle<int>? screenRect,
  3. GemAnimation? animation,
})

Centers the map view on an entire route with automatic zoom adjustment.

Positions the map to display the complete route path, automatically selecting the optimal zoom level to fit the entire route within the specified screen rectangle or the full viewport if no rectangle is provided.

This is useful for providing an overview of a calculated route before navigation or for displaying route alternatives.

Parameters

  • route: The Route object to center on and display
  • screenRect: Target screen rectangle in physical pixels where the route 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 centerOnRoute(
  final Route route, {
  final Rectangle<int>? screenRect,
  final GemAnimation? animation,
}) {
  objectMethod(
    _pointerId,
    'MapView',
    'centerOnRoute',
    args: <String, dynamic>{
      'route': route.pointerId,
      if (screenRect != null) 'rc': RectType<int>.fromRectangle(screenRect),
      if (animation != null) 'animation': animation,
    },
  );
}