Skip to content

Commit

Permalink
Set up mbgl-tile-renderer to run as a task worker service (#17)
Browse files Browse the repository at this point in the history
* Initial work on Azure queue

* Use latest vars

* Small fixes

* WIP: get volume mount working

* Introduce and implement outputDir

* Cleanup and documentation

* Throw error if required values are undefined
  • Loading branch information
rudokemper authored Feb 1, 2024
1 parent a283f93 commit 522b582
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 27 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ To use these services, you are responsible for providing an API token as needed.

Please note that depending on your bounding box and maximum zoom level, this tool has the capability to send a lot of requests. You should first use a tool like the [Mapbox offline tile count estimator](https://docs.mapbox.com/playground/offline-estimator/) to ensure that your request will be reasonable, and in the case of any sources with an API limit, won't end up costing you.

## Usage

This tool can be used in the following ways:

* Via CLI (Node.js or Docker)
* As a task worker service to poll a queue for new requests.
* Currently supported: Azure Storage Queue.
* The tool may be extended with RabbitMQ for self-hosting in the future.

## CLI options

* `-s` or `--style`: Specify the style source. Use "self" for a self-provided style or one of the following for an online source: "bing", "esri", "google", "mapbox", "mapbox-satellite", "planet".
Expand All @@ -51,7 +60,8 @@ Common options:
* `-b` or `--bounds`: Bounding box in WSEN format, comma separated (required)
* `-z` or `--minzoom`: Minimum zoom level (0 if not provided)
* `-Z` or `--maxzoom`: Maximum zoom level (required)
* `-o` or `--output`: Name of the output mbtiles file
* `-o` or `--outputdir`: Output directory (default "outputs/")
* `-f` or `--filename`: Name of the output mbtiles file

## Example usage

Expand Down Expand Up @@ -86,12 +96,12 @@ Online source (Esri) with GeoJSON overlay:
$ node src/cli.js --style esri --apikey YOUR_API_KEY_HERE --bounds "-54.28772,3.11460,-54.03630,3.35025" -Z 13 --overlay '{"type": "FeatureCollection", "name": "alert", "features": [{"geometry": {"coordinates": [[[-54.25348208981326, 3.140689896338671], [-54.25348208981326, 3.140600064810259], [-54.253841415926914, 3.140600064810259], [-54.25348208981326, 3.140689896338671]]], "geodesic": false, "type": "Polygon"}, "id": "-603946+34961", "properties": {"month_detec": "09", "year_detec": "2023"}, "type": "Feature"}]}'
```

### With Docker
## Docker

To run with Docker simply run:
To run the tool with Docker, run:

```bash
docker run -it --rm -v "$(pwd)":/app/outputs communityfirst/mbgl-tile-renderer --style "no" --bounds "-54.28772,3.11460,-54.03630,3.35025" -Z 13 --onlinesource "mapbox-style" --mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE
docker run -it --rm -v "$(pwd)":/app/outputs communityfirst/mbgl-tile-renderer --style "mapbox" --bounds "-54.28772,3.11460,-54.03630,3.35025" -Z 13 --mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE
```

This automatically pulls the latest image from Docker hub. The `docker run` command is used to execute the mbgl-tile-renderer tool with a set of options that define how the map tiles will be rendered and saved. Here's a breakdown of the command and its variables:
Expand All @@ -111,8 +121,8 @@ docker build -t mbgl-tile-renderer .

Then run:

```
docker run -it --rm -v "$(pwd)":/app/outputs mbgl-tile-renderer --style "no" --bounds "-54.28772,3.11460,-54.03630,3.35025" -Z 13 --onlinesource "mapbox-style" --mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE
```bash
docker run -it --rm -v "$(pwd)":/app/outputs mbgl-tile-renderer --style "mapbox" --bounds "-54.28772,3.11460,-54.03630,3.35025" -Z 13--mapboxstyle YOUR_USERNAME/YOUR_MAPBOX_STYLE_ID --apikey YOUR_API_KEY_HERE
```

## Inspect the mbtile outputs
Expand Down
9 changes: 8 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ while ! xdpyinfo -display ${DISPLAY} > /dev/null 2>&1; do
done
echo "Xvfb is running"

node src/cli.js "$@"
# To run the Docker container as an Azure queue service, set the QueueName env var to "mappacker-requests"
if [ "$QueueName" = "mappacker-requests" ]; then
# Run the Azure queue service
node src/azure_queue_service.js
else
# Default to the CLI API
node src/cli.js "$@"
fi
195 changes: 195 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"mbgl-tile-renderer": "./src/cli.js"
},
"dependencies": {
"@azure/storage-queue": "^12.16.0",
"@mapbox/mbtiles": "^0.12.1",
"@maplibre/maplibre-gl-native": "^5.3.1",
"axios": "^1.6.5",
Expand Down
Loading

0 comments on commit 522b582

Please sign in to comment.