simonw / datasette-tiles

Mapping tile server for Datasette, serving tiles from MBTiles packages
https://datasette.io/plugins/datasette-tiles
7 stars 5 forks source link

/-/tiles-stack mechanism for looking up tiles in multiple databases #8

Closed simonw closed 3 years ago

simonw commented 3 years ago

It would be neat if you could configure this plugin to serve tiles from multiple databases. Give it a database order and provide a tile endpoint which returns the requested tile from the first database in that order that has a result for that tile.

It could have a fallback at the end which returns an HTTP redirect to a configured tile server elsewhere.

simonw commented 3 years ago

The URL could be:

/-/tiles-multi/z/x/y.png

This would default to the order in which the databases were loaded by Datasette.

The order can be changed using a new metadata configuration setting:

plugins:
  datasette-tiles:
    tiles-multi-order:
    - new-york
    - basemap

Or by passing ?db=new-york&db=basemap in the URL to specify a specific custom order:

/-/tiles-multi/z/x/y.png?db=new-york&db=basemap
simonw commented 3 years ago

I'm going to have a special case for the datasette-basemap plugin: if that plugin is installed, basemap will always be treated as if it was the last attached database. The tiles-multi-order configuration option can be used to over-ride this behaviour.

simonw commented 3 years ago

Alternative names for this: stack, layers (could be confused with the Leaflet concept), fallback.

I think I like /-/tiles-stack more than /-/tiles-multi.

simonw commented 3 years ago

Which is more obvious, if we want to look for tiles in city1 and city2 first, then country1, then base?

datasette base.mbtiles country.mbtiles city1.mbtiles city2.mbtiles

Or:

datasette country.mbtiles city2.mbtiles city1.mbtiles country.mbtiles base.mbtiles

I think the first one. Tiles will be looked up from the end backwards.

simonw commented 3 years ago

Next steps:

simonw commented 3 years ago

I'm going to drop the query string thing unless someone asks for it.

simonw commented 3 years ago

This needs a demo page at /-/tiles-stack, similar to the tile explorer. It can be linked to in the README.

simonw commented 3 years ago

I suppose that page will use minZoom and maxZoom derived from the min/max of all of the tiles in the stack.

simonw commented 3 years ago

I built a demo database for this using the Stamen Toner map of Japan like so:

download-tiles japan-toner.mbtiles \ 
    -z 6-7 \
    --country 'japan' \
    --tiles-url "http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png" \
    --tiles-subdomains "a,b,c,d" \
    --attribution 'Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.'

https://static.simonwillison.net/static/2021/japan-toner-zoom-6-7.mbtiles

simonw commented 3 years ago

Last step: deploy the new toner demo and describe it in the README.

simonw commented 3 years ago

Demo is here - zoom in on Japan: https://datasette-tiles-demo.datasette.io/-/tiles-stack