latitudeToPixelY method

double latitudeToPixelY(
  1. double latitude
)

Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain zoom level.

@param latitude the latitude coordinate that should be converted. @param zoomLevel the zoom level at which the coordinate should be converted. @return the pixel Y coordinate of the latitude value.

Implementation

double latitudeToPixelY(double latitude) {
  const double pi180 = pi / 180;
  const double pi4 = 4 * pi;
  double sinLatitude = sin(latitude * pi180);
// FIXME improve this formula so that it works correctly without the clipping
  double pixelY =
      (0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / pi4) * _mapSize;
  return min(max(0, pixelY), _mapSize.toDouble());
}