@mapbox/tile-cover
Version:
generate the minimum number of tiles to cover a geojson geometry
81 lines (51 loc) • 2.25 kB
Markdown
tile-cover
==========
[](https://travis-ci.org/mapbox/tile-cover)
Generate the minimum number of tiles to cover a [GeoJSON Geometry](http://geojson.org/geojson-spec.html#geometry-objects).
### Install
```bash
npm install @mapbox/tile-cover
```
### Usage
```js
var cover = require('@mapbox/tile-cover');
var poly = JSON.parse(fs.readFileSync('./poly.geojson'));
var limits = {
min_zoom: 4,
max_zoom: 9
};
cover.geojson(poly.geom, limits);
cover.tiles(poly.geom, limits);
cover.indexes(poly.geom, limits);
```
# API
## geojson(geom, limits)
Given a [geometry](http://geojson.org/geojson-spec.html#geometry-objects), create cells and return them in a format easily readable by any software that reads GeoJSON.
* `geom` (`Object`): GeoJSON geometry
* `limits` (`Object`): an object with min_zoom and max_zoom properties specifying the minimum and maximum level to be tiled.
**Returns** `Object`, FeatureCollection of cells formatted as GeoJSON Features
## tiles(geom, limits)
Given a [geometry](http://geojson.org/geojson-spec.html#geometry-objects), create cells and return them in their raw form, as an array of cell identifiers.
* `geom` (`Object`): GeoJSON geometry
* `limits` (`Object`): an object with min_zoom and max_zoom properties specifying the minimum and maximum level to be tiled.
**Returns** `Array.<Array.<number>>`, An array of tiles given as [x, y, z] arrays
## indexes(geom, limits)
Given a [geometry](http://geojson.org/geojson-spec.html#geometry-objects), create cells and return them as quadkey indexes.
* `geom` (`Object`): GeoJSON geometry
* `limits` (`Object`): an object with min_zoom and max_zoom properties specifying the minimum and maximum level to be tiled.
**Returns** `Array.<String>`, An array of tiles given as quadkeys.
### Tests
```bash
npm test
```
### Benchmarks
```bash
node bench.js
```
### Examples
##### Polygons:

##### Lines:

##### Points:
