offsetToCrs method
Calculate the LatLng coordinates for a given Offset and an optional
zoom level. If zoom
is not provided the current zoom level of the
MapCamera gets used.
Implementation
LatLng offsetToCrs(Offset offset, [double? zoom]) {
final focalStartPt = projectAtZoom(center, zoom ?? this.zoom);
final point =
(offset - nonRotatedSize.center(Offset.zero)).rotate(rotationRad);
final newCenterPt = focalStartPt + point;
final worldWidth = getWorldWidthAtZoom(zoom ?? this.zoom);
double bestX = newCenterPt.dx;
if (worldWidth != 0) {
while (bestX > worldWidth) {
bestX -= worldWidth;
}
while (bestX < 0) {
bestX += worldWidth;
}
}
return unprojectAtZoom(Offset(bestX, newCenterPt.dy), zoom ?? this.zoom);
}