class WebMercator
(Niantic.Lightship.Maps.Core.Coordinates.WebMercator)
Overview
A utility class for coordinate conversion to and from the Web Mercator projection, which represents a location on the surface of the Earth.
class WebMercator {
public:
// fields
static const double MIN_LATITUDE_DEGREES = Mercator.MIN_LATITUDE_DEGREES;
static const double MAX_LATITUDE_DEGREES = Mercator.MAX_LATITUDE_DEGREES;
static const long MIN_TILE_COORD = 0;
// methods
static int MaxTileCoord(int zoomLevel);
static double WrapLongitudeDegrees(double longitudeDegrees);
static double WrapLongitudeCoord(double longitude, int zoomLevel);
static double ClampLatitudeDegrees(double latitudeDegrees);
static double ClampLatitudeCoord(double latitude, int zoomLevel);
static double FromLongitude(double longitudeDegrees, int zoomLevel);
static double ToWrappedLongitude(double longitudeCoord, int zoomLevel);
static double ToLongitude(double longitudeCoord, int zoomLevel);
static double FromLatitude(double latitudeDegrees, int zoomLevel);
static double ToClampedLatitude(double latitudeCoord, int zoomLevel);
static double ToLatitude(double latitudeCoord, int zoomLevel);
static long TileIndex(double pixels, double tileSize);
static double ToZoomLevel(double metersPerPixel, double latitude);
static double GetMetersPerUnit(double latitude, double zoomLevel);
};
Detailed Documentation
A utility class for coordinate conversion to and from the Web Mercator projection, which represents a location on the surface of the Earth.
Fields
MIN_LATITUDE_DEGREES
static const double MIN_LATITUDE_DEGREES = Mercator.MIN_LATITUDE_DEGREES
The minimum latitude supported by the projection, in degrees
MAX_LATITUDE_DEGREES
static const double MAX_LATITUDE_DEGREES = Mercator.MAX_LATITUDE_DEGREES
The maximum latitude supported by the projection, in degrees
MIN_TILE_COORD
static const long MIN_TILE_COORD = 0
The minimum tile coordinate at all zoom levels
Methods
MaxTileCoord
static int MaxTileCoord(int zoomLevel)
The maximum tile coordinate at a given zoom level
Parameters:
zoomLevel
-
WrapLongitudeDegrees
static double WrapLongitudeDegrees(double longitudeDegrees)
Wraps a longitude (in degrees) if it's outside of the range defined by LatLng.MIN_LONGITUDE_DEGREES and LatLng.MAX_LONGITUDE_DEGREES.
Parameters:
longitudeDegrees
- The longitude to wrap
Returns:
A longitude wrapped around the globe such that it fits within the valid range of longitudes.
WrapLongitudeCoord
static double WrapLongitudeCoord(double longitude, int zoomLevel)
Wraps a longitude (in tile coordinates) if it's outside of the range defined by MIN_TILE_COORD and the maximum tile coordinate value for a given zoom level.
Parameters:
longitude
- The longitude to wrap
zoomLevel
- The coordinate's zoom level
Returns:
A longitude wrapped around the globe such that it fits within the valid range of longitudes.
ClampLatitudeDegrees
static double ClampLatitudeDegrees(double latitudeDegrees)
Clamps a latitude (in degrees) to MIN_LATITUDE_DEGREES if it's less than the minimum value, or to MAX_LATITUDE_DEGREES if it's greater than the maximum value.
Parameters:
latitudeDegrees
- The latitude to clamp
Returns:
A latitude clamped to within the min and max
ClampLatitudeCoord
static double ClampLatitudeCoord(double latitude, int zoomLevel)
Clamps a latitude (in tile coordinates) to MIN_TILE_COORD if it's less than the minimum value, or to MaxTileCoord(int) if it's greater than the maximum value for a given zoom level.
Parameters:
latitude
- The latitude to clamp
zoomLevel
- The coordinate's zoom level
Returns:
A latitude clamped to within the min and max
FromLongitude
static double FromLongitude(double longitudeDegrees, int zoomLevel)
Converts a longitude from degrees to tile coordinates
Parameters:
longitudeDegrees
-
zoomLevel
-
Returns:
ToWrappedLongitude
static double ToWrappedLongitude(double longitudeCoord, int zoomLevel)
Converts a longitude from tile coordinates to degrees, and wraps the value if necessary.
Parameters:
longitudeCoord
- The longitude to convert
zoomLevel
- The coordinate's zoom level
Returns:
A longitude wrapped around the globe such that it fits within the valid range of longitudes.
ToLongitude
static double ToLongitude(double longitudeCoord, int zoomLevel)
Converts a longitude from tile coordinates to degrees
Parameters:
longitudeCoord
- The longitude to convert
zoomLevel
- The coordinate's zoom level
Returns:
FromLatitude
static double FromLatitude(double latitudeDegrees, int zoomLevel)
Converts a latitude from degrees to tile coordinates
Parameters:
latitudeDegrees
- The latitude to convert
zoomLevel
- The coordinate's zoom level
Returns:
ToClampedLatitude
static double ToClampedLatitude(double latitudeCoord, int zoomLevel)
Converts a latitude from tile coordinates to degrees, and clamps the value if necessary
Parameters:
latitudeCoord
- The latitude to convert
zoomLevel
- The coordinate's zoom level
Returns:
ToLatitude
static double ToLatitude(double latitudeCoord, int zoomLevel)
Converts a latitude from tile coordinates to degrees
Parameters:
latitudeCoord
- The latitude to convert
zoomLevel
- The coordinate's zoom level
Returns:
TileIndex
static long TileIndex(double pixels, double tileSize)
Converts a coordinate in tile space into a tile index.
Parameters:
pixels
-
tileSize
-
Returns:
ToZoomLevel
static double ToZoomLevel(double metersPerPixel, double latitude)
Converts a distance in meters represented by a pixel to a zoom level and back.
Parameters:
metersPerPixel
-
latitude
-
Returns:
GetMetersPerUnit
static double GetMetersPerUnit(double latitude, double zoomLevel)
Returns ratio of meters to web mercator units (distances in web mercator are stretched towards the poles)
Parameters:
latitude
-
zoomLevel
-
Returns: