# @maptalks/geojson-vt

> Slice GeoJSON data into vector tiles efficiently(maptalks fork)

Latest version **3.5.0** (published 2023-11-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install @maptalks/geojson-vt
pnpm add @maptalks/geojson-vt
yarn add @maptalks/geojson-vt
bun add @maptalks/geojson-vt
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.5.0 |
| Published | 2023-11-20 |
| First published | 2022-04-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 85.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Vladimir Agafonkin |
| Maintainers | fuzhenn |
| Keywords | spatial, geojson, tiles, geometry |

## Links

- npm: https://www.npmjs.com/package/@maptalks/geojson-vt
- Repository: https://github.com/fuzhenn/geojson-vt
- Issues: https://github.com/fuzhenn/geojson-vt/issues
- npm.io page: https://npm.io/package/@maptalks/geojson-vt

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.5.0 (latest) — 2023-11-20
- 3.4.1 — 2023-03-09
- 3.4.0 — 2023-03-09
- 3.3.3 — 2022-12-17
- 3.3.1 — 2022-06-07
- 3.2.3 — 2022-05-07
- 3.2.2 — 2022-05-05
- 3.2.1 — 2022-04-25

## README

## geojson-vt &mdash; GeoJSON Vector Tiles

**Fork of [mapbox/geojson-vt](https://github.com/mapbox/geojson-vt), add some functions.**

[![Build Status](https://travis-ci.org/fuzhenn/geojson-vt.svg?branch=main)](https://travis-ci.org/fuzhenn/geojson-vt)

A highly efficient JavaScript library for **slicing GeoJSON data into vector tiles on the fly**,
primarily designed to enable rendering and interacting with large geospatial datasets
on the browser side (without a server).

Created to power GeoJSON in [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js),
but can be useful in other visualization platforms
like [Leaflet](https://github.com/Leaflet/Leaflet), [OpenLayers](https://openlayers.org/) and [d3](https://github.com/mbostock/d3),
as well as Node.js server applications.

Resulting tiles conform to the JSON equivalent
of the [vector tile specification](https://github.com/mapbox/vector-tile-spec/).
To make data rendering and interaction fast, the tiles are simplified,
retaining the minimum level of detail appropriate for each zoom level
(simplifying shapes, filtering out tiny polygons and polylines).

Read more on how the library works [on the Mapbox blog](https://blog.mapbox.com/rendering-big-geodata-on-the-fly-with-geojson-vt-4e4d2a5dd1f2).

There's a C++11 port: [geojson-vt-cpp](https://github.com/mapbox/geojson-vt-cpp)

### Demo

Here's **geojson-vt** action in [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js),
dynamically loading a 100Mb US zip codes GeoJSON with 5.4 million points:

![](https://cloud.githubusercontent.com/assets/25395/5360312/86028d8e-7f91-11e4-811f-87f24acb09ca.gif)

There's a convenient [debug page](http://mapbox.github.io/geojson-vt/debug/) to test out **geojson-vt** on different data.
Just drag any GeoJSON on the page, watching the console.

![](https://cloud.githubusercontent.com/assets/25395/5363235/41955c6e-7fa8-11e4-9575-a66ef54cb6d9.gif)

### Usage

```js
// 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'
```

### Options

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.

### Install

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
<script src="https://unpkg.com/@maptalks/geojson-vt@3.2.0/geojson-vt.js"></script>
```

---
_Source: https://npm.io/package/@maptalks/geojson-vt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
