getBoundsZoom method

double getBoundsZoom(
  1. LatLngBounds bounds,
  2. CustomPoint<double> padding, {
  3. bool inside = false,
})

Implementation

double getBoundsZoom(LatLngBounds bounds, CustomPoint<double> padding,
    {bool inside = false}) {
  var zoom = this.zoom;
  var min = options.minZoom ?? 0.0;
  var max = options.maxZoom ?? double.infinity;
  var nw = bounds.northWest;
  var se = bounds.southEast;
  var size = this.size - padding;
  // Prevent negative size which results in NaN zoom value later on in the calculation
  size = CustomPoint(math.max(0, size.x), math.max(0, size.y));
  var boundsSize = Bounds(project(se, zoom), project(nw, zoom)).size;
  var scaleX = size.x / boundsSize.x;
  var scaleY = size.y / boundsSize.y;
  var scale = inside ? math.max(scaleX, scaleY) : math.min(scaleX, scaleY);

  zoom = getScaleZoom(scale, zoom);

  return math.max(min, math.min(max, zoom));
}