mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-29 06:40:25 +01:00
Remove style querystring parameter
This commit is contained in:
parent
3d2a1d5d19
commit
b0adb8cd3d
1 changed files with 18 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import url from 'url'
|
import url from 'url'
|
||||||
|
import querystring from 'querystring'
|
||||||
import style from './style.js'
|
import style from './style.js'
|
||||||
|
|
||||||
export function initialStyleUrl() {
|
export function initialStyleUrl() {
|
||||||
|
@ -24,6 +25,23 @@ export function loadStyleUrl(styleUrl, cb) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeStyleQuerystring() {
|
||||||
|
const initialUrl = url.parse(window.location.href, true)
|
||||||
|
let qs = querystring.parse(window.location.search.slice(1))
|
||||||
|
delete qs["style"]
|
||||||
|
if(Object.getOwnPropertyNames(qs).length === 0) {
|
||||||
|
qs = ""
|
||||||
|
} else {
|
||||||
|
qs = "?" + querystring.stringify(qs)
|
||||||
|
}
|
||||||
|
let newUrlHash = initialUrl.hash
|
||||||
|
if(newUrlHash === null) {
|
||||||
|
newUrlHash = ""
|
||||||
|
}
|
||||||
|
const newUrl = initialUrl.protocol + "//" + initialUrl.host + initialUrl.pathname + qs + newUrlHash
|
||||||
|
window.history.replaceState({}, document.title, newUrl)
|
||||||
|
}
|
||||||
|
|
||||||
export function loadJSON(url, defaultValue, cb) {
|
export function loadJSON(url, defaultValue, cb) {
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
|
Loading…
Reference in a new issue