Skip to content

Commit

Permalink
Support float zooms in bounds() function (#19)
Browse files Browse the repository at this point in the history
* Strips trailing whitespace from package.json

This formatting change was generated automatically when running
`npm install` with npm v6.1.0.

* Upgrades node-sphericalmercator to v1.1.0

This version now supports float-based zoom levels.

* Adds test for float zoom input for bounds function

* Refactors expected test values to be more explicit

* Rebuilds dist version of geo-viewport.js with latest sphericalmercator
  • Loading branch information
timiyay authored and mapsam committed May 29, 2018
1 parent e41266d commit d62873a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion geo-viewport.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"license": "BSD-2-Clause",
"name": "@mapbox/geo-viewport",
"license": "BSD-2-Clause",
"name": "@mapbox/geo-viewport",
"repository": {
"url": "git@github.com:mapbox/geo-viewport.git",
"url": "git@github.com:mapbox/geo-viewport.git",
"type": "git"
},
"author": "Tom MacWright",
},
"author": "Tom MacWright",
"bugs": {
"url": "https://github.com/mapbox/geo-viewport/issues"
},
"version": "0.2.2",
},
"version": "0.2.2",
"dependencies": {
"@mapbox/sphericalmercator": "~1.0.2"
},
"@mapbox/sphericalmercator": "~1.1.0"
},
"scripts": {
"test": "tap test/*.js",
"test": "tap test/*.js",
"build": "browserify -s geoViewport index.js | uglifyjs -c > geo-viewport.js"
},
},
"keywords": [
"geographic",
"viewport",
"zoom",
"geographic",
"viewport",
"zoom",
"scale"
],
],
"devDependencies": {
"browserify": "^13.0.0",
"uglify-js": "^2.6.2",
"browserify": "^13.0.0",
"uglify-js": "^2.6.2",
"tap": "^5.7.0"
},
"main": "index.js",
"homepage": "https://github.com/mapbox/geo-viewport",
},
"main": "index.js",
"homepage": "https://github.com/mapbox/geo-viewport",
"description": "convert between viewports and extents"
}
23 changes: 19 additions & 4 deletions test/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,24 @@ test('bounds for 512px tiles', function (t) {
var xMax = bounds[2];
var yMax = bounds[3];

t.equal(precisionRound(xMin, decDegreesFloatTolerance), precisionRound(-77.03945338726044, decDegreesFloatTolerance));
t.equal(precisionRound(yMin, decDegreesFloatTolerance), precisionRound(38.89697827424865, decDegreesFloatTolerance));
t.equal(precisionRound(xMax, decDegreesFloatTolerance), precisionRound(-77.03365981578827, decDegreesFloatTolerance));
t.equal(precisionRound(yMax, decDegreesFloatTolerance), precisionRound(38.89843950894583, decDegreesFloatTolerance));
t.equal(precisionRound(xMin, decDegreesFloatTolerance), -77.03945339);
t.equal(precisionRound(yMin, decDegreesFloatTolerance), 38.89697827);
t.equal(precisionRound(xMax, decDegreesFloatTolerance), -77.03365982);
t.equal(precisionRound(yMax, decDegreesFloatTolerance), 38.89843951);
t.end();
});

test('bounds for float zooms', function (t) {
var zoom = 16.52;
var bounds = viewport.bounds([-77.036556, 38.897708], zoom, [1080, 350], 512);
var xMin = bounds[0];
var yMin = bounds[1];
var xMax = bounds[2];
var yMax = bounds[3];

t.equal(precisionRound(xMin, decDegreesFloatTolerance), -77.04059627);
t.equal(precisionRound(yMin, decDegreesFloatTolerance), 38.89668897);
t.equal(precisionRound(xMax, decDegreesFloatTolerance), -77.03251573);
t.equal(precisionRound(yMax, decDegreesFloatTolerance), 38.89872702);
t.end();
});

0 comments on commit d62873a

Please sign in to comment.