Skip to content

Commit

Permalink
typescript, 2.x (#45)
Browse files Browse the repository at this point in the history
* ts, first

* no eslint, format, remove bin

* github action

* update readme and badge

* update changelog

* prepublishOnly script

* 2.0.0-dev.1

* improve constants

* remove .eslintrc

* update readme

* 2.0.0
  • Loading branch information
mapsam authored Oct 2, 2024
1 parent eefe39e commit b60d210
Show file tree
Hide file tree
Showing 20 changed files with 2,656 additions and 1,392 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: js
on: [push]
env:
NODE_VERSION: 20.x
jobs:
tests:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- name: checkout commit
uses: actions/checkout@v4

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm

- name: install node deps
run: npm ci

- name: run tests
run: npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
coverage
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v2.0.0

```js
import { SphericalMercator } from '@mapbox/sphericalmercator'
```

- No default module export
- Migrate project to Typescript
- Use GitHub Actions
- Test with Node.js v20.x
- Use vitest for running tests
- Remove the bin commands, which were undocumented and not tested

## v1.2.0

- Add support for calculating `px` values for longitudes >180 (@riastrad) [#44](https://github.com/mapbox/sphericalmercator/pull/44)
Expand Down
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
[![Build Status](https://travis-ci.com/mapbox/sphericalmercator.svg?branch=master)](http://travis-ci.com/mapbox/sphericalmercator)
[![Run tests](https://github.com/mapbox/sphericalmercator/actions/workflows/test.yml/badge.svg)](https://github.com/mapbox/sphericalmercator/actions/workflows/test.yml)

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

Provides projection math for converting between mercator meters, screen pixels (of 256x256 or configurable-size tiles), and latitude/longitude. Compatible with nodejs packages and in-browser.

See also

* [tilebelt](https://github.com/mapbox/tilebelt) provides ZXY tile math utilities in javascript
* [mercantile](https://github.com/sgillies/mercantile) provides similar utilities for projection and tile math in Python

Compatible with nodejs packages and in-browser.

## Installation

`npm install @mapbox/sphericalmercator`

## API

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

```javascript
import { SphericalMercator } from '@mapbox/sphericalmercator';

// By default, precomputes up to z30
var merc = new SphericalMercator({
size: 256,
antimeridian: true
const merc = new SphericalMercator({
size: 256,
antimeridian: true
});
```

### `px(ll, zoom)`

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

If `antimeridian: true` is passed on initialization of the `SphericalMercator` object, this method will support converting longitude values up to 360°.
Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level. The inverse of `ll`. If `antimeridian: true` is passed on initialization of the `SphericalMercator` object, this method will support converting longitude values up to 360°.

### `ll(px, zoom)`

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

### `bbox(x, y, zoom, tms_style, srs)`
### `bbox(x, y, zoom, tmsStyle, 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)
* `tmsStyle` {Boolean} whether to compute using [tms-style](https://en.wikipedia.org/wiki/Tile_Map_Service). (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)`
### `xyz(bbox, zoom, tmsStyle, 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)
* `tmsStyle` {Boolean} whether to compute using [tms-style](https://en.wikipedia.org/wiki/Tile_Map_Service). (optional, default false)
* `srs` {String} projection of input bbox (WGS84|900913). (optional, default WGS84)

Returns {Object} XYZ bounds containing minX, maxX, minY, maxY properties.
Expand All @@ -75,6 +76,10 @@ Convert lon, lat values to mercator x, y

Convert mercator x, y values to lon, lat

## See Also
## Developing

* [mercantile](https://github.com/sgillies/mercantile) provides similar utilities for projection and tile math in Python
```sh
npm ci # install
npm test # run tests
npm run format # format files with prettier
```
22 changes: 0 additions & 22 deletions bin/bbox.js

This file was deleted.

19 changes: 0 additions & 19 deletions bin/to4326.js

This file was deleted.

19 changes: 0 additions & 19 deletions bin/to900913.js

This file was deleted.

25 changes: 0 additions & 25 deletions bin/xyz.js

This file was deleted.

Loading

0 comments on commit b60d210

Please sign in to comment.