getBoundsCenterZoom method

CenterZoom getBoundsCenterZoom(
  1. LatLngBounds bounds,
  2. FitBoundsOptions options
)

Implementation

CenterZoom getBoundsCenterZoom(
    LatLngBounds bounds, FitBoundsOptions options) {
  var paddingTL =
      CustomPoint<double>(options.padding.left, options.padding.top);
  var paddingBR =
      CustomPoint<double>(options.padding.right, options.padding.bottom);

  var paddingTotalXY = paddingTL + paddingBR;

  var zoom = getBoundsZoom(bounds, paddingTotalXY, inside: false);
  zoom = math.min(options.maxZoom, zoom);

  var paddingOffset = (paddingBR - paddingTL) / 2;
  var swPoint = project(bounds.southWest, zoom);
  var nePoint = project(bounds.northEast, zoom);
  var center = unproject((swPoint + nePoint) / 2 + paddingOffset, zoom);
  return CenterZoom(
    center: center,
    zoom: zoom,
  );
}