Class WebMercatorProjection

java.lang.Object
net.buildtheearth.terracore.geo.projection.mercator.WebMercatorProjection
All Implemented Interfaces:
GeographicProjection

public class WebMercatorProjection extends Object implements GeographicProjection
Implementation of the web Mercator projection, with projected space normalized between 0 and 2^zoom * 256. This projection is mainly used by tiled mapping services like GoogleMaps or OpenStreetMap. In this implementation of the projection, 1 unit on the projected space corresponds to 1 pixel on those services at the same zoom level. The origin is on the upper left corner of the map.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    protected final double
     
    protected final double
     
    protected final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double[]
    Indicates the minimum and maximum X and Y coordinates on the projected space.
    double[]
    fromGeo(double longitude, double latitude)
    Converts geographic coordinates to map coordinates
    double
    Gives an estimation of the scale of this projection.
     
    double[]
    toGeo(double x, double y)
    Converts map coordinates to geographic coordinates
     
    boolean
    Indicates whether or not the north pole is projected to the north of the south pole on the projected space, assuming Minecraft's coordinate system cardinal directions for the projected space (north is negative Z).
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.buildtheearth.terracore.geo.projection.GeographicProjection

    azimuth, azimuth, tissot, tissot, vector
  • Field Details

    • LIMIT_LATITUDE

      public static final double LIMIT_LATITUDE
    • zoom

      protected final int zoom
    • scaleTo

      protected final transient double scaleTo
    • scaleFrom

      protected final transient double scaleFrom
  • Constructor Details

    • WebMercatorProjection

      public WebMercatorProjection(Integer zoom)
  • Method Details

    • toGeo

      public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException
      Description copied from interface: GeographicProjection
      Converts map coordinates to geographic coordinates
      Specified by:
      toGeo in interface GeographicProjection
      Parameters:
      x - - x map coordinate
      y - - y map coordinate
      Returns:
      {longitude, latitude} in degrees
      Throws:
      OutOfProjectionBoundsException - if the specified point on the projected space cannot be mapped to a point of the geographic space
    • fromGeo

      public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException
      Description copied from interface: GeographicProjection
      Converts geographic coordinates to map coordinates
      Specified by:
      fromGeo in interface GeographicProjection
      Parameters:
      longitude - - longitude, in degrees
      latitude - - latitude, in degrees
      Returns:
      {x, y} map coordinates
      Throws:
      OutOfProjectionBoundsException - if the specified point on the geographic space cannot be mapped to a point of the projected space
    • bounds

      public double[] bounds()
      Description copied from interface: GeographicProjection
      Indicates the minimum and maximum X and Y coordinates on the projected space.
      Specified by:
      bounds in interface GeographicProjection
      Returns:
      {minimum X, minimum Y, maximum X, maximum Y}
    • upright

      public boolean upright()
      Description copied from interface: GeographicProjection
      Indicates whether or not the north pole is projected to the north of the south pole on the projected space, assuming Minecraft's coordinate system cardinal directions for the projected space (north is negative Z).
      Specified by:
      upright in interface GeographicProjection
      Returns:
      north pole Z <= south pole Z
    • metersPerUnit

      public double metersPerUnit()
      Description copied from interface: GeographicProjection
      Gives an estimation of the scale of this projection. This is just an estimation, as distortion is inevitable when projecting a sphere onto a flat surface, so this value varies from places to places in reality.
      Specified by:
      metersPerUnit in interface GeographicProjection
      Returns:
      an estimation of the scale of this projection
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • properties

      public Map<String,Object> properties()
      Specified by:
      properties in interface GeographicProjection
      Returns:
      any additional configuration properties used by this projection
    • zoom

      public int zoom()