Did you know that mapbox-gl-native supports high resolution exports? It's true. Follow these steps to enable.
- Open the console.
- Check out mapbox gl native with
git clone [email protected]:mapbox/mapbox-gl-native.git
- Run
make render
which kicks off the build process for a CLI tool for making images. Aftermake render
succeeds, the CLI tool will be located at./build/macos/Debug/mbgl-render
. - Type
./build/macos/Debug/mbgl-render
in the console. If you press return without any arguments, you'll see help output:
Allowed options:
-s [ --style ] json Map stylesheet
-x [ --lon ] degrees (=0) Longitude
-y [ --lat ] degrees (=0) Latitude in degrees
-z [ --zoom ] number (=0) Zoom level
-b [ --bearing ] degrees (=0) Bearing
-p [ --pitch ] degrees (=0) Pitch
-w [ --width ] pixels (=512) Image width
-h [ --height ] pixels (=512) Image height
-r [ --ratio ] number (=1) Image scale factor
-c [ --class ] name Class name
-t [ --token ] key Mapbox access token
--debug Debug mode
-o [ --output ] file (=out.png) Output file name
-d [ --cache ] file (=cache.sqlite) Cache database file name
-d [ --assets ] file (=.) Directory to which asset:// URLs will
resolve
- Download the style JSON you want to make an image from.
- Make sure there's a valid MAPBOX_ACCESS_TOKEN env variable in your terminal instance. Best to add one to your bash_profile, but can also be added by typing
export MAPBOX_ACCESS_TOKEN={yourtoken}
and pressing return. - use the command with at the minimum, the
-s
argument to point to the path to your style JSON, the-r
argument to make the image high resolution, and the-o
argument to save the output to a file. For example,./build/macos/Debug/mbgl-render -s ~/standard/style.json -r 3 -z 4 -o ~/standard/img.png
gives me this nice high resolution image of null island:
Notes:
- Printing Mapbox maps is subject to the Mapbox TOS.
- Check out our gallery of designer maps: https://www.mapbox.com/designer-maps/ – it's possible to print these ✨.
- The render command will automatically use fonts and icons from api styles, at the right resolution. No extra work required to get high res icons.
- It's possible to make an alias for the render function so you can use it anywhere. Add
alias rendermap='~/path/to/repos/mapbox-gl-native/build/macos/Debug/mbgl-render'
to your bash profile. Once you've done that, you can userendermap -s ./style.json
. - Right now this is undocumented in mapbox gl native.