Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate vector tiles and how to display it in leaflet

My data consists of many elements and attibutes, so I can't send entire json to client-side because it's too slow reading and displaying data.

At this point I need to make tiles from data. I have worked with tippecanoe, and it's so good but it "only" generates *.mbtiles (vector data inside *.pbf), and Leaflet 1.0.2 can't work with this format, so I tried to extract into zoom folders z/x/y with mbutil, but it seems that resulted *.pbf tiles are not correct because I've tried with Mapbox gl js and doesn't work well.

So first question is:

someone know how can I generate *.pbf tiles correctly from geojson files? I've tried some of options showed here: awesome-vector-tiles

And someone know if there's some plugin for Leaflet 1.0.2 that can work with vector tiles in *.mbtiles, *.pbf or *.json?

I've tried with mapbox-gl-leaflet, vectorgrid and tangram.

Thank you very much for your help

like image 996
Albert Avatar asked Dec 29 '16 11:12

Albert


People also ask

Can leaflet use vector tiles?

Leaflet doesn't support vector tiles by default. For basemaps, it is recommended to use it with traditional raster tiles (Mercator XYZ). Such tiles can be generated on demand for any of the GL styles with the open-source server software called TileServer GL.

How do I add a vector layer to a leaflet?

Polygon. Step 1 − Create a Map object by passing a <div> element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer() method of the Map class.

How do I publish a vector tile package?

Vector tile package file size is 500 GB or greaterSign in to your organization and open Content > My Content. You must have privileges to publish hosted tile layers. Click your tile package to display its item details page and click Publish.


1 Answers

You can serve Mapbox vector tiles from a Tippecanoe generated .mbtiles file using TileServer-GL. Using Docker makes this task even easier.

Assuming you have already generated a file called geo.mbtiles using Tippecanoe in your current directory:

docker run -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl geo.mbtiles

This will spin up a server, and it will give you an endpoint that serves .pbf vector tiles. These can be rendered with Mapbox GL, Leaflet.VectorGrid, etc.

like image 182
glifchits Avatar answered Sep 28 '22 02:09

glifchits