centerZoomFitBounds method

  1. @override
  2. @Deprecated('Prefer `CameraFit.bounds(bounds: bounds).fit(controller.camera)` or `CameraFit.insideBounds(bounds: bounds).fit(controller.camera)`. ' 'This method is replaced by applying a CameraFit to the MapCamera. ' 'This method is deprecated since v6.')
CenterZoom centerZoomFitBounds(
  1. LatLngBounds bounds, {
  2. FitBoundsOptions options = const FitBoundsOptions(padding: EdgeInsets.all(12)),
})
override

Calculates the appropriate center and zoom level for the map to perfectly fit bounds, with additional configurable options

Does not move/zoom the map: see fitBounds.

Implementation

@override
@Deprecated(
  'Prefer `CameraFit.bounds(bounds: bounds).fit(controller.camera)` or `CameraFit.insideBounds(bounds: bounds).fit(controller.camera)`. '
  'This method is replaced by applying a CameraFit to the MapCamera. '
  'This method is deprecated since v6.',
)
CenterZoom centerZoomFitBounds(
  LatLngBounds bounds, {
  FitBoundsOptions options =
      const FitBoundsOptions(padding: EdgeInsets.all(12)),
}) {
  final cameraFit = options.inside
      ? CameraFit.insideBounds(
          bounds: bounds,
          padding: options.padding,
          maxZoom: options.maxZoom,
          forceIntegerZoomLevel: options.forceIntegerZoomLevel,
        )
      : CameraFit.bounds(
          bounds: bounds,
          padding: options.padding,
          maxZoom: options.maxZoom,
          forceIntegerZoomLevel: options.forceIntegerZoomLevel,
        );

  final fittedState = cameraFit.fit(camera);
  return CenterZoom(
    center: fittedState.center,
    zoom: fittedState.zoom,
  );
}