Skip to content

Instantly share code, notes, and snippets.

@samanpwbb
Last active January 22, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samanpwbb/5db434404342ba359f54501d59040ee9 to your computer and use it in GitHub Desktop.
Save samanpwbb/5db434404342ba359f54501d59040ee9 to your computer and use it in GitHub Desktop.

Did you know that mapbox-gl-native supports high resolution exports? It's true. Follow these steps to enable.

  1. Open the console.
  2. Check out mapbox gl native with git clone git@github.com:mapbox/mapbox-gl-native.git
  3. Run make render which kicks off the build process for a CLI tool for making images. After make render succeeds, the CLI tool will be located at ./build/macos/Debug/mbgl-render.
  4. 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
  1. Download the style JSON you want to make an image from.
  2. 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.
  3. 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:

img-3


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 use rendermap -s ./style.json.
  • Right now this is undocumented in mapbox gl native.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment