mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-03 23:11:45 +01:00
24 lines
630 B
JavaScript
24 lines
630 B
JavaScript
|
import request from 'request'
|
||
|
import url from 'url'
|
||
|
import style from './style.js'
|
||
|
|
||
|
export function initialStyleUrl() {
|
||
|
const initialUrl = url.parse(window.location.href, true)
|
||
|
return (initialUrl.query || {}).style
|
||
|
}
|
||
|
|
||
|
export function loadStyleUrl(styleUrl, cb) {
|
||
|
console.log('Loading style', styleUrl)
|
||
|
request({
|
||
|
url: styleUrl,
|
||
|
withCredentials: false,
|
||
|
}, (error, response, body) => {
|
||
|
if (!error && response.statusCode == 200) {
|
||
|
cb(style.ensureStyleValidity(JSON.parse(body)))
|
||
|
} else {
|
||
|
console.warn('Could not fetch default style', styleUrl)
|
||
|
cb(style.emptyStyle)
|
||
|
}
|
||
|
})
|
||
|
}
|