Last active
February 13, 2019 03:01
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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