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

viewport-mercator-project

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viewport-mercator-project - npm Package Compare versions

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;

2

package.json
{
"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();
});
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