Render mapbox-gl styles as rasters
To install
npm install orangemug/mapbox-gl-to-blob
Example usage shown below
const mapboxGlToBlob = require("mapbox-gl-to-blob");
const opts = {
// See <https://www.mapbox.com/mapbox-gl-js/api/#map> for usage
mapboxGl: {
// Required arguments
style: "https://rawgit.com/lukasmartinelli/osm-liberty/gh-pages/style.json",
// Optional arguments (showing defaults)
pitch: 0,
zoom: 0,
center: [0,0],
bearing: 0,
},
output: {
dpi: 300,
dimensions: {
unit: "mm",
width: 300,
height: 300
}
}
}
mapboxGlToBlob
.toBlob(opts)
.then(function(pngBlob) {
// ...
})
Currently the best way to develop this library is via the ./examples
To start the examples just run
npm run examples
..and go to url printed in the terminal.
Although at the moment somewhat untested, it should work in all modern browsers. With the exception of IE which will require a polyfill, see