Slice GeoJSON data into vector tiles efficiently(maptalks fork)
npm install @maptalks/geojson-vtjs
// build an initial index of tiles
var tileIndex = geojsonvt(geoJSON);
// request a particular tile
var features = tileIndex.getTile(z, x, y).features;
// show an array of tile coordinates created so far
console.log(tileIndex.tileCoords); // [{z: 0, x: 0, y: 0}, ...]
`
#### Multi data source with layer name
`js
// build an initial index of tiles
var tileIndex = geojsonvt([
{
layer: 'layer-1',
data: geoJSON
},
{
layer: 'layer-2',
data: geoJSON
}
]);
// request a particular tile
var features = tileIndex.getTile(z, x, y).features;
// each feature in features will have a extra property 'layer'
`
$3
You can fine-tune the results with an options object,
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; 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
debug: 0, // logging level (0 to disable, 1 or 2)
lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features
promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with generateId
generateId: false, // whether to generate feature ids. Cannot be used with promoteId
hasAltitude: false, // whether input data has altitude
disableFilter: false, // whether filter by size(length for polyline, area for polygon)
indexMaxZoom: 5, // max zoom in the initial tile index
indexMaxPoints: 100000 // max number of points per tile in the index
});
`
#### Added options
- hasAltitude, to support data with altitude(if coordinate has no altitude, altitude default to 0 internally)
- disableFilter, to disable filter line/polygon by it's size
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.
The promoteId and generateId options ignore existing id values on the feature objects.
GeoJSON-VT only operates on zoom levels up to 24.
$3
Install using NPM (npm install @maptalks/geojson-vt) or Yarn (yarn add @maptalks/geojson-vt), then:
`js
// import as a ES module
import geojsonvt from '@maptalks/geojson-vt';
// or require in Node / Browserify
const geojsonvt = require('@maptalks/geojson-vt');
`
Or use a browser build directly:
`html
``