Skip to main content

struct WebMercator12

(Niantic.Lightship.Maps.Core.Coordinates.WebMercator12)

Overview

A type specifying location on the surface of the Earth in Web Mercator coordinates at zoom level 12: https://en.wikipedia.org/wiki/Web_Mercator_projection

struct WebMercator12 {
// fields

static const int ZOOM_LEVEL = 12;
static const int MIN_TILE_COORD = 0;
static const int MAX_TILE_COORD =(1<<ZOOM_LEVEL) - 1;
static const double MIN_LATITUDE_DEGREES = Mercator.MIN_LATITUDE_DEGREES;
static const double MAX_LATITUDE_DEGREES = Mercator.MAX_LATITUDE_DEGREES;
readonly double East;
readonly double North;
readonly double Elevation;

// methods

WebMercator12(in Vector3D vec3);
WebMercator12(Vector3 vec3);
WebMercator12(double east, double elevation, double north);
Vector3D ToVector3D();
LatLng ToLatLng();
override string ToString();
static double WrapLongitudeDegrees(double longitudeDegrees);
static double ClampLatitudeDegrees(double latitudeDegrees);
static double WrapLongitudeCoord(double longitudeCoord);
static double ClampLatitudeCoord(double latitudeCoord);
static int WrapLongitudeCoord(int longitudeCoord);
static int ClampLatitudeCoord(int latitudeCoord);
static double FromLongitude(double longitudeDegrees);
static double FromLatitude(double latitudeDegrees);
static double ToLatitude(double latitudeCoord);
static double ToLongitude(double x);
static double GetMetersPerUnit(double latitudeDegrees);
};

Detailed Documentation

A type specifying location on the surface of the Earth in Web Mercator coordinates at zoom level 12: https://en.wikipedia.org/wiki/Web_Mercator_projection

East: Longitude -180 maps to 0. Longitude 180 maps to 4095.

North: Latitude ~ -85 maps to 0. Longitude ~ 85 maps to 4095.

Fields

ZOOM_LEVEL

static const int ZOOM_LEVEL = 12

The zoom level of a WebMercator12 coordinate (which is 12)

MIN_TILE_COORD

static const int MIN_TILE_COORD = 0

The minimum tile coordinate value

MAX_TILE_COORD

static const int MAX_TILE_COORD =(1<<ZOOM_LEVEL) - 1

The maximum tile coordinate value

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

East

readonly double East

positive going East

North

readonly double North

positive going North

Elevation

readonly double Elevation

meters, positive going up

Methods

WebMercator12

WebMercator12(in Vector3D vec3)

Create a WebMercator12 coordinate from a Vector3 (of doubles) where x -> east y -> north z -> up

    Parameters:

    vec3 -

WebMercator12

WebMercator12(Vector3 vec3)

Create a WebMercator12 coordinate from a Vector3 (of floats) where x -> east y -> north z -> up

    Parameters:

    vec3 -

WebMercator12

WebMercator12(double east, double elevation, double north)

Create a WebMercator12 coordinate from north, east, and elevation

    Parameters:

    east -

    elevation -

    north -

ToVector3D

Vector3D ToVector3D()

Convert to a Vector3D where east -> x north -> y up -> z

    Returns:

ToLatLng

LatLng ToLatLng()

Converts a location in WebMercator12 coordinates to LatLng

    Returns:

    The current location in WebMercator12

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.

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

WrapLongitudeCoord

static double WrapLongitudeCoord(double longitudeCoord)

Wraps a longitude (in tile coordinates) if it's outside of the range defined by MIN_TILE_COORD and MAX_TILE_COORD.

    Parameters:

    longitudeCoord - The longitude to wrap

    Returns:

    A longitude wrapped around the globe such that it fits within the valid range of longitudes.

ClampLatitudeCoord

static double ClampLatitudeCoord(double latitudeCoord)

Clamps a latitude (in tile coordinates) to MIN_TILE_COORD if it's less than the minimum value, or to MAX_TILE_COORD if it's greater than the maximum value.

    Parameters:

    latitudeCoord - The latitude to clamp

    Returns:

    A latitude clamped to within the min and max

WrapLongitudeCoord

static int WrapLongitudeCoord(int longitudeCoord)

Wraps a longitude (in tile coordinates) if it's outside of the range defined by MIN_TILE_COORD and MAX_TILE_COORD.

    Parameters:

    longitudeCoord - The longitude to wrap

    Returns:

    A longitude wrapped around the globe such that it fits within the valid range of longitudes.

ClampLatitudeCoord

static int ClampLatitudeCoord(int latitudeCoord)

Clamps a latitude (in tile coordinates) to MIN_TILE_COORD if it's less than the minimum value, or to MAX_TILE_COORD if it's greater than the maximum value.

    Parameters:

    latitudeCoord - The latitude to clamp

    Returns:

    A latitude clamped to within the min and max

FromLongitude

static double FromLongitude(double longitudeDegrees)

Converts a longitude from degrees to tile coordinates

    Parameters:

    longitudeDegrees -

    Returns:

FromLatitude

static double FromLatitude(double latitudeDegrees)

Converts a latitude from degrees to tile coordinates

    Parameters:

    latitudeDegrees -

    Returns:

ToLatitude

static double ToLatitude(double latitudeCoord)

Converts a latitude from tile coordinates to degrees

    Parameters:

    latitudeCoord -

    Returns:

ToLongitude

static double ToLongitude(double x)

Converts a longitude from tile coordinates to degrees

    Parameters:

    x -

    Returns:

GetMetersPerUnit

static double GetMetersPerUnit(double latitudeDegrees)

Returns ratio of meters to web mercator 12 units (distances in web mercator are stretched towards the poles)

    Parameters:

    latitudeDegrees - Latitude, in degrees