Slice GeoJSON into vector tiles on the fly in the browser
Installations
npm install geojson-vt
Developer
mapbox
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
No
Node Version
20.14.0
NPM Version
10.8.0
Statistics
1,898 Stars
257 Commits
270 Forks
180 Watching
7 Branches
557 Contributors
Updated on 27 Nov 2024
Languages
JavaScript (98.4%)
HTML (1.6%)
Total Downloads
Cumulative downloads
Total Downloads
180,445,132
Last day
-3.7%
244,691
Compared to previous day
Last week
2.5%
1,292,589
Compared to previous week
Last month
9.6%
5,402,619
Compared to previous month
Last year
22.2%
54,866,414
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
6
geojson-vt — GeoJSON Vector Tiles
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, but can be useful in other visualization platforms like Leaflet, OpenLayers and d3, as well as Node.js server applications.
Resulting tiles conform to the JSON equivalent of the vector tile specification. 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.
There's a C++11 port: geojson-vt-cpp
Demo
Here's geojson-vt action in Mapbox GL JS, dynamically loading a 100Mb US zip codes GeoJSON with 5.4 million points:
There's a convenient debug page to test out geojson-vt on different data. Just drag any GeoJSON on the page, watching the console.
Usage
1// build an initial index of tiles 2var tileIndex = geojsonvt(geoJSON); 3 4// request a particular tile 5var features = tileIndex.getTile(z, x, y).features; 6 7// show an array of tile coordinates created so far 8console.log(tileIndex.tileCoords); // [{z: 0, x: 0, y: 0}, ...]
Options
You can fine-tune the results with an options object, although the defaults are sensible and work well for most use cases.
1var tileIndex = geojsonvt(data, { 2 maxZoom: 14, // max zoom to preserve detail on; can't be higher than 24 3 tolerance: 3, // simplification tolerance (higher means simpler) 4 extent: 4096, // tile extent (both width and height) 5 buffer: 64, // tile buffer on each side 6 debug: 0, // logging level (0 to disable, 1 or 2) 7 lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features 8 promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with `generateId` 9 generateId: false, // whether to generate feature ids. Cannot be used with `promoteId` 10 indexMaxZoom: 5, // max zoom in the initial tile index 11 indexMaxPoints: 100000 // max number of points per tile in the index 12});
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 geojson-vt
), then:
1// import as a ES module 2import geojsonvt from 'geojson-vt'; 3 4// import from a CDN in the browser: 5import geojsonvt from 'https://esm.run/geojson-vt';
Or use a browser build directly:
1<script src="https://unpkg.com/geojson-vt/geojson-vt.js"></script>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/mapbox/.github/SECURITY.md:1
- Info: Found linked content: github.com/mapbox/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/mapbox/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/mapbox/.github/SECURITY.md:1
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
branch protection is not maximal on development and all release branches
Details
- Info: 'allow deletion' disabled on branch 'main'
- Info: 'force pushes' disabled on branch 'main'
- Warn: 'branch protection settings apply to administrators' is disabled on branch 'main'
- Warn: 'stale review dismissal' is disabled on branch 'main'
- Warn: required approving review count is 1 on branch 'main'
- Warn: codeowners review is not required on branch 'main'
- Warn: 'last push approval' is disabled on branch 'main'
- Warn: no status checks found to merge onto branch 'main'
- Info: PRs are required in order to make changes on branch 'main'
Reason
Found 11/27 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/mapbox/geojson-vt/node.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/mapbox/geojson-vt/node.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 1
Details
- Warn: 2 commits out of 14 are checked with a SAST tool
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
5
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More