Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.