consbio / mbtileserver

Basic Go server for mbtiles
ISC License
658 stars 104 forks source link

HTTP 204 response on valid tile request. #123

Closed nextstopsun closed 2 years ago

nextstopsun commented 2 years ago

HTTP/1.1 204 No Content response when requesting an existing pbf tile.

Hosting with docker:

docker run --rm -p 8080:8000 -v /data/cache/mbtiles:/tilesets consbio/mbtileserver -v

Testing request:

curl -i http://localhost:8080/services/s1/tiles/9/308/159.pbf
HTTP/1.1 204 No Content
Vary: Origin
Date: Wed, 24 Nov 2021 07:08:50 GMT

Testing with sqlite

sqlite3 s1.mbtiles                                           
SQLite version 3.32.3 2020-06-18 14:16:19
Enter ".help" for usage hints.
sqlite> select hex(tile_data) from tiles where zoom_level=9 and tile_column=308 and tile_row=159;

--long binary output here

sqlite> select tile_data from tiles where zoom_level=9 and tile_column=308 and tile_row=159;
?

I've double checked and the data is there in the tiles table. Verbose logging doesn't output the actual database query, so I've got no clue why mbtileserver sends no content back.

brendan-ward commented 2 years ago

mbtileserver returns a HTTP 204 when the tile could not be queried from the underlying mbtiles file; other formats generally return HTTP 404 in this case, but doing so for vector tiles tends to produce bad behavior in various clients.

Note that the Y (row) coordinate of the tile request is flipped before querying the mbtiles file here because mbtiles are stored according to the mbtiles spec but served according to XYZ here, so a request for

.../tiles/9/308/159.pbf

would translate into a query of

sqlite> select tile_data from tiles where zoom_level=9 and tile_column=308 and tile_row=352;

Can you please check that query against your mbtiles file to determine if there is indeed a tile present for that zoom / column / row?

You may also want to double-check that your mbtiles file contains files according to the TMS row order according to the mbtiles spec. How did you create your tiles?

nextstopsun commented 2 years ago

@brendan-ward Thanks, TMS schema was the case here.

Fixed with

UPDATE tiles SET tile_row = (1 << zoom_level) - 1 - tile_row;