focusedZoomCenter method

LatLng focusedZoomCenter(
  1. Point<num> cursorPos,
  2. double zoom
)

Calculate the center point which would keep the same point of the map visible at the given cursorPos with the zoom set to zoom.

Implementation

LatLng focusedZoomCenter(Point cursorPos, double zoom) {
  // Calculate offset of mouse cursor from viewport center
  final viewCenter = nonRotatedSize / 2;
  final offset = (cursorPos - viewCenter).rotate(rotationRad);
  // Match new center coordinate to mouse cursor position
  final scale = getZoomScale(zoom, this.zoom);
  final newOffset = offset * (1.0 - 1.0 / scale);
  final mapCenter = project(center);
  final newCenter = unproject(mapCenter + newOffset);
  return newCenter;
}