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;
  final min = options.minZoom ?? 0.0;
  final max = options.maxZoom ?? double.infinity;
  final nw = bounds.northWest;
  final 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.0, size.x), math.max(0.0, size.y));
  final boundsSize = Bounds(project(se, zoom), project(nw, zoom)).size;
  final scaleX = size.x / boundsSize.x;
  final scaleY = size.y / boundsSize.y;
  final scale = inside ? math.max(scaleX, scaleY) : math.min(scaleX, scaleY);

  zoom = getScaleZoom(scale, zoom);

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