I'm interested in how to host vector tiles from static server. It's easy to serve png tiles with Leaflet, but I'm failing to do so with .geojson, .pbf or .mvt tiles. I'm trying to add to a map a single point and it just doesn't appear no matter what.
I'm not bound to Leaflet or any of its plugins or gis tools, and yet I can't make it work. Here is how I failed with protomaps-leaflet plugin:
Protomaps + Leaflet attempt
Here is small HTML which renders vector tiles:
https://protomaps.github.io/protomaps-leaflet/examples/leaflet.html#0/0/0 https://github.com/protomaps/protomaps-leaflet/blob/main/examples/leaflet.html
This is how vector layer is created and added to a map:
const map = L.map('map') let hash = new L.Hash(map) if (!window.location.hash) map.setView(new L.LatLng(0,0),0) var layer = protomapsL.leafletLayer({url:'https://api.protomaps.com/tiles/v4/{z}/{x}/{y}.mvt?key=1003762824b9687f',flavor:'light',lang:"en"}) layer.addTo(map) It fetches .mvt files from https://api.protomaps.com/tiles/v4/{z}/{x}/{y}.mvt?key=1003762824b9687f url.
I've downloaded leaflet.html file to empty dir, changed urlpattern to ./tilesMeta/{z}/{x}/{y}.pbf, created output.geojson file:
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [0, 0] }, "properties": { "name": "Test Point" } } ] } Created .pbf files:
& $tippecanoe --no-tile-compression -e tilesMeta -l default -z1 output.geojson Started Http server:
python -m http.server 8000 But at http://localhost:8000/protomapEmpty.html there is an empty map canvas.
Also, I've tried creating a lot of points (in hope they will be more visible):
$feature = @' { "type": "Feature", "geometry": { "type": "Point", "coordinates": [0, 0] }, "properties": { "name": "Test Point" } } '@ | ConvertFrom-Json -Depth 9 $features = -10..10 | % { $x = $_ -10..10 | % { $feature.geometry.coordinates = $x,$_; $feature.properties.name = $x,$_ -join " " Add-Member -inp $feature -NotePropertyName id -NotePropertyValue (Get-Random -Min 0 -max 99999) -Force $feature | ConvertTo-Json -Depth 9 | ConvertFrom-Json -Depth 9 } } [pscustomobject]@{type = 'FeatureCollection'; features = $features} | ConvertTo-Json -Depth 9 > points.geojson & $tippecanoe --no-tile-compression -e tilesMeta -l default -zg .\points.geojson Directory structure:
.\output.geojson .\points.geojson .\protomapEmpty.html .\tilesMeta\metadata.json .\tilesMeta\0\0\0.pbf .\tilesMeta\1\0\0.pbf .\tilesMeta\1\0\1.pbf .\tilesMeta\1\1\0.pbf .\tilesMeta\1\1\1.pbf There are no errors in js console. It just doesn't display any vector tiles.
I've tried other Leaflet vector tiles plugins with no luck:
https://leafletjs.com/plugins.html#vector-tiles
These tutorials seem related, but I haven't tried them yet:
https://xycarto.com/2020/11/18/static-vector-tiles-for-small-projects/
https://xycarto.com/2021/04/30/static-vector-tiles-ii-openlayers-with-custom-projection/
I even tried downloading .mvt file from https://api.protomaps.com/tiles/v4/{z}/{x}/{y}.mvt?key=1003762824b9687f and placing it into corresponding directory, but no luck (each time I was sure file extensions match url pattern).