zoom method

  1. @override
double zoom(
  1. double scale
)
override

Scale to Zoom function.

Implementation

@override
double zoom(double scale) {
  // Find closest number in _scales, down
  double? downScale = _closestElement(scales, scale);
  int downZoom = scales.indexOf(downScale);

  // Check if scale is downScale => return array index
  if (scale == downScale) {
    return downZoom.toDouble();
  }

  if (downScale == null) {
    return double.negativeInfinity;
  }

  // Interpolate
  int nextZoom = downZoom + 1;
  double? nextScale = scales[nextZoom];

  if (nextScale == null) {
    return double.infinity;
  }

  double scaleDiff = nextScale - downScale;
  return (scale - downScale) / scaleDiff + downZoom;
}