Skip to main content

datasette-tiles

PyPI Changelog Tests License

Datasette plugin for serving MBTiles map tiles

Installation

Install this plugin in the same environment as Datasette.

$ datasette install datasette-tiles

Demo

You can try this plugin out at https://datasette-tiles-demo.datasette.io/-/tiles

Usage

This plugin scans all database files connected to Datasette to see if any of them are valid MBTiles databases.

It can then serve tiles from those databases at the following URL:

/-/tiles/db-name/zoom/x/y.png

An example map for each database demonstrating the configured minimum and maximum zoom for that database can be found at /-/tiles/db-name - this can also be accessed via the table and database action menus for that database.

Visit /-/tiles for an index page of attached valid databases.

You can install the datasette-basemap plugin to get a basemap default set of tiles, handling zoom levels 0 to 6 using OpenStreetMap.

Tile coordinate systems

There are two tile coordinate systems in common use for online maps. The first is used by OpenStreetMap and Google Maps, the second is from a specification called Tile Map Service, or TMS.

Both systems use three components: z/x/y - where z is the zoom level, x is the column and y is the row.

The difference is in the way the y value is counted. OpenStreetMap has y=0 at the top. TMS has y=0 at the bottom.

An illustrative example: at zoom level 2 the map is divided into 16 total tiles. The OpenStreetMap scheme numbers them like so:

0/0  1/0  2/0  3/0
0/1  1/1  2/1  3/1
0/2  1/2  2/2  3/2
0/3  1/3  2/3  3/3

The TMS scheme looks like this:

0/3  1/3  2/3  3/3
0/2  1/2  2/2  3/2
0/1  1/1  2/1  3/1
0/0  1/0  2/0  3/0

datasette-tiles can serve tiles using either of these standards. For the OpenStreetMap / Google Maps 0-at-the-top system, use the following URL:

/-/tiles/database-name/{z}/{x}/{y}.png

For the TMS 0-at-the-bottom system, use this:

/-/tiles-tms/database-name/{z}/{x}/{y}.png

Configuring a Leaflet tile layer

The following JavaScript will configure a Leaflet TileLayer for use with this plugin:

var tiles = leaflet.tileLayer("/-/tiles/basemap/{z}/{x}/{y}.png", {
  minZoom: 0,
  maxZoom: 6,
  attribution: "\u00a9 OpenStreetMap contributors"
});

Tile stacks

datasette-tiles can be configured to serve tiles from multiple attached MBTiles files, searching each database in order for a tile and falling back to the next in line if that tile is not found.

For a demo of this in action, visit https://datasette-tiles-demo.datasette.io/-/tiles-stack and zoom in on Japan. It should start showing Stamen's Toner map of Japan once you get to zoom level 6 and 7.

The /-/tiles-stack/{z}/{x}/{y}.png endpoint provides this feature.

If you start Datasette like this:

datasette world.mbtiles country.mbtiles city1.mbtiles city2.mbtiles

Any requests for a tile from the /-/tiles-stack path will first check the city2 database, than city1, then country, then world.

If you have the datasette-basemap plugin installed it will be given special treatment: the basemap database will always be the last database checked for a tile.

Rather than rely on the order in which databases were attached, you can instead configure an explicit order using the tiles-stack-order plugin setting. Add the following to your metadata.json file:

{
    "plugins": {
        "datasette-tiles": {
            "tiles-stack-order": ["world", "country"]
        }
    }
}

You can then run Datasette like this:

datasette -m metadata.json country.mbtiles world.mbtiles

This endpoint serves tiles using the OpenStreetMap / Google Maps coordinate system. To load tiles using the TMS coordinate system use this endpoint instead:

/-/tiles-stack-tms/{z}/{x}/{y}.png

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-tiles
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for datasette-tiles 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-tiles 0.6.1
File Size Uploaded Provenance Actions
datasette-tiles-0.6.1.tar.gz 10.0 kB Without provenance Details for datasette-tiles-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datasette-tiles 0.6.1
File Interpreter ABI Platform Actions
datasette_tiles-0.6.1-py3-none-any.whl Python 3 none any Details for datasette_tiles-0.6.1-py3-none-any.whl

Total release size: 19.3 kB

Release files / datasette-tiles-0.6.1.tar.gz

Download URL datasette-tiles-0.6.1.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2f11c57200541c3bd9dd5a165d9c15580b8656fac966af50ba8e45853cf9f7fb
BLAKE2b-256 checksum
How to use checksums
a8f40ae203f1e2cd29e6d96c5992747615715d2ccfe8d780125a4434b7bd1d28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

Release files / datasette_tiles-0.6.1-py3-none-any.whl

Download URL datasette_tiles-0.6.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48753bb114bfc68219a86109dcedcba26c18a7acd30dd8922cfaa933eef2d9dd
BLAKE2b-256 checksum
How to use checksums
08c1a1ae55157f8ace54803b68e75f9c6f0164a805a6a1c3341d7befc4835335
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

Security for datasette-tiles 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page