Skip to content

Instantly share code, notes, and snippets.

@chriswhong
Last active February 13, 2019 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswhong/bf54a051916e2b8c376ec194873b36d1 to your computer and use it in GitHub Desktop.
Save chriswhong/bf54a051916e2b8c376ec194873b36d1 to your computer and use it in GitHub Desktop.
Push any mapboxGL map style to maputnik using planning labs' maputnik-push service
// this will only work if window.map === your mapboxgl map instance
// we usually set window.map = map in the callback using map.on('style.load', function () { ... })
fetch('https://maputnik-push.planninglabs.nyc/style', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(window.map.getStyle()),
})
.then(d => d.json())
.then((res) => {
const { styleid } = res;
console.log(`https://maputnik.github.io/editor/?style=https://maputnik-push.planninglabs.nyc/style/${styleid}#${window.map.getZoom()}/${window.map.getCenter().lat}/${window.map.getCenter().lng}`, '_blank');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment