sphericalmercator

A Crystal port of @mapbox/sphericalmercator Javascript package.

sphericalmercator provides projection math for converting between mercator meters, screen pixels (of 256x256 or configurable-size tiles), and latitude/longitude.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      sphericalmercator:
        github: ferblape/sphericalmercator
  2. Run shards install

Usage

require "sphericalmercator"

Some datatypes are assumed to be arrays: ll is [lon, lat], xy and px are [x, y].

merc = SphericalMercator.new(256)

px(ll, zoom)

Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level. The inverse of ll

ll(px, zoom)

Convert screen pixel value to lon, lat, at a certain zoom level. The inverse of px

bbox(x, y, zoom, tms_style, srs)

Convert tile xyz value to bbox of the form [w, s, e, n]

Returns bbox array of values in form [w, s, e, n].

xyz(bbox, zoom, tms_style, srs)

Convert bbox to xyz bounds

Returns {Object} XYZ bounds containing minX, maxX, minY, maxY properties.

convert(bbox, to)

Convert bbox from 900913 to WGS84 or vice versa

Returns bbox array of values in form [w, s, e, n].

forward(ll)

Convert lon, lat values to mercator x, y

inverse(xy)

Convert mercator x, y values to lon, lat

Development

TODO Write development instructions here

Contributing

  1. Fork it (https://github.com/ferblape/sphericalmercator/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors