Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "quadbin", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Utility functions for working with Quadbins", | ||
@@ -43,3 +43,5 @@ "license": "MIT", | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"@mapbox/tile-cover": "^3.0.2" | ||
} | ||
} |
@@ -75,1 +75,9 @@ # quadbin-js | ||
Converts quadbin cell into a xyz tile. | ||
## geometryToCells | ||
```javascript | ||
function geometryToCells(geometry: GeoJSONGeometry, resolution: bigint): bigint | ||
``` | ||
Returns a list of cells covering a GeoJSON geometry at a given resolution |
@@ -0,1 +1,3 @@ | ||
import {tiles} from '@mapbox/tile-cover'; | ||
const B = [ | ||
@@ -12,3 +14,3 @@ 0x5555555555555555n, | ||
type Quadbin = bigint; | ||
type Tile = {x: number, y: number, z: number}; | ||
type Tile = {x: number; y: number; z: number}; | ||
@@ -83,1 +85,9 @@ export function hexToBigInt(hex: string): bigint { | ||
} | ||
export function geometryToCells(geometry, resolution: bigint): Quadbin[] { | ||
const zoom = Number(resolution); | ||
return tiles(geometry, { | ||
min_zoom: zoom, | ||
max_zoom: zoom | ||
}).map(([x, y, z]) => tileToCell({x, y, z})); | ||
} |
import test from 'tape'; | ||
import {tileToCell, cellToTile, cellToParent, getResolution} from '../src/index' | ||
import { | ||
tileToCell, | ||
cellToTile, | ||
cellToParent, | ||
geometryToCells, | ||
getResolution, | ||
hexToBigInt | ||
} from '../src/index'; | ||
import {tileToQuadkey} from './quadkey-utils'; | ||
@@ -41,1 +48,31 @@ | ||
}); | ||
// Zoom:26 test not agreeing with Python | ||
import PointGeometry from './data/PointGeometry.json'; | ||
import MultiPointGeometry from './data/MultiPointGeometry.json'; | ||
import LineStringGeometry from './data/LineStringGeometry.json'; | ||
import MultiLineStringGeometry from './data/MultiLineStringGeometry.json'; | ||
import PolygonGeometry from './data/PolygonGeometry.json'; | ||
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json'; | ||
const testCases = [ | ||
PointGeometry, | ||
MultiPointGeometry, | ||
LineStringGeometry, | ||
PolygonGeometry, | ||
MultiPolygonGeometry | ||
]; | ||
test('Quadbin geometryToCells', async t => { | ||
for (const {name, geometry, expected} of testCases) { | ||
for (const resolution of Object.keys(expected)) { | ||
const expectedCells = expected[resolution].map(BigInt).sort(); | ||
const cells = geometryToCells(geometry, resolution).sort(); | ||
t.deepEquals( | ||
cells, | ||
expectedCells, | ||
`Correct cells generated from ${name} geometry at resolution ${resolution}` | ||
); | ||
} | ||
} | ||
t.end(); | ||
}); |
20274
26
559
83
1
+ Added@mapbox/tile-cover@^3.0.2
+ Added@mapbox/tile-cover@3.0.2(transitive)
+ Added@mapbox/tilebelt@1.0.2(transitive)