global-mercator
Advanced tools
Comparing version 0.1.4 to 0.1.5
53
index.js
"use strict"; | ||
const Debug = require('debug'); | ||
const lodash_1 = require('lodash'); | ||
const debug = { | ||
exports.debug = { | ||
error: Debug('global-mercator:error'), | ||
@@ -268,4 +268,4 @@ log: Debug('global-mercator:log'), | ||
if (lodash_1.isUndefined(items[key])) { | ||
const message = (name) ? `${name} <${key}> is required.` : `<${key}> is required.`; | ||
debug.error(message); | ||
const message = (name) ? `${name} <${key}> is required` : `<${key}> is required`; | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -288,3 +288,3 @@ } | ||
const message = `${name} <tx> must not be less than 0`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -294,3 +294,3 @@ } | ||
const message = `${name} <ty> must not be less than 0`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -311,3 +311,3 @@ } | ||
const message = (name) ? `${name} <zoom> cannot be less than 1` : '<zoom> cannot be less than 1'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -317,3 +317,3 @@ } | ||
const message = (name) ? `${name} <zoom> cannot be greater than 23` : '<zoom> cannot be greater than 23'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -334,3 +334,3 @@ } | ||
const message = 'Pixels must be an Array of 2 numbers'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -342,3 +342,3 @@ } | ||
const message = `Pixels [px] has been modified to ${px}`; | ||
debug.warning(message); | ||
exports.debug.warning(message); | ||
} | ||
@@ -348,3 +348,3 @@ if (py % 1 !== 0) { | ||
const message = `Pixels [py] has been modified to ${py}`; | ||
debug.warning(message); | ||
exports.debug.warning(message); | ||
} | ||
@@ -364,3 +364,3 @@ return [px, py]; | ||
const message = 'Meters must be an Array of 2 numbers'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -373,3 +373,3 @@ } | ||
const message = `Meters [my] cannot be greater than ${max}`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -379,3 +379,3 @@ } | ||
const message = `Meters [my] cannot be less than ${min}`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -385,3 +385,3 @@ } | ||
const message = `Meters [mx] cannot be greater than ${max}`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -391,3 +391,3 @@ } | ||
const message = `Meters [mx] cannot be less than ${min}`; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -420,3 +420,3 @@ } | ||
const message = 'LatLng must be an Array of 2 numbers'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -427,3 +427,3 @@ } | ||
const message = 'LatLng [lat] must be within -90 to 90 degrees'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -433,3 +433,3 @@ } | ||
const message = 'LatLng [lng] must be within -180 to 180 degrees'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -439,3 +439,3 @@ } | ||
const message = 'LatLng [lat] has been modified to 85'; | ||
debug.warning(message); | ||
exports.debug.warning(message); | ||
lat = 85; | ||
@@ -445,3 +445,3 @@ } | ||
const message = 'LatLng [lat] has been modified to -85'; | ||
debug.warning(message); | ||
exports.debug.warning(message); | ||
lat = -85; | ||
@@ -462,3 +462,3 @@ } | ||
const message = '[bounds] must be an Array of 4 numbers'; | ||
debug.error(message); | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
@@ -495,3 +495,5 @@ } | ||
this.py = py; | ||
this.zoom = zoom; | ||
if (!lodash_1.isUndefined(zoom)) { | ||
this.zoom = zoom; | ||
} | ||
validateUndefined(this, 'Pixels'); | ||
@@ -541,2 +543,7 @@ validatePixels([px, py]); | ||
Resolution(zoom) { | ||
if (lodash_1.isUndefined(zoom)) { | ||
const message = '<zoom> is required'; | ||
exports.debug.error(message); | ||
throw new Error(message); | ||
} | ||
return this.initialResolution / Math.pow(2, zoom); | ||
@@ -736,4 +743,4 @@ } | ||
// console.log(metersToPixels({mx: 10000000, my: 5500000, zoom: 13})) | ||
console.log(validateLatLng([-85, -120])); | ||
console.log(metersToPixels({ mx: 3000, my: 4000 })); | ||
} | ||
//# sourceMappingURL=index.js.map |
14
index.ts
import * as Debug from 'debug' | ||
import { range, isUndefined, keys } from 'lodash' | ||
const debug = { | ||
export const debug = { | ||
error: Debug('global-mercator:error'), | ||
@@ -300,3 +300,3 @@ log: Debug('global-mercator:log'), | ||
if (isUndefined(items[key])) { | ||
const message = (name) ? `${ name } <${ key }> is required.` : `<${ key }> is required.` | ||
const message = (name) ? `${ name } <${ key }> is required` : `<${ key }> is required` | ||
debug.error(message) | ||
@@ -518,3 +518,3 @@ throw new Error(message) | ||
this.py = py | ||
this.zoom = zoom | ||
if (!isUndefined(zoom)) { this.zoom = zoom } | ||
validateUndefined(this, 'Pixels') | ||
@@ -568,2 +568,7 @@ validatePixels([px, py]) | ||
public Resolution(zoom: number) { | ||
if (isUndefined(zoom)) { | ||
const message = '<zoom> is required' | ||
debug.error(message) | ||
throw new Error(message) | ||
} | ||
return this.initialResolution / Math.pow(2, zoom) | ||
@@ -782,3 +787,4 @@ } | ||
// console.log(metersToPixels({mx: 10000000, my: 5500000, zoom: 13})) | ||
console.log(validateLatLng([-85, -120])) | ||
// console.log(metersToPixels({mx: 3000, my: 4000})) | ||
console.log(latLngToMeters({lat: 23, lng: 23})) | ||
} |
{ | ||
"name": "global-mercator", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Global Mercator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -140,4 +140,7 @@ "use strict"; | ||
ava_1.default('validateUndefined', t => { | ||
t.throws(() => mercator.validateUndefined({ x: undefined }), '<x> is required.'); | ||
t.throws(() => mercator.validateUndefined({ x: undefined }), '<x> is required'); | ||
}); | ||
ava_1.default('metersToPixels missing zoom', t => { | ||
t.throws(() => mercator.metersToPixels({ mx: -8348968.179247875, my: 5621503.917462073 }), '<zoom> is required'); | ||
}); | ||
//# sourceMappingURL=test.js.map |
@@ -169,3 +169,7 @@ import test from 'ava' | ||
test('validateUndefined', t => { | ||
t.throws(() => mercator.validateUndefined({x: undefined}), '<x> is required.') | ||
t.throws(() => mercator.validateUndefined({x: undefined}), '<x> is required') | ||
}) | ||
test('metersToPixels missing zoom', t => { | ||
t.throws(() => mercator.metersToPixels({ mx: -8348968.179247875, my: 5621503.917462073}), '<zoom> is required') | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
846860
23139