invert method

  1. @override
(double, double) invert(
  1. double x,
  2. double y
)
override

Inverts screen coordinates to geographic longitude, latitude.

Implementation

@override
(double, double) invert(double x, double y) {
  final (rawX, rawY) = removeTransform(x, y);
  final adjustedY = -rawY;

  final rho = math.sqrt(rawX * rawX + adjustedY * adjustedY);
  if (rho > 1) {
    return (double.nan, double.nan);
  }

  final c = math.asin(rho);
  final sinc = math.sin(c);
  final cosc = math.cos(c);

  final phi0 = toRadians(centerLat);
  final sinPhi0 = math.sin(phi0);
  final cosPhi0 = math.cos(phi0);

  double latitude;
  if (rho == 0) {
    latitude = centerLat;
  } else {
    latitude = toDegrees(
      math.asin(cosc * sinPhi0 + adjustedY * sinc * cosPhi0 / rho),
    );
  }

  double longitude;
  if (rho == 0) {
    longitude = centerLon;
  } else {
    longitude = centerLon +
        toDegrees(
          math.atan2(
            rawX * sinc,
            rho * cosPhi0 * cosc - adjustedY * sinPhi0 * sinc,
          ),
        ) -
        _rotate0;
  }

  return (clampLongitude(longitude), clampLatitude(latitude));
}