Unverified Commit 9acf64ab authored by Vladimir Agafonkin's avatar Vladimir Agafonkin Committed by GitHub
Browse files

add an explicit 0-24 zoom cap (#88)

parent acfd98d6
......@@ -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
......@@ -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
......
......@@ -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));
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment