Skip to content

Commit

Permalink
Add action to build tiles from input (#48)
Browse files Browse the repository at this point in the history
* Add action to build tiles from input

* Add instructions to README and add minzoom and overlay inputs

* Consistent use of field options

* Remove tiletype and radio

---------

Co-authored-by: rudokemper <rtakemper@gmail.com>
  • Loading branch information
luandro and rudokemper authored Mar 15, 2024
1 parent 6996f75 commit 8b4f079
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
74 changes: 74 additions & 0 deletions .github/workflows/gen-tiles-input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Generate Tiles from Input

on:
workflow_dispatch:
inputs:
style:
description: 'Map style to be used for tile generation. See readme for options.'
default: 'bing'
required: true
bounds:
description: 'Geographical bounds for the tile generation in "minLongitude,minLatitude,maxLongitude,maxLatitude" format'
default: '-54.28772,3.11460,-54.03630,3.35025'
required: true
maxzoom:
description: 'Maximum zoom level for which the tiles will be generated'
default: '15'
required: true
minzoom:
description: 'Minimum zoom level (optional, 0 if not provided)'
required: false
monthyear:
description: 'For Planet style, month and year for which the tiles are generated, in YYYY-MM format'
required: false
mapbox_style:
description: 'For Mapbox style, in the format <yourusername>/<styleid>'
required: false
openstreetmap:
description: 'Overlay OSM vector data on top of your imagery'
required: false
overlay:
description: 'GeoJSON object for a feature layer to overlay on top of the online source'
required: false
apiKeySecret:
description: 'API key'
required: false
filename:
description: 'Name of the output MBTiles file (optional, "output" if not provided)'
required: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate Tile Command
id: generate-tile-command
run: |
FILENAME="${{ github.event.inputs.filename }}"
STYLE="${{ github.event.inputs.style }}"
BOUNDS="${{ github.event.inputs.bounds }}"
MAXZOOM="${{ github.event.inputs.maxzoom }}"
MINZOOM="${{ github.event.inputs.minzoom }}"
COMMAND="--style $STYLE -Z $MAXZOOM --bounds $BOUNDS"
if [ -n "$FILENAME" ]; then COMMAND+=" -f $FILENAME"; fi
if [ -n "$OPENSTREETMAP" ]; then COMMAND+=" -O $OPENSTREETMAP"; fi
if [ -n "$MINZOOM" ]; then COMMAND+=" -z $MINZOOM"; fi
if [ -n "${{ github.event.inputs.apiKeySecret }}" ]; then
API_KEY=${!API_KEY_SECRET}
COMMAND+=" --apikey $API_KEY"
fi
if [ -n "${{ github.event.inputs.monthyear }}" ]; then COMMAND+=" --monthyear $MONTHYEAR"; fi
if [ -n "${{ github.event.inputs.mapbox_style }}" ]; then COMMAND+=" --mapboxstyle $MAPBOX_STYLE"; fi
if [ -n "${{ github.event.inputs.overlay }}" ]; then COMMAND+=" --overlay '${{ github.event.inputs.overlay }}'"; fi
echo "COMMAND=$COMMAND" >> $GITHUB_ENV
- name: Scrape tiles
run: |
docker run --rm -v ${{ github.workspace }}/outputs:/app/outputs communityfirst/mapgl-tile-renderer:main ${{ env.COMMAND }}
- name: Upload mbtiles file as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.inputs.name }}.mbtiles
path: outputs/*.mbtiles
if-no-files-found: error # 'warn' or 'ignore' are also available, 'error' will fail the step
retention-days: 90
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If using any of the imagery online styles ("bing", "esri", "google", "mapbox-sat
If your style is `mapbox`:
* `-m` or `--mapboxstyle` in the format `<yourusername>/<styleid>`

If your style is `planet-monthly-visual`:
If your style is `planet`:
* `-p` or `--monthyear`: The month and year (in YYYY-MM format) of the Planet Monthly Visual Basemap to use

Common options:
Expand Down Expand Up @@ -159,6 +159,21 @@ For Azure Storage Queue (and other queue services in the future), mapgl-tile-ren
}
```

## Running with Github Actions

To use the Github Actions workflow defined in `.github/workflows/gen-tiles-input.yml` for generating tiles, follow these steps:

1. Fork the repository containing the workflow file.
2. Navigate to your forked repository on Github.
3. Click on the "Actions" tab.
4. You will see a list of available workflows. Click on the "Generate Tiles from Input" workflow.
5. Click on the "Run workflow" dropdown button.
6. Fill in the required and optional input fields. See [CLI options](#cli-options) above for the list of fields.
7. After providing the necessary information in the input fields, click on the "Run workflow" button to initiate the tile generation process.
8. The workflow will execute the steps defined in `gen-tiles-input.yml` and upon completion, the generated tiles will be available as artifacts in the workflow run.

Make sure to review the `gen-tiles-input.yml` file to understand the inputs and outputs of the workflow.

# 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).
Expand Down

0 comments on commit 8b4f079

Please sign in to comment.