Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
geojson-vt
Advanced tools
The geojson-vt package is a library for slicing GeoJSON into vector tiles on the fly. It's primarily designed to handle large amounts of data by cutting them into smaller, more manageable pieces called 'tiles'. These tiles can then be used for efficient rendering and manipulation on map interfaces.
Slicing GeoJSON into vector tiles
This feature allows you to convert a GeoJSON object into vector tiles. You can then retrieve specific tiles by their x, y, and z coordinates.
const geojsonVt = require('geojson-vt');
const geojsonData = {
type: 'FeatureCollection',
features: [...]
};
const options = {};
const tileIndex = geojsonVt(geojsonData, options);
const tile = tileIndex.getTile(z, x, y);
Custom tile generation options
This feature allows you to customize how the GeoJSON data is sliced into vector tiles, including the level of detail, simplification tolerance, and tile dimensions.
const options = {
maxZoom: 17, // 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
generateId: false, // whether to generate feature ids. Cannot be used with promoteId
indexMaxZoom: 5, // max zoom in the initial tile index
indexMaxPoints: 100000 // max number of points per tile in the index
};
const tileIndex = geojsonVt(geojsonData, options);
On-the-fly tile generation
This feature allows you to generate tiles on demand, rather than processing an entire set of tiles upfront. This can be more efficient when dealing with large datasets.
const tile = tileIndex.getTile(z, x, y);
if (!tile) {
console.log('Tile not found');
} else {
console.log('Generated tile:', tile);
}
Mapshaper is a tool for editing and converting vector map data. It has a web interface and a command-line tool. While it can simplify and convert data formats, it doesn't specifically slice data into vector tiles like geojson-vt does, but it can be used for preprocessing data before using it with 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, but can be useful in other visualization platforms like Leaflet 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
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.
// 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}, ...]
You can fine-tune the results with an options object, although the defaults are sensible and work well for most use cases.
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)
indexMaxZoom: 5, // max zoom in the initial tile index
indexMaxPoints: 100000 // max number of points per tile in the index
});
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
.
GeoJSON-VT only operates on zoom levels up to 24.
Install with NPM or Yarn (npm install geojson-vt
), or use one of the CDN browser builds:
FAQs
Slice GeoJSON data into vector tiles efficiently
The npm package geojson-vt receives a total of 1,003,863 weekly downloads. As such, geojson-vt popularity was classified as popular.
We found that geojson-vt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 29 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.