Closed simonw closed 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
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.
Alternative names for this: stack, layers (could be confused with the Leaflet concept), fallback.
I think I like /-/tiles-stack
more than /-/tiles-multi
.
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.
Next steps:
tiles-stack-order
setting?db=a&db=b
query string handlingI'm going to drop the query string thing unless someone asks for it.
This needs a demo page at /-/tiles-stack
, similar to the tile explorer. It can be linked to in the README.
I suppose that page will use minZoom
and maxZoom
derived from the min/max of all of the tiles in the stack.
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
Last step: deploy the new toner demo and describe it in the README.
Demo is here - zoom in on Japan: https://datasette-tiles-demo.datasette.io/-/tiles-stack
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.