Skip to content

Commit

Permalink
v0.0.39
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Apr 13, 2024
1 parent d7f66a3 commit 0fc1186
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.0.39
* Added +proj=webmerc

v0.0.38
* Added geos projection

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mproj",
"version": "0.0.38",
"version": "0.0.39",
"description": "A JavaScript port of the Proj.4 cartographic projections library",
"keywords": [
"projections",
Expand Down
22 changes: 21 additions & 1 deletion src/projections/merc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @require pj_phi2, pj_tsfn */


pj_add(pj_merc, 'merc', 'Mercator', 'Cyl, Sph&Ell\nlat_ts=');
pj_add(pj_webmerc, 'webmerc', 'Web Mercator / Pseudo Mercator', 'Cyl, Ell');

function pj_merc(P) {
var EPS10 = 1e-10;
Expand Down Expand Up @@ -55,3 +55,23 @@ function pj_merc(P) {
lp.lam = xy.x / P.k0;
}
}

function pj_webmerc(P) {
P.k0 = 1;
P.inv = s_inv;
P.fwd = s_fwd;

function s_fwd(lp, xy) {
if (fabs(fabs(lp.phi) - M_HALFPI) <= EPS10) {
f_error();
}
xy.x = P.k0 * lp.lam;
xy.y = P.k0 * log(tan(M_FORTPI + 0.5 * lp.phi));
}

function s_inv(xy, lp) {
lp.phi = M_HALFPI - 2 * atan(exp(-xy.y / P.k0));
lp.lam = xy.x / P.k0;
}
}

23 changes: 23 additions & 0 deletions test/projections/webmerc_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

var assert = require('assert'),
api = require('../../'),
helpers = require('../helpers');

describe('+proj=webmerc', function () {
var webmerc = '+proj=webmerc +datum=WGS84';
var merc = '+proj=merc +a=6378137 +b=6378137';

it('test1', function() {
helpers.proj_roundtrip(webmerc, [83, 3]);
});

it('test2', function() {
var p = [-83, -3];
assert.deepEqual(helpers.proj_fwd(webmerc, p), helpers.proj_fwd(merc, p))
});

it('test3', function() {
var p = [-9239517, -334111];
assert.deepEqual(helpers.proj_inv(webmerc, p), helpers.proj_inv(merc, p))
});
});

0 comments on commit 0fc1186

Please sign in to comment.