Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

global-mercator

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

global-mercator - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

3

CHANGELOG.md

@@ -6,3 +6,4 @@

- Convert project to support Rollup (ES6 next modules)
- Convert to ES5
- Convert project to support Rollup
- Add `tileSize` @param

@@ -9,0 +10,0 @@ - Dropped Grid methods (BREAKS backwards compatibility - Major release 2.X)

@@ -7,4 +7,7 @@ (function (global, factory) {

const originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize = 256) { return 2 * Math.PI * 6378137 / tileSize }
var originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize) {
tileSize = tileSize || 256;
return 2 * Math.PI * 6378137 / tileSize
}

@@ -17,7 +20,9 @@ /**

* @example
* const id = hash([312, 480, 4])
* var id = hash([312, 480, 4])
* //=5728
*/
function hash (tile) {
const [x, y, z] = tile;
var x = tile[0];
var y = tile[1];
var z = tile[2];
return (1 << z) * ((1 << z) + x) + y

@@ -32,9 +37,12 @@ }

* @example
* const center = bboxToCenter([90, -45, 85, -50])
* var center = bboxToCenter([90, -45, 85, -50])
* //= [ 87.5, -47.5 ]
*/
function bboxToCenter (bbox) {
const [west, south, east, north] = bbox;
let lng = (west - east) / 2 + east;
let lat = (south - north) / 2 + north;
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var lng = (west - east) / 2 + east;
var lat = (south - north) / 2 + north;
lng = Number(lng.toFixed(6));

@@ -51,9 +59,11 @@ lat = Number(lat.toFixed(6));

* @example
* const meters = lngLatToMeters([126, 37])
* var meters = lngLatToMeters([126, 37])
* //=[ 14026255.8, 4439106.7 ]
*/
function lngLatToMeters (lnglat) {
const [lng, lat] = validateLngLat(lnglat);
let x = lng * originShift / 180.0;
let y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
validateLngLat(lnglat);
var lng = lnglat[0];
var lat = lnglat[1];
var x = lng * originShift / 180.0;
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
y = y * originShift / 180.0;

@@ -71,9 +81,10 @@ x = Number(x.toFixed(1));

* @example
* const lnglat = metersToLngLat([14026255, 4439106])
* var lnglat = metersToLngLat([14026255, 4439106])
* //=[ 126, 37 ]
*/
function metersToLngLat (meters) {
const [x, y] = meters;
let lng = (x / originShift) * 180.0;
let lat = (y / originShift) * 180.0;
var x = meters[0];
var y = meters[1];
var lng = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);

@@ -93,10 +104,11 @@ lng = Number(lng.toFixed(6));

* @example
* const pixels = metersToPixels([14026255, 4439106], 13)
* var pixels = metersToPixels([14026255, 4439106], 13)
* //=[ 1782579.1, 1280877.3, 13 ]
*/
function metersToPixels (meters, zoom, tileSize) {
const [x, y] = meters;
const res = resolution(zoom, tileSize);
const px = (x + originShift) / res;
const py = (y + originShift) / res;
var x = meters[0];
var y = meters[1];
var res = resolution(zoom, tileSize);
var px = (x + originShift) / res;
var py = (y + originShift) / res;
return [px, py, zoom]

@@ -112,8 +124,8 @@ }

* @example
* const tile = lngLatToTile([126, 37], 13)
* var tile = lngLatToTile([126, 37], 13)
* //=[ 6963, 5003, 13 ]
*/
function lngLatToTile (lnglat, zoom) {
const meters = lngLatToMeters(validateLngLat(lnglat));
const pixels = metersToPixels(meters, zoom);
var meters = lngLatToMeters(validateLngLat(lnglat));
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -129,3 +141,3 @@ }

* @example
* const google = lngLatToGoogle([126, 37], 13)
* var google = lngLatToGoogle([126, 37], 13)
* //=[ 6963, 3188, 13 ]

@@ -137,3 +149,3 @@ */

}
const tile = lngLatToTile(validateLngLat(lnglat), zoom);
var tile = lngLatToTile(validateLngLat(lnglat), zoom);
return tileToGoogle(tile)

@@ -149,3 +161,3 @@ }

* @example
* const tile = metersToTile([14026255, 4439106], 13)
* var tile = metersToTile([14026255, 4439106], 13)
* //=[ 6963, 5003, 13 ]

@@ -157,3 +169,3 @@ */

}
const pixels = metersToPixels(meters, zoom);
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -169,10 +181,13 @@ }

* @example
* const meters = pixelsToMeters([1782579, 1280877, 13])
* var meters = pixelsToMeters([1782579, 1280877, 13])
* //=[ 14026252.0, 4439099.5 ]
*/
function pixelsToMeters (pixels, tileSize) {
const [px, py, zoom] = validatePixels(pixels);
const res = resolution(zoom, tileSize);
let mx = px * res - originShift;
let my = py * res - originShift;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
var res = resolution(zoom, tileSize);
var mx = px * res - originShift;
var my = py * res - originShift;
mx = Number(mx.toFixed(1));

@@ -190,12 +205,16 @@ my = Number(my.toFixed(1));

* @example
* const tile = pixelsToTile([1782579, 1280877, 13])
* var tile = pixelsToTile([1782579, 1280877, 13])
* //=[ 6963, 5003, 13 ]
*/
function pixelsToTile (pixels, tileSize = 256) {
const [px, py, zoom] = validatePixels(pixels);
function pixelsToTile (pixels, tileSize) {
tileSize = tileSize || 256;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
if (zoom === 0) {
return [0, 0, 0]
}
let tx = Math.ceil(px / tileSize) - 1;
let ty = Math.ceil(py / tileSize) - 1;
var tx = Math.ceil(px / tileSize) - 1;
var ty = Math.ceil(py / tileSize) - 1;
if (tx < 0) {

@@ -220,9 +239,13 @@ tx = 0;

* @example
* const bbox = tileToBBoxMeters([6963, 5003, 13])
* var bbox = tileToBBoxMeters([6963, 5003, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function tileToBBoxMeters (tile, tileSize = 256) {
const [tx, ty, zoom] = validateTile(tile);
let min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
let max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
function tileToBBoxMeters (tile, tileSize) {
tileSize = tileSize || 256;
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
var min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
var max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -240,13 +263,20 @@ }

* @example
* const bbox = tileToBBox([6963, 5003, 13])
* var bbox = tileToBBox([6963, 5003, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function tileToBBox (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [-180, -85.051129, 180, 85.051129]
}
const [mx1, my1, mx2, my2] = tileToBBoxMeters([tx, ty, zoom]);
const min = metersToLngLat([mx1, my1, zoom]);
const max = metersToLngLat([mx2, my2, zoom]);
var bbox = tileToBBoxMeters([tx, ty, zoom]);
var mx1 = bbox[0];
var my1 = bbox[1];
var mx2 = bbox[2];
var my2 = bbox[3];
var min = metersToLngLat([mx1, my1, zoom]);
var max = metersToLngLat([mx2, my2, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -261,7 +291,7 @@ }

* @example
* const bbox = googleToBBoxMeters([6963, 3188, 13])
* var bbox = googleToBBoxMeters([6963, 3188, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function googleToBBoxMeters (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBoxMeters(Tile)

@@ -276,7 +306,7 @@ }

* @example
* const bbox = googleToBBox([6963, 3188, 13])
* var bbox = googleToBBox([6963, 3188, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function googleToBBox (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBox(Tile)

@@ -291,12 +321,15 @@ }

* @example
* const google = tileToGoogle([6963, 5003, 13])
* var google = tileToGoogle([6963, 5003, 13])
* //=[ 6963, 3188, 13 ]
*/
function tileToGoogle (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [0, 0, 0]
}
const x = tx;
const y = (Math.pow(2, zoom) - 1) - ty;
var x = tx;
var y = (Math.pow(2, zoom) - 1) - ty;
return [x, y, zoom]

@@ -311,9 +344,11 @@ }

* @example
* const tile = googleToTile([6963, 3188, 13])
* var tile = googleToTile([6963, 3188, 13])
* //=[ 6963, 5003, 13 ]
*/
function googleToTile (google) {
const [x, y, zoom] = google;
const tx = x;
const ty = Math.pow(2, zoom) - y - 1;
var x = google[0];
var y = google[1];
var zoom = google[2];
var tx = x;
var ty = Math.pow(2, zoom) - y - 1;
return [tx, ty, zoom]

@@ -328,7 +363,7 @@ }

* @example
* const quadkey = googleToQuadkey([6963, 3188, 13])
* var quadkey = googleToQuadkey([6963, 3188, 13])
* //='1321102330211'
*/
function googleToQuadkey (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToQuadkey(Tile)

@@ -343,7 +378,10 @@ }

* @example
* const quadkey = tileToQuadkey([6963, 5003, 13])
* var quadkey = tileToQuadkey([6963, 5003, 13])
* //='1321102330211'
*/
function tileToQuadkey (tile) {
let [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
// Zoom 0 does not exist for Quadkey

@@ -353,7 +391,7 @@ if (zoom === 0) {

}
let quadkey = '';
var quadkey = '';
ty = (Math.pow(2, zoom) - 1) - ty;
range(zoom, 0, -1).map(i => {
let digit = 0;
let mask = 1 << (i - 1);
range(zoom, 0, -1).map(function (i) {
var digit = 0;
var mask = 1 << (i - 1);
if ((tx & mask) !== 0) {

@@ -376,7 +414,7 @@ digit += 1;

* @example
* const tile = quadkeyToTile('1321102330211')
* var tile = quadkeyToTile('1321102330211')
* //=[ 6963, 5003, 13 ]
*/
function quadkeyToTile (quadkey) {
const Google = quadkeyToGoogle(quadkey);
var Google = quadkeyToGoogle(quadkey);
return googleToTile(Google)

@@ -391,11 +429,11 @@ }

* @example
* const google = quadkeyToGoogle('1321102330211')
* var google = quadkeyToGoogle('1321102330211')
* //=[ 6963, 3188, 13 ]
*/
function quadkeyToGoogle (quadkey) {
let x = 0;
let y = 0;
const zoom = quadkey.length;
range(zoom, 0, -1).map(i => {
let mask = 1 << (i - 1);
var x = 0;
var y = 0;
var zoom = quadkey.length;
range(zoom, 0, -1).map(function (i) {
var mask = 1 << (i - 1);
switch (parseInt(quadkey[zoom - i], 0)) {

@@ -427,8 +465,8 @@ case 0:

* @example
* const meters = bboxToMeters([ 125, 35, 127, 37 ])
* var meters = bboxToMeters([ 125, 35, 127, 37 ])
* //=[ 13914936.3, 4163881.1, 14137575.3, 4439106.7 ]
*/
function bboxToMeters (bbox) {
const min = lngLatToMeters([bbox[0], bbox[1]]);
const max = lngLatToMeters([bbox[2], bbox[3]]);
var min = lngLatToMeters([bbox[0], bbox[1]]);
var max = lngLatToMeters([bbox[2], bbox[3]]);
return [min[0], min[1], max[0], max[1]]

@@ -452,3 +490,5 @@ }

function validateTile (tile) {
const [tx, ty, zoom] = tile;
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
validateZoom(zoom);

@@ -459,3 +499,3 @@ if (tx === undefined || tx === null) { throw new Error('<x> is required') }

if (ty < 0) { throw new Error('<y> must not be less than 0') }
const maxCount = Math.pow(2, zoom);
var maxCount = Math.pow(2, zoom);
if (tx >= maxCount || ty >= maxCount) { throw new Error('Illegal parameters for tile') }

@@ -499,3 +539,4 @@ return tile

function validateLngLat (lnglat) {
const [lng, lat] = lnglat;
var lng = lnglat[0];
var lat = lnglat[1];
if (lat === undefined || lat === null) { throw new Error('<lat> is required') }

@@ -533,3 +574,3 @@ if (lng === undefined || lng === null) { throw new Error('<lng> is required') }

* @example
* const res = resolution(13)
* var res = resolution(13)
* //=19.109257071294063

@@ -565,5 +606,5 @@ */

}
const length = Math.max(Math.ceil((stop - start) / step), 0);
const range = Array(length);
for (let idx = 0; idx < length; idx++, start += step) {
var length = Math.max(Math.ceil((stop - start) / step), 0);
var range = Array(length);
for (var idx = 0; idx < length; idx++, start += step) {
range[idx] = start;

@@ -570,0 +611,0 @@ }

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.globalMercator=t.globalMercator||{})}(this,function(t){"use strict";function e(t=256){return 2*Math.PI*6378137/t}function n(t){const[e,n,o]=t;return(1<<o)*((1<<o)+e)+n}function o(t){const[e,n,o,r]=t;let i=(e-o)/2+o,u=(n-r)/2+r;return i=Number(i.toFixed(6)),u=Number(u.toFixed(6)),[i,u]}function r(t){const[e,n]=L(t);let o=e*q/180,r=Math.log(Math.tan((90+n)*Math.PI/360))/(Math.PI/180);return r=r*q/180,o=Number(o.toFixed(1)),r=Number(r.toFixed(1)),[o,r]}function i(t){const[e,n]=t;let o=e/q*180,r=n/q*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),o=Number(o.toFixed(6)),r=Number(r.toFixed(6)),[o,r]}function u(t,e,n){const[o,r]=t,i=P(e,n),u=(o+q)/i,a=(r+q)/i;return[u,a,e]}function a(t,e){const n=r(L(t)),o=u(n,e);return f(o)}function c(t,e){if(0===e)return[0,0,0];const n=a(L(t),e);return M(n)}function s(t,e){if(0===e)return[0,0,0];const n=u(t,e);return f(n)}function l(t,e){const[n,o,r]=I(t),i=P(r,e);let u=n*i-q,a=o*i-q;return u=Number(u.toFixed(1)),a=Number(a.toFixed(1)),[u,a]}function f(t,e=256){const[n,o,r]=I(t);if(0===r)return[0,0,0];let i=Math.ceil(n/e)-1,u=Math.ceil(o/e)-1;return i<0&&(i=0),u<0&&(u=0),[i,u,r]}function h(t,e=256){const[n,o,r]=y(t);let i=l([n*e,o*e,r]),u=l([(n+1)*e,(o+1)*e,r]);return[i[0],i[1],u[0],u[1]]}function d(t){const[e,n,o]=y(t);if(0===o)return[-180,-85.051129,180,85.051129];const[r,u,a,c]=h([e,n,o]),s=i([r,u,o]),l=i([a,c,o]);return[s[0],s[1],l[0],l[1]]}function w(t){const e=b(t);return h(e)}function g(t){const e=b(t);return d(e)}function M(t){const[e,n,o]=y(t);if(0===o)return[0,0,0];const r=e,i=Math.pow(2,o)-1-n;return[r,i,o]}function b(t){const[e,n,o]=t,r=e,i=Math.pow(2,o)-n-1;return[r,i,o]}function T(t){const e=b(t);return m(e)}function m(t){let[e,n,o]=y(t);if(0===o)return"";let r="";return n=Math.pow(2,o)-1-n,k(o,0,-1).map(t=>{let o=0,i=1<<t-1;0!==(e&i)&&(o+=1),0!==(n&i)&&(o+=2),r=r.concat(o)}),r}function x(t){const e=p(t);return b(e)}function p(t){let e=0,n=0;const o=t.length;return k(o,0,-1).map(r=>{let i=1<<r-1;switch(parseInt(t[o-r],0)){case 0:break;case 1:e+=i;break;case 2:n+=i;break;case 3:e+=i,n+=i;break;default:throw new Error("Invalid Quadkey digit sequence")}}),[e,n,o]}function E(t){const e=r([t[0],t[1]]),n=r([t[2],t[3]]);return[e[0],e[1],n[0],n[1]]}function y(t){const[e,n,o]=t;if(v(o),void 0===e||null===e)throw new Error("<x> is required");if(void 0===n||null===n)throw new Error("<y> is required");if(e<0)throw new Error("<x> must not be less than 0");if(n<0)throw new Error("<y> must not be less than 0");const r=Math.pow(2,o);if(e>=r||n>=r)throw new Error("Illegal parameters for tile");return t}function v(t){if(void 0===t||null===t)throw new Error("<zoom> is required");if(t<0)throw new Error("<zoom> cannot be less than 0");if(t>30)throw new Error("<zoom> cannot be greater than 30");return t}function L(t){const[e,n]=t;if(void 0===n||null===n)throw new Error("<lat> is required");if(void 0===e||null===e)throw new Error("<lng> is required");if(n<-90||n>90)throw new Error("LngLat <lat> must be within -90 to 90 degrees");if(e<-180||e>180)throw new Error("LngLat <lng> must be within -180 to 180 degrees");return[e,n]}function I(t){return t}function P(t,n){return e(n)/Math.pow(2,t)}function k(t,e,n){null==e&&(e=t||0,t=0),n||(n=e<t?-1:1);const o=Math.max(Math.ceil((e-t)/n),0),r=Array(o);for(let i=0;i<o;i++,t+=n)r[i]=t;return r}const q=2*Math.PI*6378137/2;t.hash=n,t.bboxToCenter=o,t.lngLatToMeters=r,t.metersToLngLat=i,t.metersToPixels=u,t.lngLatToTile=a,t.lngLatToGoogle=c,t.metersToTile=s,t.pixelsToMeters=l,t.pixelsToTile=f,t.tileToBBoxMeters=h,t.tileToBBox=d,t.googleToBBoxMeters=w,t.googleToBBox=g,t.tileToGoogle=M,t.googleToTile=b,t.googleToQuadkey=T,t.tileToQuadkey=m,t.quadkeyToTile=x,t.quadkeyToGoogle=p,t.bboxToMeters=E,t.validateTile=y,t.validateZoom=v,t.validateLngLat=L,t.validatePixels=I,t.resolution=P,t.range=k,Object.defineProperty(t,"__esModule",{value:!0})});
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(r.globalMercator=r.globalMercator||{})}(this,function(r){"use strict";function e(r){return r=r||256,2*Math.PI*6378137/r}function t(r){var e=r[0],t=r[1],n=r[2];return(1<<n)*((1<<n)+e)+t}function n(r){var e=r[0],t=r[1],n=r[2],o=r[3],i=(e-n)/2+n,a=(t-o)/2+o;return i=Number(i.toFixed(6)),a=Number(a.toFixed(6)),[i,a]}function o(r){L(r);var e=r[0],t=r[1],n=e*q/180,o=Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180);return o=o*q/180,n=Number(n.toFixed(1)),o=Number(o.toFixed(1)),[n,o]}function i(r){var e=r[0],t=r[1],n=e/q*180,o=t/q*180;return o=180/Math.PI*(2*Math.atan(Math.exp(o*Math.PI/180))-Math.PI/2),n=Number(n.toFixed(6)),o=Number(o.toFixed(6)),[n,o]}function a(r,e,t){var n=r[0],o=r[1],i=P(e,t),a=(n+q)/i,u=(o+q)/i;return[a,u,e]}function u(r,e){var t=o(L(r)),n=a(t,e);return s(n)}function l(r,e){if(0===e)return[0,0,0];var t=u(L(r),e);return g(t)}function f(r,e){if(0===e)return[0,0,0];var t=a(r,e);return s(t)}function c(r,e){I(r);var t=r[0],n=r[1],o=r[2],i=P(o,e),a=t*i-q,u=n*i-q;return a=Number(a.toFixed(1)),u=Number(u.toFixed(1)),[a,u]}function s(r,e){e=e||256,I(r);var t=r[0],n=r[1],o=r[2];if(0===o)return[0,0,0];var i=Math.ceil(t/e)-1,a=Math.ceil(n/e)-1;return i<0&&(i=0),a<0&&(a=0),[i,a,o]}function h(r,e){e=e||256,E(r);var t=r[0],n=r[1],o=r[2],i=c([t*e,n*e,o]),a=c([(t+1)*e,(n+1)*e,o]);return[i[0],i[1],a[0],a[1]]}function v(r){E(r);var e=r[0],t=r[1],n=r[2];if(0===n)return[-180,-85.051129,180,85.051129];var o=h([e,t,n]),a=o[0],u=o[1],l=o[2],f=o[3],c=i([a,u,n]),s=i([l,f,n]);return[c[0],c[1],s[0],s[1]]}function d(r){var e=M(r);return h(e)}function w(r){var e=M(r);return v(e)}function g(r){E(r);var e=r[0],t=r[1],n=r[2];if(0===n)return[0,0,0];var o=e,i=Math.pow(2,n)-1-t;return[o,i,n]}function M(r){var e=r[0],t=r[1],n=r[2],o=e,i=Math.pow(2,n)-t-1;return[o,i,n]}function b(r){var e=M(r);return T(e)}function T(r){E(r);var e=r[0],t=r[1],n=r[2];if(0===n)return"";var o="";return t=Math.pow(2,n)-1-t,k(n,0,-1).map(function(r){var n=0,i=1<<r-1;0!==(e&i)&&(n+=1),0!==(t&i)&&(n+=2),o=o.concat(n)}),o}function m(r){var e=x(r);return M(e)}function x(r){var e=0,t=0,n=r.length;return k(n,0,-1).map(function(o){var i=1<<o-1;switch(parseInt(r[n-o],0)){case 0:break;case 1:e+=i;break;case 2:t+=i;break;case 3:e+=i,t+=i;break;default:throw new Error("Invalid Quadkey digit sequence")}}),[e,t,n]}function p(r){var e=o([r[0],r[1]]),t=o([r[2],r[3]]);return[e[0],e[1],t[0],t[1]]}function E(r){var e=r[0],t=r[1],n=r[2];if(y(n),void 0===e||null===e)throw new Error("<x> is required");if(void 0===t||null===t)throw new Error("<y> is required");if(e<0)throw new Error("<x> must not be less than 0");if(t<0)throw new Error("<y> must not be less than 0");var o=Math.pow(2,n);if(e>=o||t>=o)throw new Error("Illegal parameters for tile");return r}function y(r){if(void 0===r||null===r)throw new Error("<zoom> is required");if(r<0)throw new Error("<zoom> cannot be less than 0");if(r>30)throw new Error("<zoom> cannot be greater than 30");return r}function L(r){var e=r[0],t=r[1];if(void 0===t||null===t)throw new Error("<lat> is required");if(void 0===e||null===e)throw new Error("<lng> is required");if(t<-90||t>90)throw new Error("LngLat <lat> must be within -90 to 90 degrees");if(e<-180||e>180)throw new Error("LngLat <lng> must be within -180 to 180 degrees");return[e,t]}function I(r){return r}function P(r,t){return e(t)/Math.pow(2,r)}function k(r,e,t){null==e&&(e=r||0,r=0),t||(t=e<r?-1:1);for(var n=Math.max(Math.ceil((e-r)/t),0),o=Array(n),i=0;i<n;i++,r+=t)o[i]=r;return o}var q=2*Math.PI*6378137/2;r.hash=t,r.bboxToCenter=n,r.lngLatToMeters=o,r.metersToLngLat=i,r.metersToPixels=a,r.lngLatToTile=u,r.lngLatToGoogle=l,r.metersToTile=f,r.pixelsToMeters=c,r.pixelsToTile=s,r.tileToBBoxMeters=h,r.tileToBBox=v,r.googleToBBoxMeters=d,r.googleToBBox=w,r.tileToGoogle=g,r.googleToTile=M,r.googleToQuadkey=b,r.tileToQuadkey=T,r.quadkeyToTile=m,r.quadkeyToGoogle=x,r.bboxToMeters=p,r.validateTile=E,r.validateZoom=y,r.validateLngLat=L,r.validatePixels=I,r.resolution=P,r.range=k,Object.defineProperty(r,"__esModule",{value:!0})});

@@ -1,3 +0,6 @@

const originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize = 256) { return 2 * Math.PI * 6378137 / tileSize }
var originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize) {
tileSize = tileSize || 256;
return 2 * Math.PI * 6378137 / tileSize
}

@@ -10,7 +13,9 @@ /**

* @example
* const id = hash([312, 480, 4])
* var id = hash([312, 480, 4])
* //=5728
*/
function hash (tile) {
const [x, y, z] = tile;
var x = tile[0];
var y = tile[1];
var z = tile[2];
return (1 << z) * ((1 << z) + x) + y

@@ -25,9 +30,12 @@ }

* @example
* const center = bboxToCenter([90, -45, 85, -50])
* var center = bboxToCenter([90, -45, 85, -50])
* //= [ 87.5, -47.5 ]
*/
function bboxToCenter (bbox) {
const [west, south, east, north] = bbox;
let lng = (west - east) / 2 + east;
let lat = (south - north) / 2 + north;
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var lng = (west - east) / 2 + east;
var lat = (south - north) / 2 + north;
lng = Number(lng.toFixed(6));

@@ -44,9 +52,11 @@ lat = Number(lat.toFixed(6));

* @example
* const meters = lngLatToMeters([126, 37])
* var meters = lngLatToMeters([126, 37])
* //=[ 14026255.8, 4439106.7 ]
*/
function lngLatToMeters (lnglat) {
const [lng, lat] = validateLngLat(lnglat);
let x = lng * originShift / 180.0;
let y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
validateLngLat(lnglat);
var lng = lnglat[0];
var lat = lnglat[1];
var x = lng * originShift / 180.0;
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
y = y * originShift / 180.0;

@@ -64,9 +74,10 @@ x = Number(x.toFixed(1));

* @example
* const lnglat = metersToLngLat([14026255, 4439106])
* var lnglat = metersToLngLat([14026255, 4439106])
* //=[ 126, 37 ]
*/
function metersToLngLat (meters) {
const [x, y] = meters;
let lng = (x / originShift) * 180.0;
let lat = (y / originShift) * 180.0;
var x = meters[0];
var y = meters[1];
var lng = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);

@@ -86,10 +97,11 @@ lng = Number(lng.toFixed(6));

* @example
* const pixels = metersToPixels([14026255, 4439106], 13)
* var pixels = metersToPixels([14026255, 4439106], 13)
* //=[ 1782579.1, 1280877.3, 13 ]
*/
function metersToPixels (meters, zoom, tileSize) {
const [x, y] = meters;
const res = resolution(zoom, tileSize);
const px = (x + originShift) / res;
const py = (y + originShift) / res;
var x = meters[0];
var y = meters[1];
var res = resolution(zoom, tileSize);
var px = (x + originShift) / res;
var py = (y + originShift) / res;
return [px, py, zoom]

@@ -105,8 +117,8 @@ }

* @example
* const tile = lngLatToTile([126, 37], 13)
* var tile = lngLatToTile([126, 37], 13)
* //=[ 6963, 5003, 13 ]
*/
function lngLatToTile (lnglat, zoom) {
const meters = lngLatToMeters(validateLngLat(lnglat));
const pixels = metersToPixels(meters, zoom);
var meters = lngLatToMeters(validateLngLat(lnglat));
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -122,3 +134,3 @@ }

* @example
* const google = lngLatToGoogle([126, 37], 13)
* var google = lngLatToGoogle([126, 37], 13)
* //=[ 6963, 3188, 13 ]

@@ -130,3 +142,3 @@ */

}
const tile = lngLatToTile(validateLngLat(lnglat), zoom);
var tile = lngLatToTile(validateLngLat(lnglat), zoom);
return tileToGoogle(tile)

@@ -142,3 +154,3 @@ }

* @example
* const tile = metersToTile([14026255, 4439106], 13)
* var tile = metersToTile([14026255, 4439106], 13)
* //=[ 6963, 5003, 13 ]

@@ -150,3 +162,3 @@ */

}
const pixels = metersToPixels(meters, zoom);
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -162,10 +174,13 @@ }

* @example
* const meters = pixelsToMeters([1782579, 1280877, 13])
* var meters = pixelsToMeters([1782579, 1280877, 13])
* //=[ 14026252.0, 4439099.5 ]
*/
function pixelsToMeters (pixels, tileSize) {
const [px, py, zoom] = validatePixels(pixels);
const res = resolution(zoom, tileSize);
let mx = px * res - originShift;
let my = py * res - originShift;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
var res = resolution(zoom, tileSize);
var mx = px * res - originShift;
var my = py * res - originShift;
mx = Number(mx.toFixed(1));

@@ -183,12 +198,16 @@ my = Number(my.toFixed(1));

* @example
* const tile = pixelsToTile([1782579, 1280877, 13])
* var tile = pixelsToTile([1782579, 1280877, 13])
* //=[ 6963, 5003, 13 ]
*/
function pixelsToTile (pixels, tileSize = 256) {
const [px, py, zoom] = validatePixels(pixels);
function pixelsToTile (pixels, tileSize) {
tileSize = tileSize || 256;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
if (zoom === 0) {
return [0, 0, 0]
}
let tx = Math.ceil(px / tileSize) - 1;
let ty = Math.ceil(py / tileSize) - 1;
var tx = Math.ceil(px / tileSize) - 1;
var ty = Math.ceil(py / tileSize) - 1;
if (tx < 0) {

@@ -213,9 +232,13 @@ tx = 0;

* @example
* const bbox = tileToBBoxMeters([6963, 5003, 13])
* var bbox = tileToBBoxMeters([6963, 5003, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function tileToBBoxMeters (tile, tileSize = 256) {
const [tx, ty, zoom] = validateTile(tile);
let min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
let max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
function tileToBBoxMeters (tile, tileSize) {
tileSize = tileSize || 256;
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
var min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
var max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -233,13 +256,20 @@ }

* @example
* const bbox = tileToBBox([6963, 5003, 13])
* var bbox = tileToBBox([6963, 5003, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function tileToBBox (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [-180, -85.051129, 180, 85.051129]
}
const [mx1, my1, mx2, my2] = tileToBBoxMeters([tx, ty, zoom]);
const min = metersToLngLat([mx1, my1, zoom]);
const max = metersToLngLat([mx2, my2, zoom]);
var bbox = tileToBBoxMeters([tx, ty, zoom]);
var mx1 = bbox[0];
var my1 = bbox[1];
var mx2 = bbox[2];
var my2 = bbox[3];
var min = metersToLngLat([mx1, my1, zoom]);
var max = metersToLngLat([mx2, my2, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -254,7 +284,7 @@ }

* @example
* const bbox = googleToBBoxMeters([6963, 3188, 13])
* var bbox = googleToBBoxMeters([6963, 3188, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function googleToBBoxMeters (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBoxMeters(Tile)

@@ -269,7 +299,7 @@ }

* @example
* const bbox = googleToBBox([6963, 3188, 13])
* var bbox = googleToBBox([6963, 3188, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function googleToBBox (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBox(Tile)

@@ -284,12 +314,15 @@ }

* @example
* const google = tileToGoogle([6963, 5003, 13])
* var google = tileToGoogle([6963, 5003, 13])
* //=[ 6963, 3188, 13 ]
*/
function tileToGoogle (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [0, 0, 0]
}
const x = tx;
const y = (Math.pow(2, zoom) - 1) - ty;
var x = tx;
var y = (Math.pow(2, zoom) - 1) - ty;
return [x, y, zoom]

@@ -304,9 +337,11 @@ }

* @example
* const tile = googleToTile([6963, 3188, 13])
* var tile = googleToTile([6963, 3188, 13])
* //=[ 6963, 5003, 13 ]
*/
function googleToTile (google) {
const [x, y, zoom] = google;
const tx = x;
const ty = Math.pow(2, zoom) - y - 1;
var x = google[0];
var y = google[1];
var zoom = google[2];
var tx = x;
var ty = Math.pow(2, zoom) - y - 1;
return [tx, ty, zoom]

@@ -321,7 +356,7 @@ }

* @example
* const quadkey = googleToQuadkey([6963, 3188, 13])
* var quadkey = googleToQuadkey([6963, 3188, 13])
* //='1321102330211'
*/
function googleToQuadkey (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToQuadkey(Tile)

@@ -336,7 +371,10 @@ }

* @example
* const quadkey = tileToQuadkey([6963, 5003, 13])
* var quadkey = tileToQuadkey([6963, 5003, 13])
* //='1321102330211'
*/
function tileToQuadkey (tile) {
let [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
// Zoom 0 does not exist for Quadkey

@@ -346,7 +384,7 @@ if (zoom === 0) {

}
let quadkey = '';
var quadkey = '';
ty = (Math.pow(2, zoom) - 1) - ty;
range(zoom, 0, -1).map(i => {
let digit = 0;
let mask = 1 << (i - 1);
range(zoom, 0, -1).map(function (i) {
var digit = 0;
var mask = 1 << (i - 1);
if ((tx & mask) !== 0) {

@@ -369,7 +407,7 @@ digit += 1;

* @example
* const tile = quadkeyToTile('1321102330211')
* var tile = quadkeyToTile('1321102330211')
* //=[ 6963, 5003, 13 ]
*/
function quadkeyToTile (quadkey) {
const Google = quadkeyToGoogle(quadkey);
var Google = quadkeyToGoogle(quadkey);
return googleToTile(Google)

@@ -384,11 +422,11 @@ }

* @example
* const google = quadkeyToGoogle('1321102330211')
* var google = quadkeyToGoogle('1321102330211')
* //=[ 6963, 3188, 13 ]
*/
function quadkeyToGoogle (quadkey) {
let x = 0;
let y = 0;
const zoom = quadkey.length;
range(zoom, 0, -1).map(i => {
let mask = 1 << (i - 1);
var x = 0;
var y = 0;
var zoom = quadkey.length;
range(zoom, 0, -1).map(function (i) {
var mask = 1 << (i - 1);
switch (parseInt(quadkey[zoom - i], 0)) {

@@ -420,8 +458,8 @@ case 0:

* @example
* const meters = bboxToMeters([ 125, 35, 127, 37 ])
* var meters = bboxToMeters([ 125, 35, 127, 37 ])
* //=[ 13914936.3, 4163881.1, 14137575.3, 4439106.7 ]
*/
function bboxToMeters (bbox) {
const min = lngLatToMeters([bbox[0], bbox[1]]);
const max = lngLatToMeters([bbox[2], bbox[3]]);
var min = lngLatToMeters([bbox[0], bbox[1]]);
var max = lngLatToMeters([bbox[2], bbox[3]]);
return [min[0], min[1], max[0], max[1]]

@@ -445,3 +483,5 @@ }

function validateTile (tile) {
const [tx, ty, zoom] = tile;
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
validateZoom(zoom);

@@ -452,3 +492,3 @@ if (tx === undefined || tx === null) { throw new Error('<x> is required') }

if (ty < 0) { throw new Error('<y> must not be less than 0') }
const maxCount = Math.pow(2, zoom);
var maxCount = Math.pow(2, zoom);
if (tx >= maxCount || ty >= maxCount) { throw new Error('Illegal parameters for tile') }

@@ -492,3 +532,4 @@ return tile

function validateLngLat (lnglat) {
const [lng, lat] = lnglat;
var lng = lnglat[0];
var lat = lnglat[1];
if (lat === undefined || lat === null) { throw new Error('<lat> is required') }

@@ -526,3 +567,3 @@ if (lng === undefined || lng === null) { throw new Error('<lng> is required') }

* @example
* const res = resolution(13)
* var res = resolution(13)
* //=19.109257071294063

@@ -558,5 +599,5 @@ */

}
const length = Math.max(Math.ceil((stop - start) / step), 0);
const range = Array(length);
for (let idx = 0; idx < length; idx++, start += step) {
var length = Math.max(Math.ceil((stop - start) / step), 0);
var range = Array(length);
for (var idx = 0; idx < length; idx++, start += step) {
range[idx] = start;

@@ -563,0 +604,0 @@ }

@@ -5,4 +5,7 @@ 'use strict';

const originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize = 256) { return 2 * Math.PI * 6378137 / tileSize }
var originShift = 2 * Math.PI * 6378137 / 2.0;
function initialResolution (tileSize) {
tileSize = tileSize || 256;
return 2 * Math.PI * 6378137 / tileSize
}

@@ -15,7 +18,9 @@ /**

* @example
* const id = hash([312, 480, 4])
* var id = hash([312, 480, 4])
* //=5728
*/
function hash (tile) {
const [x, y, z] = tile;
var x = tile[0];
var y = tile[1];
var z = tile[2];
return (1 << z) * ((1 << z) + x) + y

@@ -30,9 +35,12 @@ }

* @example
* const center = bboxToCenter([90, -45, 85, -50])
* var center = bboxToCenter([90, -45, 85, -50])
* //= [ 87.5, -47.5 ]
*/
function bboxToCenter (bbox) {
const [west, south, east, north] = bbox;
let lng = (west - east) / 2 + east;
let lat = (south - north) / 2 + north;
var west = bbox[0];
var south = bbox[1];
var east = bbox[2];
var north = bbox[3];
var lng = (west - east) / 2 + east;
var lat = (south - north) / 2 + north;
lng = Number(lng.toFixed(6));

@@ -49,9 +57,11 @@ lat = Number(lat.toFixed(6));

* @example
* const meters = lngLatToMeters([126, 37])
* var meters = lngLatToMeters([126, 37])
* //=[ 14026255.8, 4439106.7 ]
*/
function lngLatToMeters (lnglat) {
const [lng, lat] = validateLngLat(lnglat);
let x = lng * originShift / 180.0;
let y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
validateLngLat(lnglat);
var lng = lnglat[0];
var lat = lnglat[1];
var x = lng * originShift / 180.0;
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
y = y * originShift / 180.0;

@@ -69,9 +79,10 @@ x = Number(x.toFixed(1));

* @example
* const lnglat = metersToLngLat([14026255, 4439106])
* var lnglat = metersToLngLat([14026255, 4439106])
* //=[ 126, 37 ]
*/
function metersToLngLat (meters) {
const [x, y] = meters;
let lng = (x / originShift) * 180.0;
let lat = (y / originShift) * 180.0;
var x = meters[0];
var y = meters[1];
var lng = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);

@@ -91,10 +102,11 @@ lng = Number(lng.toFixed(6));

* @example
* const pixels = metersToPixels([14026255, 4439106], 13)
* var pixels = metersToPixels([14026255, 4439106], 13)
* //=[ 1782579.1, 1280877.3, 13 ]
*/
function metersToPixels (meters, zoom, tileSize) {
const [x, y] = meters;
const res = resolution(zoom, tileSize);
const px = (x + originShift) / res;
const py = (y + originShift) / res;
var x = meters[0];
var y = meters[1];
var res = resolution(zoom, tileSize);
var px = (x + originShift) / res;
var py = (y + originShift) / res;
return [px, py, zoom]

@@ -110,8 +122,8 @@ }

* @example
* const tile = lngLatToTile([126, 37], 13)
* var tile = lngLatToTile([126, 37], 13)
* //=[ 6963, 5003, 13 ]
*/
function lngLatToTile (lnglat, zoom) {
const meters = lngLatToMeters(validateLngLat(lnglat));
const pixels = metersToPixels(meters, zoom);
var meters = lngLatToMeters(validateLngLat(lnglat));
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -127,3 +139,3 @@ }

* @example
* const google = lngLatToGoogle([126, 37], 13)
* var google = lngLatToGoogle([126, 37], 13)
* //=[ 6963, 3188, 13 ]

@@ -135,3 +147,3 @@ */

}
const tile = lngLatToTile(validateLngLat(lnglat), zoom);
var tile = lngLatToTile(validateLngLat(lnglat), zoom);
return tileToGoogle(tile)

@@ -147,3 +159,3 @@ }

* @example
* const tile = metersToTile([14026255, 4439106], 13)
* var tile = metersToTile([14026255, 4439106], 13)
* //=[ 6963, 5003, 13 ]

@@ -155,3 +167,3 @@ */

}
const pixels = metersToPixels(meters, zoom);
var pixels = metersToPixels(meters, zoom);
return pixelsToTile(pixels)

@@ -167,10 +179,13 @@ }

* @example
* const meters = pixelsToMeters([1782579, 1280877, 13])
* var meters = pixelsToMeters([1782579, 1280877, 13])
* //=[ 14026252.0, 4439099.5 ]
*/
function pixelsToMeters (pixels, tileSize) {
const [px, py, zoom] = validatePixels(pixels);
const res = resolution(zoom, tileSize);
let mx = px * res - originShift;
let my = py * res - originShift;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
var res = resolution(zoom, tileSize);
var mx = px * res - originShift;
var my = py * res - originShift;
mx = Number(mx.toFixed(1));

@@ -188,12 +203,16 @@ my = Number(my.toFixed(1));

* @example
* const tile = pixelsToTile([1782579, 1280877, 13])
* var tile = pixelsToTile([1782579, 1280877, 13])
* //=[ 6963, 5003, 13 ]
*/
function pixelsToTile (pixels, tileSize = 256) {
const [px, py, zoom] = validatePixels(pixels);
function pixelsToTile (pixels, tileSize) {
tileSize = tileSize || 256;
validatePixels(pixels);
var px = pixels[0];
var py = pixels[1];
var zoom = pixels[2];
if (zoom === 0) {
return [0, 0, 0]
}
let tx = Math.ceil(px / tileSize) - 1;
let ty = Math.ceil(py / tileSize) - 1;
var tx = Math.ceil(px / tileSize) - 1;
var ty = Math.ceil(py / tileSize) - 1;
if (tx < 0) {

@@ -218,9 +237,13 @@ tx = 0;

* @example
* const bbox = tileToBBoxMeters([6963, 5003, 13])
* var bbox = tileToBBoxMeters([6963, 5003, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function tileToBBoxMeters (tile, tileSize = 256) {
const [tx, ty, zoom] = validateTile(tile);
let min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
let max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
function tileToBBoxMeters (tile, tileSize) {
tileSize = tileSize || 256;
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
var min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom]);
var max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -238,13 +261,20 @@ }

* @example
* const bbox = tileToBBox([6963, 5003, 13])
* var bbox = tileToBBox([6963, 5003, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function tileToBBox (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [-180, -85.051129, 180, 85.051129]
}
const [mx1, my1, mx2, my2] = tileToBBoxMeters([tx, ty, zoom]);
const min = metersToLngLat([mx1, my1, zoom]);
const max = metersToLngLat([mx2, my2, zoom]);
var bbox = tileToBBoxMeters([tx, ty, zoom]);
var mx1 = bbox[0];
var my1 = bbox[1];
var mx2 = bbox[2];
var my2 = bbox[3];
var min = metersToLngLat([mx1, my1, zoom]);
var max = metersToLngLat([mx2, my2, zoom]);
return [min[0], min[1], max[0], max[1]]

@@ -259,7 +289,7 @@ }

* @example
* const bbox = googleToBBoxMeters([6963, 3188, 13])
* var bbox = googleToBBoxMeters([6963, 3188, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
function googleToBBoxMeters (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBoxMeters(Tile)

@@ -274,7 +304,7 @@ }

* @example
* const bbox = googleToBBox([6963, 3188, 13])
* var bbox = googleToBBox([6963, 3188, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
function googleToBBox (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToBBox(Tile)

@@ -289,12 +319,15 @@ }

* @example
* const google = tileToGoogle([6963, 5003, 13])
* var google = tileToGoogle([6963, 5003, 13])
* //=[ 6963, 3188, 13 ]
*/
function tileToGoogle (tile) {
const [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
if (zoom === 0) {
return [0, 0, 0]
}
const x = tx;
const y = (Math.pow(2, zoom) - 1) - ty;
var x = tx;
var y = (Math.pow(2, zoom) - 1) - ty;
return [x, y, zoom]

@@ -309,9 +342,11 @@ }

* @example
* const tile = googleToTile([6963, 3188, 13])
* var tile = googleToTile([6963, 3188, 13])
* //=[ 6963, 5003, 13 ]
*/
function googleToTile (google) {
const [x, y, zoom] = google;
const tx = x;
const ty = Math.pow(2, zoom) - y - 1;
var x = google[0];
var y = google[1];
var zoom = google[2];
var tx = x;
var ty = Math.pow(2, zoom) - y - 1;
return [tx, ty, zoom]

@@ -326,7 +361,7 @@ }

* @example
* const quadkey = googleToQuadkey([6963, 3188, 13])
* var quadkey = googleToQuadkey([6963, 3188, 13])
* //='1321102330211'
*/
function googleToQuadkey (google) {
const Tile = googleToTile(google);
var Tile = googleToTile(google);
return tileToQuadkey(Tile)

@@ -341,7 +376,10 @@ }

* @example
* const quadkey = tileToQuadkey([6963, 5003, 13])
* var quadkey = tileToQuadkey([6963, 5003, 13])
* //='1321102330211'
*/
function tileToQuadkey (tile) {
let [tx, ty, zoom] = validateTile(tile);
validateTile(tile);
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
// Zoom 0 does not exist for Quadkey

@@ -351,7 +389,7 @@ if (zoom === 0) {

}
let quadkey = '';
var quadkey = '';
ty = (Math.pow(2, zoom) - 1) - ty;
range(zoom, 0, -1).map(i => {
let digit = 0;
let mask = 1 << (i - 1);
range(zoom, 0, -1).map(function (i) {
var digit = 0;
var mask = 1 << (i - 1);
if ((tx & mask) !== 0) {

@@ -374,7 +412,7 @@ digit += 1;

* @example
* const tile = quadkeyToTile('1321102330211')
* var tile = quadkeyToTile('1321102330211')
* //=[ 6963, 5003, 13 ]
*/
function quadkeyToTile (quadkey) {
const Google = quadkeyToGoogle(quadkey);
var Google = quadkeyToGoogle(quadkey);
return googleToTile(Google)

@@ -389,11 +427,11 @@ }

* @example
* const google = quadkeyToGoogle('1321102330211')
* var google = quadkeyToGoogle('1321102330211')
* //=[ 6963, 3188, 13 ]
*/
function quadkeyToGoogle (quadkey) {
let x = 0;
let y = 0;
const zoom = quadkey.length;
range(zoom, 0, -1).map(i => {
let mask = 1 << (i - 1);
var x = 0;
var y = 0;
var zoom = quadkey.length;
range(zoom, 0, -1).map(function (i) {
var mask = 1 << (i - 1);
switch (parseInt(quadkey[zoom - i], 0)) {

@@ -425,8 +463,8 @@ case 0:

* @example
* const meters = bboxToMeters([ 125, 35, 127, 37 ])
* var meters = bboxToMeters([ 125, 35, 127, 37 ])
* //=[ 13914936.3, 4163881.1, 14137575.3, 4439106.7 ]
*/
function bboxToMeters (bbox) {
const min = lngLatToMeters([bbox[0], bbox[1]]);
const max = lngLatToMeters([bbox[2], bbox[3]]);
var min = lngLatToMeters([bbox[0], bbox[1]]);
var max = lngLatToMeters([bbox[2], bbox[3]]);
return [min[0], min[1], max[0], max[1]]

@@ -450,3 +488,5 @@ }

function validateTile (tile) {
const [tx, ty, zoom] = tile;
var tx = tile[0];
var ty = tile[1];
var zoom = tile[2];
validateZoom(zoom);

@@ -457,3 +497,3 @@ if (tx === undefined || tx === null) { throw new Error('<x> is required') }

if (ty < 0) { throw new Error('<y> must not be less than 0') }
const maxCount = Math.pow(2, zoom);
var maxCount = Math.pow(2, zoom);
if (tx >= maxCount || ty >= maxCount) { throw new Error('Illegal parameters for tile') }

@@ -497,3 +537,4 @@ return tile

function validateLngLat (lnglat) {
const [lng, lat] = lnglat;
var lng = lnglat[0];
var lat = lnglat[1];
if (lat === undefined || lat === null) { throw new Error('<lat> is required') }

@@ -531,3 +572,3 @@ if (lng === undefined || lng === null) { throw new Error('<lng> is required') }

* @example
* const res = resolution(13)
* var res = resolution(13)
* //=19.109257071294063

@@ -563,5 +604,5 @@ */

}
const length = Math.max(Math.ceil((stop - start) / step), 0);
const range = Array(length);
for (let idx = 0; idx < length; idx++, start += step) {
var length = Math.max(Math.ceil((stop - start) / step), 0);
var range = Array(length);
for (var idx = 0; idx < length; idx++, start += step) {
range[idx] = start;

@@ -568,0 +609,0 @@ }

@@ -1,3 +0,6 @@

const originShift = 2 * Math.PI * 6378137 / 2.0
function initialResolution (tileSize = 256) { return 2 * Math.PI * 6378137 / tileSize }
var originShift = 2 * Math.PI * 6378137 / 2.0
function initialResolution (tileSize) {
tileSize = tileSize || 256
return 2 * Math.PI * 6378137 / tileSize
}

@@ -10,7 +13,9 @@ /**

* @example
* const id = hash([312, 480, 4])
* var id = hash([312, 480, 4])
* //=5728
*/
export function hash (tile) {
const [x, y, z] = tile
var x = tile[0]
var y = tile[1]
var z = tile[2]
return (1 << z) * ((1 << z) + x) + y

@@ -25,9 +30,12 @@ }

* @example
* const center = bboxToCenter([90, -45, 85, -50])
* var center = bboxToCenter([90, -45, 85, -50])
* //= [ 87.5, -47.5 ]
*/
export function bboxToCenter (bbox) {
const [west, south, east, north] = bbox
let lng = (west - east) / 2 + east
let lat = (south - north) / 2 + north
var west = bbox[0]
var south = bbox[1]
var east = bbox[2]
var north = bbox[3]
var lng = (west - east) / 2 + east
var lat = (south - north) / 2 + north
lng = Number(lng.toFixed(6))

@@ -44,9 +52,11 @@ lat = Number(lat.toFixed(6))

* @example
* const meters = lngLatToMeters([126, 37])
* var meters = lngLatToMeters([126, 37])
* //=[ 14026255.8, 4439106.7 ]
*/
export function lngLatToMeters (lnglat) {
const [lng, lat] = validateLngLat(lnglat)
let x = lng * originShift / 180.0
let y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0)
validateLngLat(lnglat)
var lng = lnglat[0]
var lat = lnglat[1]
var x = lng * originShift / 180.0
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0)
y = y * originShift / 180.0

@@ -64,9 +74,10 @@ x = Number(x.toFixed(1))

* @example
* const lnglat = metersToLngLat([14026255, 4439106])
* var lnglat = metersToLngLat([14026255, 4439106])
* //=[ 126, 37 ]
*/
export function metersToLngLat (meters) {
const [x, y] = meters
let lng = (x / originShift) * 180.0
let lat = (y / originShift) * 180.0
var x = meters[0]
var y = meters[1]
var lng = (x / originShift) * 180.0
var lat = (y / originShift) * 180.0
lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0)

@@ -86,10 +97,11 @@ lng = Number(lng.toFixed(6))

* @example
* const pixels = metersToPixels([14026255, 4439106], 13)
* var pixels = metersToPixels([14026255, 4439106], 13)
* //=[ 1782579.1, 1280877.3, 13 ]
*/
export function metersToPixels (meters, zoom, tileSize) {
const [x, y] = meters
const res = resolution(zoom, tileSize)
const px = (x + originShift) / res
const py = (y + originShift) / res
var x = meters[0]
var y = meters[1]
var res = resolution(zoom, tileSize)
var px = (x + originShift) / res
var py = (y + originShift) / res
return [px, py, zoom]

@@ -105,8 +117,8 @@ }

* @example
* const tile = lngLatToTile([126, 37], 13)
* var tile = lngLatToTile([126, 37], 13)
* //=[ 6963, 5003, 13 ]
*/
export function lngLatToTile (lnglat, zoom) {
const meters = lngLatToMeters(validateLngLat(lnglat))
const pixels = metersToPixels(meters, zoom)
var meters = lngLatToMeters(validateLngLat(lnglat))
var pixels = metersToPixels(meters, zoom)
return pixelsToTile(pixels)

@@ -122,3 +134,3 @@ }

* @example
* const google = lngLatToGoogle([126, 37], 13)
* var google = lngLatToGoogle([126, 37], 13)
* //=[ 6963, 3188, 13 ]

@@ -130,3 +142,3 @@ */

}
const tile = lngLatToTile(validateLngLat(lnglat), zoom)
var tile = lngLatToTile(validateLngLat(lnglat), zoom)
return tileToGoogle(tile)

@@ -142,3 +154,3 @@ }

* @example
* const tile = metersToTile([14026255, 4439106], 13)
* var tile = metersToTile([14026255, 4439106], 13)
* //=[ 6963, 5003, 13 ]

@@ -150,3 +162,3 @@ */

}
const pixels = metersToPixels(meters, zoom)
var pixels = metersToPixels(meters, zoom)
return pixelsToTile(pixels)

@@ -162,10 +174,13 @@ }

* @example
* const meters = pixelsToMeters([1782579, 1280877, 13])
* var meters = pixelsToMeters([1782579, 1280877, 13])
* //=[ 14026252.0, 4439099.5 ]
*/
export function pixelsToMeters (pixels, tileSize) {
const [px, py, zoom] = validatePixels(pixels)
const res = resolution(zoom, tileSize)
let mx = px * res - originShift
let my = py * res - originShift
validatePixels(pixels)
var px = pixels[0]
var py = pixels[1]
var zoom = pixels[2]
var res = resolution(zoom, tileSize)
var mx = px * res - originShift
var my = py * res - originShift
mx = Number(mx.toFixed(1))

@@ -183,12 +198,16 @@ my = Number(my.toFixed(1))

* @example
* const tile = pixelsToTile([1782579, 1280877, 13])
* var tile = pixelsToTile([1782579, 1280877, 13])
* //=[ 6963, 5003, 13 ]
*/
export function pixelsToTile (pixels, tileSize = 256) {
const [px, py, zoom] = validatePixels(pixels)
export function pixelsToTile (pixels, tileSize) {
tileSize = tileSize || 256
validatePixels(pixels)
var px = pixels[0]
var py = pixels[1]
var zoom = pixels[2]
if (zoom === 0) {
return [0, 0, 0]
}
let tx = Math.ceil(px / tileSize) - 1
let ty = Math.ceil(py / tileSize) - 1
var tx = Math.ceil(px / tileSize) - 1
var ty = Math.ceil(py / tileSize) - 1
if (tx < 0) {

@@ -213,9 +232,13 @@ tx = 0

* @example
* const bbox = tileToBBoxMeters([6963, 5003, 13])
* var bbox = tileToBBoxMeters([6963, 5003, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
export function tileToBBoxMeters (tile, tileSize = 256) {
const [tx, ty, zoom] = validateTile(tile)
let min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom])
let max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom])
export function tileToBBoxMeters (tile, tileSize) {
tileSize = tileSize || 256
validateTile(tile)
var tx = tile[0]
var ty = tile[1]
var zoom = tile[2]
var min = pixelsToMeters([tx * tileSize, ty * tileSize, zoom])
var max = pixelsToMeters([(tx + 1) * tileSize, (ty + 1) * tileSize, zoom])
return [min[0], min[1], max[0], max[1]]

@@ -233,13 +256,20 @@ }

* @example
* const bbox = tileToBBox([6963, 5003, 13])
* var bbox = tileToBBox([6963, 5003, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
export function tileToBBox (tile) {
const [tx, ty, zoom] = validateTile(tile)
validateTile(tile)
var tx = tile[0]
var ty = tile[1]
var zoom = tile[2]
if (zoom === 0) {
return [-180, -85.051129, 180, 85.051129]
}
const [mx1, my1, mx2, my2] = tileToBBoxMeters([tx, ty, zoom])
const min = metersToLngLat([mx1, my1, zoom])
const max = metersToLngLat([mx2, my2, zoom])
var bbox = tileToBBoxMeters([tx, ty, zoom])
var mx1 = bbox[0]
var my1 = bbox[1]
var mx2 = bbox[2]
var my2 = bbox[3]
var min = metersToLngLat([mx1, my1, zoom])
var max = metersToLngLat([mx2, my2, zoom])
return [min[0], min[1], max[0], max[1]]

@@ -254,7 +284,7 @@ }

* @example
* const bbox = googleToBBoxMeters([6963, 3188, 13])
* var bbox = googleToBBoxMeters([6963, 3188, 13])
* //=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
*/
export function googleToBBoxMeters (google) {
const Tile = googleToTile(google)
var Tile = googleToTile(google)
return tileToBBoxMeters(Tile)

@@ -269,7 +299,7 @@ }

* @example
* const bbox = googleToBBox([6963, 3188, 13])
* var bbox = googleToBBox([6963, 3188, 13])
* //=[ 125.991, 36.985, 126.035, 37.020 ]
*/
export function googleToBBox (google) {
const Tile = googleToTile(google)
var Tile = googleToTile(google)
return tileToBBox(Tile)

@@ -284,12 +314,15 @@ }

* @example
* const google = tileToGoogle([6963, 5003, 13])
* var google = tileToGoogle([6963, 5003, 13])
* //=[ 6963, 3188, 13 ]
*/
export function tileToGoogle (tile) {
const [tx, ty, zoom] = validateTile(tile)
validateTile(tile)
var tx = tile[0]
var ty = tile[1]
var zoom = tile[2]
if (zoom === 0) {
return [0, 0, 0]
}
const x = tx
const y = (Math.pow(2, zoom) - 1) - ty
var x = tx
var y = (Math.pow(2, zoom) - 1) - ty
return [x, y, zoom]

@@ -304,9 +337,11 @@ }

* @example
* const tile = googleToTile([6963, 3188, 13])
* var tile = googleToTile([6963, 3188, 13])
* //=[ 6963, 5003, 13 ]
*/
export function googleToTile (google) {
const [x, y, zoom] = google
const tx = x
const ty = Math.pow(2, zoom) - y - 1
var x = google[0]
var y = google[1]
var zoom = google[2]
var tx = x
var ty = Math.pow(2, zoom) - y - 1
return [tx, ty, zoom]

@@ -321,7 +356,7 @@ }

* @example
* const quadkey = googleToQuadkey([6963, 3188, 13])
* var quadkey = googleToQuadkey([6963, 3188, 13])
* //='1321102330211'
*/
export function googleToQuadkey (google) {
const Tile = googleToTile(google)
var Tile = googleToTile(google)
return tileToQuadkey(Tile)

@@ -336,7 +371,10 @@ }

* @example
* const quadkey = tileToQuadkey([6963, 5003, 13])
* var quadkey = tileToQuadkey([6963, 5003, 13])
* //='1321102330211'
*/
export function tileToQuadkey (tile) {
let [tx, ty, zoom] = validateTile(tile)
validateTile(tile)
var tx = tile[0]
var ty = tile[1]
var zoom = tile[2]
// Zoom 0 does not exist for Quadkey

@@ -346,7 +384,7 @@ if (zoom === 0) {

}
let quadkey = ''
var quadkey = ''
ty = (Math.pow(2, zoom) - 1) - ty
range(zoom, 0, -1).map(i => {
let digit = 0
let mask = 1 << (i - 1)
range(zoom, 0, -1).map(function (i) {
var digit = 0
var mask = 1 << (i - 1)
if ((tx & mask) !== 0) {

@@ -369,7 +407,7 @@ digit += 1

* @example
* const tile = quadkeyToTile('1321102330211')
* var tile = quadkeyToTile('1321102330211')
* //=[ 6963, 5003, 13 ]
*/
export function quadkeyToTile (quadkey) {
const Google = quadkeyToGoogle(quadkey)
var Google = quadkeyToGoogle(quadkey)
return googleToTile(Google)

@@ -384,11 +422,11 @@ }

* @example
* const google = quadkeyToGoogle('1321102330211')
* var google = quadkeyToGoogle('1321102330211')
* //=[ 6963, 3188, 13 ]
*/
export function quadkeyToGoogle (quadkey) {
let x = 0
let y = 0
const zoom = quadkey.length
range(zoom, 0, -1).map(i => {
let mask = 1 << (i - 1)
var x = 0
var y = 0
var zoom = quadkey.length
range(zoom, 0, -1).map(function (i) {
var mask = 1 << (i - 1)
switch (parseInt(quadkey[zoom - i], 0)) {

@@ -420,8 +458,8 @@ case 0:

* @example
* const meters = bboxToMeters([ 125, 35, 127, 37 ])
* var meters = bboxToMeters([ 125, 35, 127, 37 ])
* //=[ 13914936.3, 4163881.1, 14137575.3, 4439106.7 ]
*/
export function bboxToMeters (bbox) {
const min = lngLatToMeters([bbox[0], bbox[1]])
const max = lngLatToMeters([bbox[2], bbox[3]])
var min = lngLatToMeters([bbox[0], bbox[1]])
var max = lngLatToMeters([bbox[2], bbox[3]])
return [min[0], min[1], max[0], max[1]]

@@ -445,3 +483,5 @@ }

export function validateTile (tile) {
const [tx, ty, zoom] = tile
var tx = tile[0]
var ty = tile[1]
var zoom = tile[2]
validateZoom(zoom)

@@ -452,3 +492,3 @@ if (tx === undefined || tx === null) { throw new Error('<x> is required') }

if (ty < 0) { throw new Error('<y> must not be less than 0') }
const maxCount = Math.pow(2, zoom)
var maxCount = Math.pow(2, zoom)
if (tx >= maxCount || ty >= maxCount) { throw new Error('Illegal parameters for tile') }

@@ -492,3 +532,4 @@ return tile

export function validateLngLat (lnglat) {
const [lng, lat] = lnglat
var lng = lnglat[0]
var lat = lnglat[1]
if (lat === undefined || lat === null) { throw new Error('<lat> is required') }

@@ -526,3 +567,3 @@ if (lng === undefined || lng === null) { throw new Error('<lng> is required') }

* @example
* const res = resolution(13)
* var res = resolution(13)
* //=19.109257071294063

@@ -558,5 +599,5 @@ */

}
const length = Math.max(Math.ceil((stop - start) / step), 0)
const range = Array(length)
for (let idx = 0; idx < length; idx++, start += step) {
var length = Math.max(Math.ceil((stop - start) / step), 0)
var range = Array(length)
for (var idx = 0; idx < length; idx++, start += step) {
range[idx] = start

@@ -563,0 +604,0 @@ }

{
"name": "global-mercator",
"version": "2.0.2",
"version": "2.0.3",
"description": "Tools to help with TMS, Quadkey & Google (XYZ) Tiles",

@@ -33,3 +33,3 @@ "main": "dist/global-mercator.js",

"typescript": "^2.1.5",
"uglify-js": "git://github.com/mishoo/UglifyJS2.git#harmony"
"uglify-js": "^2.7.5"
},

@@ -36,0 +36,0 @@ "keywords": [

@@ -24,3 +24,3 @@ # [Global Mercator](https://www.npmjs.com/package/global-mercator)

**web browser ([ES6](https://kangax.github.io/compat-table/es6))**
**web browser ([ES5](https://kangax.github.io/compat-table/es5))**

@@ -27,0 +27,0 @@ ```html

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc