protomaps / go-pmtiles

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

server always sends 404 #175

Open tillda opened 1 month ago

tillda commented 1 month ago

I have a tiles directory with myeurope.mbtiles. From which I run all sorts of pmtiles serve . variants. I am trying the MapLibre example. No matter what I try I always get a 404 response. I actually also don't understand if the URL that goes to new pmtiles.PMTiles should be "http://localhost:8080/myaustria" or "http://localhost:8080/myaustria.pmtiles"

I Aways get 404 response(s) like this:

CleanShot 2024-06-22 at 14 57 15@2x

The 204 is "No Content" status code.

bdon commented 1 month ago

If you are using pmtiles serve to decode on the server you don't need to use new pmtiles.PMTiles at all, which is for client-side decoding. Access your tiles via /{z}/{x}/{y} URLs.

tillda commented 1 month ago

Thanks for a prompt reply. I quicky tried the example in your CodePen. No matter what url i put in url: below, I always get one of these 404s. Also, can't there be some bug with those %2Fs? Surprisingly. http://localhost:8080/myaustria/metadata DOES return correct JSON response.

2024/06/22 15:53:12 main.go:147: served 404 %2Fmyaustria.pmtiles in 98.708µs
2024/06/22 15:53:30 main.go:147: served 404 %2Fmyaustria in 18.125µs

App.js:

<Map
        style={{ width: 600, height: 400 }}
        mapStyle={{
          version: 8,
          sources: {
            sample: {
              type: "vector",
              url:
                "pmtiles://http://localhost:8080/myaustria.pmtiles"
            }
          },
bdon commented 1 month ago
mapStyle={{
          version: 8,
          sources: {
            sample: {
              type: "vector",
              url:
                "pmtiles://http://localhost:8080/myaustria.pmtiles"
            }
          },

Again, you do not need pmtiles:// for client-side decoding if you are using pmtiles serve on the server side. Please see these docs: https://maplibre.org/maplibre-style-spec/sources/#vector

GridGrapher commented 1 month ago

I was having a seemingly identical issue, for reference I am basing my code on the MapLibre PMTiles example and running the docker go-pmtiles container to serve my .pmtiles file.

I solved the issue by changing the "url" to "tiles" reference, see the *** section in your adjusted code below.

<Map
        style={{ width: 600, height: 400 }}
        mapStyle={{
          version: 8,
          sources: {
            sample: {
              type: "vector",
             ***
              tiles: [
                "http://localhost:8080/myaustria/{z}/{x}/{y}.mvt"
              ]
             ***
            }
          },

This is what @bdon mentioned above, I'm just adding the example code as I missed the "url" -> "tiles" at the start when working on it myself. Hope this helps.

bdon commented 1 month ago

@GridGrapher thanks for posting the example, I updated the JS code here with a comment:

https://github.com/protomaps/PMTiles/pull/417/files

If you are using go-pmtiles you don't need to pay attention to any of the client-side PMTiles code at all, you can just access it from MapLibre like any typical ZXY URL the way most of the MapLibre documentation shows.

Where it can get confusing is url and tiles: https://maplibre.org/maplibre-style-spec/sources/