viewport-mercator-project
Advanced tools
Comparing version 2.0.1 to 2.1.0
15
index.js
@@ -45,2 +45,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var offsetY = opts.height * 0.5 - y; | ||
function project(lnglat2) { | ||
@@ -53,2 +54,3 @@ var lamda2 = lnglat2[0] * DEGREES_TO_RADIANS; | ||
} | ||
function unproject(xy) { | ||
@@ -61,5 +63,16 @@ var x2 = xy[0] - offsetX; | ||
} | ||
return {project: project, unproject: unproject}; | ||
function contains(lnglat2) { | ||
var xy = project(lnglat2); | ||
var x = xy[0]; | ||
var y = xy[1]; | ||
return ( | ||
x >= 0 && x <= opts.width && | ||
y >= 0 && y <= opts.height | ||
); | ||
} | ||
return {project: project, unproject: unproject, contains: contains}; | ||
} | ||
module.exports = ViewportMercator; |
{ | ||
"name": "viewport-mercator-project", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Convert to and from lat/lng and pixels in web mercator at arbitrary floating point zoom levels.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,2 +29,5 @@ # viewport-mercator-project | ||
viewport.unproject(pixels); // returns [0, 0] | ||
// Test if a lnglat is within the viewport | ||
viewport.contains(lnglat); // true | ||
```` | ||
@@ -41,3 +44,9 @@ | ||
## Notes on Projection | ||
The coordinate system of the viewport is defined as a cartesian plane with the origin in the top left, | ||
where the positive x-axis goes right, and the positive y-axis goes down. | ||
That is, the top left corner is `[0, 0]` and the bottom right corner is `[width, height]`. | ||
## Change log | ||
@@ -44,0 +53,0 @@ |
@@ -101,1 +101,30 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
}); | ||
test('contains a given point', function tt(t) { | ||
var size = 512; | ||
var viewport = createViewport({ | ||
width: size, | ||
height: size, | ||
latitude: 0, | ||
longitude: 0, | ||
zoom: 12 | ||
}); | ||
// Center should be in | ||
t.true(viewport.contains([0, 0])); | ||
// Test the boundaries are in | ||
t.true(viewport.contains(viewport.unproject([0, 0]))); | ||
t.true(viewport.contains(viewport.unproject([512, 512]))); | ||
// Outside in either direction is false | ||
t.false(viewport.contains(viewport.unproject([-1, 256]))); | ||
t.false(viewport.contains(viewport.unproject([256, -1]))); | ||
t.false(viewport.contains(viewport.unproject([256, 513]))); | ||
t.false(viewport.contains(viewport.unproject([513, 256]))); | ||
// Both under and over | ||
t.false(viewport.contains(viewport.unproject([513, 513]))); | ||
t.false(viewport.contains(viewport.unproject([-1, -1]))); | ||
t.end(); | ||
}); |
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
11024
179
69