Skip to content

Commit

Permalink
Add support for exporting in smp (Styled Map Package) format (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudokemper authored Nov 27, 2024
1 parent fa6a2b3 commit e9c4bf4
Show file tree
Hide file tree
Showing 9 changed files with 2,485 additions and 127 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Publish to DockerHub](https://github.com/ConservationMetrics/mapgl-tile-renderer/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/ConservationMetrics/mapgl-tile-renderer/actions/workflows/docker-publish.yml)

This headless Node.js MapGL renderer can be used to generate styled raster tiles in an MBTiles format. It can work with self-provided tilesets and a stylesheet, or an online API source with optional GeoJSON and OpenStreetMap data overlays.
This headless Node.js MapGL renderer can be used to generate styled raster tiles in an MBTiles or [Styled Map Package](https://github.com/digidem/styled-map-package) format. It can work with self-provided tilesets and a stylesheet, or an online API source with optional GeoJSON and OpenStreetMap data overlays.

The motivation to build this utility is to create offline background maps for use in mobile data collection applications, such as [Mapeo](https://mapeo.app/), [ODK Collect](https://getodk.org/), [Kobo Collect](https://www.kobotoolbox.org/), [Locus Map](https://www.locusmap.app/) or other offline-compatible tools that can work with self-hosted tiles like [Terrastories](https://terrastories.app/). However, it can be helpful for any use case where having self-hosted raster MBTiles is a requirement.
The motivation to build this utility is to create offline background maps for use in mobile data collection applications, such as [Mapeo / CoMapeo](https://mapeo.app/), [ODK Collect](https://getodk.org/), [Kobo Collect](https://www.kobotoolbox.org/), [Locus Map](https://www.locusmap.app/) or other offline-compatible tools that can work with self-hosted tiles like [Terrastories](https://terrastories.app/). However, it can be helpful for any use case where having self-hosted raster tileset is a requirement.

This tool started as an extension of [mbgl-renderer](https://github.com/consbio/mbgl-renderer), which was built to export single static map images. Our thanks go out to the contributors of that project.

Expand Down Expand Up @@ -76,6 +76,7 @@ Common options:
* `-t` or `--tiletype`: Output tile type (jpg, png, or webp) (optional, jpg if not provided)
* `-o` or `--outputdir`: Output directory (optional, "outputs/" if not provided)
* `-f` or `--filename`: Name of the output MBTiles file (optional, "output" if not provided)
* `-F` or `--format`: "mbtiles" or "smp" format (optional, "mbtiles" if not provided)
* `-T` or `--thumbnail`: Optionally, generate a thumbnail of your style with a bounding box overlaid (false if not provided)

## CLI example usage
Expand All @@ -92,10 +93,10 @@ From an online source (Bing), with OpenStreetMap data overlaid:
mapgl-tile-renderer --style bing --bounds "-79,37,-77,38" --openstreetmap true -Z 8 --apikey YOUR_API_KEY_HERE
```

From an online source (Mapbox):
From an online source (Mapbox), SMP output:

```bash
mapgl-tile-renderer --style mapbox --mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE --bounds "-79,37,-77,38" -Z 8
mapgl-tile-renderer --style mapbox --mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE --bounds "-79,37,-77,38" -Z 8 -F smp
```

From an online source (Planet):
Expand Down Expand Up @@ -186,19 +187,23 @@ Make sure to review the `gen-tiles-input.yml` file to understand the inputs and

## Inspect the outputs

Three easy ways to examine and inspect the MBTiles:
To examine and inspect MBTiles files:

1. Upload them to a [Felt](https://felt.com) map.
2. Use the [mbview](https://github.com/mapbox/mbview) tool to view them in the browser.
3. Load them in [QGIS](https://qgis.org).
1. Load them in [QGIS](https://qgis.org).
2. Open them in this [MBTiles Viewer](https://mbtiles-viewer.pages.dev/) webpage.
3. Upload them to a [Felt](https://felt.com) map.

## Formats other than MBTiles
To examine and inspect SMP files:

1. Open them in this [SMP Viewer](https://smp-viewer.pages.dev/) webpage.

## Formats other than MBTiles or SMP

In the future, we may decide to extend this tool to support creating raster tiles in a different format, such as XYZ or [PMTiles](https://github.com/protomaps/PMTiles). However, for the time being, you can use tools like [tippecanoe](https://github.com/felt/tippecanoe) or [go-pmtiles](https://github.com/protomaps/go-pmtiles) to convert the MBTiles outputs generated by this tool.

# For developers

Mapgl-tile-renderer uses [Maplibre-GL Native](https://www.npmjs.com/package/@maplibre/maplibre-gl-native) to render tiles, [Sharp](https://www.npmjs.com/package/sharp) to save them as an image, and Mapbox's [mbtiles Node package](https://www.npmjs.com/package/@mapbox/mbtiles) to compile them into an MBTiles database (which is a SQLite file).
Mapgl-tile-renderer uses [Maplibre-GL Native](https://www.npmjs.com/package/@maplibre/maplibre-gl-native) to render tiles, [Sharp](https://www.npmjs.com/package/sharp) to save them as an image, Mapbox's [mbtiles](https://www.npmjs.com/package/@mapbox/mbtiles) to compile them into an MBTiles database (which is a SQLite file), and Awana Digital's [styled-map-package](https://github.com/digidem/styled-map-package) to convert MBTiles to SMP.

## Node installation requirements

Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default {
},
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^styled-map-package/from-mbtiles$":
"<rootDir>/node_modules/styled-map-package/lib/from-mbtiles.js",
"^styled-map-package/writer$":
"<rootDir>/node_modules/styled-map-package/lib/writer.js",
},
transformIgnorePatterns: [], // Remove the ignore pattern to transform all modules
};
Loading

0 comments on commit e9c4bf4

Please sign in to comment.