go-pmtiles icon indicating copy to clipboard operation
go-pmtiles copied to clipboard

server always sends 404

Open tillda opened this issue 1 year ago • 5 comments

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.

tillda avatar Jun 22 '24 12:06 tillda

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.

bdon avatar Jun 22 '24 13:06 bdon

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"
            }
          },

tillda avatar Jun 22 '24 14:06 tillda

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

bdon avatar Jun 22 '24 14:06 bdon

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.

GridGrapher avatar Jun 27 '24 19:06 GridGrapher

@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/

  • tiles is a array of ZXY endpoints, because historically many APIs had multiple mirrors under different subdomains to improve performance
  • url usually loads a TileJSON https://github.com/mapbox/tilejson-spec endpoint. This has a few advantages over using a ZXY url, it pre-populates the min/maxzoom. You can access TileJSON from go-pmtiles at http://localhost:8080/myaustria.json but it requires setting the public url initialization variable to generate proper URLs.

bdon avatar Jun 28 '24 09:06 bdon