Skip to content

Commit

Permalink
add an explicit 0-24 zoom cap
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Nov 13, 2017
1 parent acfd98d commit 3ad3ace
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -54,7 +54,7 @@ although the defaults are sensible and work well for most use cases.

```js
var tileIndex = geojsonvt(data, {
maxZoom: 14, // max zoom to preserve detail on
maxZoom: 14, // max zoom to preserve detail on; can't be higher than 24
tolerance: 3, // simplification tolerance (higher means simpler)
extent: 4096, // tile extent (both width and height)
buffer: 64, // tile buffer on each side
Expand All @@ -68,6 +68,8 @@ var tileIndex = geojsonvt(data, {

By default, tiles at zoom levels above `indexMaxZoom` are generated on the fly, but you can pre-generate all possible tiles for `data` by setting `indexMaxZoom` and `maxZoom` to the same value, setting `indexMaxPoints` to `0`, and then accessing the resulting tile coordinates from the `tileCoords` property of `tileIndex`.

GeoJSON-VT only operates on zoom levels up to 24.

### Browser builds

```bash
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Expand Up @@ -20,6 +20,8 @@ function GeoJSONVT(data, options) {

if (debug) console.time('preprocess data');

if (options.maxZoom < 0 || options.maxZoom > 24) throw new Error('maxZoom should be in the 0-24 range');

var z2 = 1 << options.maxZoom, // 2^z
features = convert(data, options.tolerance / (z2 * options.extent));

Expand Down Expand Up @@ -163,6 +165,8 @@ GeoJSONVT.prototype.getTile = function (z, x, y) {
extent = options.extent,
debug = options.debug;

if (z < 0 || z > 24) return null;

var z2 = 1 << z;
x = ((x % z2) + z2) % z2; // wrap tile x coordinate

Expand Down
1 change: 1 addition & 0 deletions test/test-get-tile.js
Expand Up @@ -27,6 +27,7 @@ test('getTile: us-states.json', function (t) {

t.equal(index.getTile(11, 800, 400), null, 'non-existing tile');
t.equal(index.getTile(-5, 123.25, 400.25), null, 'invalid tile');
t.equal(index.getTile(25, 200, 200), null, 'invalid tile');

t.equal(index.total, 37);

Expand Down

0 comments on commit 3ad3ace

Please sign in to comment.