protomaps / go-pmtiles

Single-file executable tool for working with PMTiles archives
BSD 3-Clause "New" or "Revised" License
350 stars 48 forks source link

404 when trying to serve local PMTiles using the pmtiles CLI #162

Closed BigBoulard closed 4 months ago

BigBoulard commented 4 months ago

Hello,

I struggle to serve a PMTiles file locally using pmtiles CLI through the pmtiles serve command. I'm probably missing something obvious. I've created a public repo to illustrate the issue https://github.com/BigBoulard/test-maplibre-pmtiles-local

pmtiles serve output

> ls
README.md                  belgium-planetiler.pmtiles index.html                 index.js                   style.json
> pmtiles serve --cors="*" --port=3003 .
2024/04/06 09:11:05 main.go:149: Serving  . on port 3003 and interface 0.0.0.0 with Access-Control-Allow-Origin: *
2024/04/06 09:11:12 main.go:146: served 404 /belgium-planetiler.pmtiles in 56.375µs

PMTiles File Info

The file has been generated using Planetiler through docker.

docker run --name planetiler -e JAVA_TOOL_OPTIONS="-Xmx1g" -v "$(pwd)/data":/data ghcr.io/onthegomap/planetiler:latest --download --area=belgium --output=/data/belgium.pmtiles

File info

pmtiles show belgium-planetiler.pmtiles
pmtiles spec version: 3
tile type: Vector Protobuf (MVT)
bounds: (long: 2.340725, lat: 49.494891) (long: 6.410265, lat: 51.598390)
min zoom: 0
max zoom: 14
center: (long: 4.375495, lat: 50.546641)
center zoom: 7
addressed tiles count: 22313
tile entries count: 21309
tile contents count: 20932
clustered: true
internal compression: 2
tile compression: 2
planetiler:osm:osmosisreplicationseq 3994
planetiler:osm:osmosisreplicationtime 2024-03-10T21:21:01Z
version 3.14.0
vector_layers <object...>
attribution <a href="https://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>
description A tileset showcasing all layers in OpenMapTiles. https://openmaptiles.org
planetiler:githash 7dd0f85bb1c025ea5a853ede7f2bd301d3429073
type baselayer
name OpenMapTiles
planetiler:buildtime 2024-03-09T00:09:08.235Z
planetiler:osm:osmosisreplicationurl http://download.geofabrik.de/europe/belgium-updates
planetiler:version 0.7-SNAPSHOT

Thank you so much.

bdon commented 4 months ago

did you ask for /belgium-planetiler.json or /belgium-planetiler/0/0/0.mvt ? the extension .pmtiles is not part of the route

BigBoulard commented 4 months ago

did you ask for /belgium-planetiler.json or /belgium-planetiler/0/0/0.mvt ? the extension .pmtiles is not part of the route

I asked for pmtiles://http://0.0.0.0:3003/belgium-planetiler.pmtiles

{
  "version": 8,
  "sources": {
    "protomaps": {
      "type": "vector",
      "attribution": "<a href=\"https://github.com/protomaps/basemaps\">Protomaps</a> © <a href=\"https://openstreetmap.org\">OpenStreetMap</a>",
      "url": "pmtiles://http://0.0.0.0:3003/belgium-planetiler.pmtiles"
    }
  },
  ...
 // index.html
let protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', protocol.tile);

const p = new pmtiles.PMTiles(
  'http://0.0.0.0:3003/maps/belgium-planetiler.pmtiles'
);

let map = new maplibregl.Map({
  container: 'map',
  zoom: 5,
  center: [4.399925366497536, 50.852261740575464],
  hash: true,
  pitchWithRotate: false,
  style: 'style.json',
});
bdon commented 4 months ago

If you want to access it as pmtiles://http://...belgium_planetiler.pmtiles and not http://belgium_planetiler/{z}/{x}/{y}.mvt you do not need pmtiles serve, just any static http server.