simonw / datasette-tiles

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

Initial plugin design #1

Closed simonw closed 3 years ago

simonw commented 3 years ago

This plugin will work by scanning all other attached databases to see if they are a valid MBTiles package. It will then make those tiles available at /-/tiles/db-name/z/x/y.png

simonw commented 3 years ago

It's going to have an interface at /-/tiles which shows the list of available tile databases, and /-/tiles/db-name will present a Leaflet map previewing those tiles. It will depend on datasette-leaflet for that.

simonw commented 3 years ago

It will consult the _internal database https://docs.datasette.io/en/stable/internals.html#the-internal-database to determine if a database is a valid MBTiles package, by looking for the following tables (or views):

CREATE TABLE tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob);
CREATE TABLE metadata (name text, value text);

See https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md

simonw commented 3 years ago

For simplicity I'll just look for the tiles database table:

select
  columns.database_name,
  columns.table_name,
  group_concat(columns.name) as columns
from
  columns
where
  columns.table_name = "tiles"
group by
  columns.database_name,
  columns.table_name
order by
  columns.table_name

Outputs:

database_name table_name columns
San_Francisco tiles tile_column,tile_data,tile_row,zoom_level
basemap tiles tile_column,tile_data,tile_row,zoom_level