Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display vector tiles generated by geojson-vt in leaflet?

I have a lot of GeoJSON spatial data that I want to display on a leaflet map. Around 35,000 GeoJSON objects.

Because the amount of points can get very large, I wanted to use the geojson-vt library to tile my data on the client side.

Right now I have successfully tiled my data using the geojson-vt library:

var geoJson = {}; // Request to get data via API call not shown here

var tileOptions = {
        maxZoom: 18, 
        tolerance: 5, 
        extent: 4096,
        buffer: 64, 
        debug: 0, 
        indexMaxZoom: 0, 
        indexMaxPoints: 100000, 
    };

var tileIndex = geojsonvt(geoJson, tileOptions);

How do I integrate the vector tile data generated by geojson-vt to my Leaflet map?

Are there any recommended plugins or libraries that can help?

like image 656
Røye Avatar asked Nov 05 '15 14:11

Røye


People also ask

How do you display GeoJSON in leaflet?

GeoJSON objects are added to the map through a GeoJSON layer. To create it and add it to a map, we can use the following code: L. geoJSON(geojsonFeature).

What is a vector tileset?

Vector tiles are a way to deliver geographic data in small chunks to a browser or other client application. Vector tiles are similar to raster tiles, but instead of raster images, the data returned is a vector representation of the features in the tile.


2 Answers

This plugin for leaflet really helped me out, it's a great start and it works with Leaflet 1.0 and higher. I current use it in a mapping application with the current version of Leaflet and it works great. https://github.com/brandonxiang/leaflet-geojson-vt/tree/leaflet1.0.0

like image 200
Aaron Becker Avatar answered Oct 28 '22 13:10

Aaron Becker


In this example, it is shown how to render geojson-vt in a leaflet map by using L.CanvasTiles.

The problem is that Sumbera's CanvasTiles extension depicted in that example works only up to leaflet 0.7. I haven't found a repo for CanvasTiles in particular, much less an npm package for it.

like image 43
ffflabs Avatar answered Oct 28 '22 12:10

ffflabs