sphericalmercator
Version, currently 0.1.01 version
- 0.1.0latestJun 23, 2020
github.com/ferblape/sphericalmercator
A Crystal port of mapbox/sphericalmercator Javascript package
Installation
# Add this to your shard.yml
dependencies:
sphericalmercator:
github: ferblape/sphericalmercator
version: ~> 0.1.0Then run:
shards installshard.yml
- Crystal
0.35.1- License
- MIT
- Author
- Fernando Blat
Dependencies
This version declares no dependencies.
README
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
-
Add the dependency to your
shard.yml:dependencies: sphericalmercator: github: ferblape/sphericalmercator -
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]
x{Number} x (longitude) number.y{Number} y (latitude) number.zoom{Number} zoom.tms_style{Boolean} whether to compute using tms-style. (optional, default false)srs{String} projection for resulting bbox (WGS84|900913). (optional, default WGS84)
Returns bbox array of values in form [w, s, e, n].
xyz(bbox, zoom, tms_style, srs)
Convert bbox to xyz bounds
bbox{Number} bbox in the form[w, s, e, n].zoom{Number} zoom.tms_style{Boolean} whether to compute using tms-style. (optional, default false)srs{String} projection of input bbox (WGS84|900913). (optional, default WGS84)
Returns {Object} XYZ bounds containing minX, maxX, minY, maxY properties.
convert(bbox, to)
Convert bbox from 900913 to WGS84 or vice versa
bbox{Number} bbox in the form[w, s, e, n].to{String} projection of resulting bbox (WGS84|900913). (optional, default WGS84)
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
- Fork it (https://github.com/ferblape/sphericalmercator/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Mapbox - original creators of the code
- Fernando Blat - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Jun 23, 2020
- Commit
d66d450bce4e- Crystal
0.35.1- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/ferblape/sphericalmercator
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 16, 2026
- Versions
- 1