View Source SphericalMercator (Spherical Mercator v1.0.0)
This is a port of MapBox's SphericalMercator JS library to Elixir.
The API remains similar, so refer to the original project for the documentation.
The code could be prettier but it aims at following the style of original implementation.
Summary
Types
Two-element list with coordinates in the form [x,y]
or [long,lat]
.
Four-element list with coords bounding box in the form [w, s, e, n]
.
Projection, either "WGS84" or "900913".
Four-element list with XYZ bounding box in the form [min_x, min_y, max_x, max_y]
.
Functions
Convert tile xyz value to bbox of the form [w, s, e, n]
Convert projection of given bbox.
Convert lon/lat values to 900913 x/y.
Convert 900913 x/y values to lon/lat.
Convert screen pixel value to lon lat
SphericalMercator constructor: precaches calculations for fast tile lookups.
Convert lon lat to screen pixel value.
Convert bbox to xyx bounds
Types
@type coords() :: [float()]
Two-element list with coordinates in the form [x,y]
or [long,lat]
.
@type coordsbox() :: [float()]
Four-element list with coords bounding box in the form [w, s, e, n]
.
@type srs() :: String.t()
Projection, either "WGS84" or "900913".
@type t() :: %SphericalMercator{ cache: Map.t(), expansion: pos_integer(), size: number() }
@type xyzbox() :: [pos_integer()]
Four-element list with XYZ bounding box in the form [min_x, min_y, max_x, max_y]
.
Functions
@spec bbox(t(), pos_integer(), pos_integer(), number(), boolean(), srs()) :: coordsbox()
Convert tile xyz value to bbox of the form [w, s, e, n]
sm
- a SphericalMercator structx
- x (longitude) numbery
- y (latitude) numberzoom
- zoomtms_style
- whether to compute using tms-stylesrs
- projection for resulting bbox (WGS84|900913)
Returns a bbox list of values in form [w, s, e, n]
.
Convert projection of given bbox.
bbox
- bbox in the form[w, s, e, n]
.to
- projection of output bbox (WGS84|900913). Input bboxassumed to be the "other" projection.
Returns bbox with reprojected coordinates.
Convert lon/lat values to 900913 x/y.
Convert 900913 x/y values to lon/lat.
Convert screen pixel value to lon lat
sm
- a SphericalMercator structpx
- a list ([x, y]
) array of geographic coordinates.zoom
- zoom level.
SphericalMercator constructor: precaches calculations for fast tile lookups.
Convert lon lat to screen pixel value.
sm
- a SphericalMercator structll
- a list ([lon, lat]
) of geographic coordinates.zoom
- zoom level.
Convert bbox to xyx bounds
bbox
- bbox in the form[w, s, e, n]
.zoom
- zoom.tms_style
- whether to compute using tms-style.srs
- projection of input bbox (WGS84|900913).
Returns XYZ bounding box with list [minX, maxX, minY, maxY]
.