improved way of getting hash parameters
This commit is contained in:
parent
b5887bceb4
commit
934a59e59f
@ -45,21 +45,28 @@ class UrlManager {
|
||||
}
|
||||
|
||||
public getStartLayerNameFromUrl(): string | null {
|
||||
const hash = window.location.hash;
|
||||
let layerName = null;
|
||||
if (hash.length > 1) {
|
||||
layerName = hash.includes("&") ? hash.split("&")[0].substring(1) : hash.substring(1);
|
||||
const parameters = this.getHashParameters();
|
||||
for (const key in parameters) {
|
||||
if (parameters[key] === undefined) {
|
||||
return key;
|
||||
}
|
||||
return layerName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getHashParameter(name: string): string | undefined {
|
||||
const parameters = window.location.hash.split("&").reduce((res: Record<string, string>, item: string) => {
|
||||
return this.getHashParameters()[name];
|
||||
}
|
||||
|
||||
private getHashParameters(): Record<string, string> {
|
||||
return window.location.hash
|
||||
.substring(1)
|
||||
.split("&")
|
||||
.reduce((res: Record<string, string>, item: string) => {
|
||||
const parts = item.split("=");
|
||||
res[parts[0]] = parts[1];
|
||||
return res;
|
||||
}, {});
|
||||
return parameters[name];
|
||||
}
|
||||
|
||||
pushStartLayerNameToUrl(startLayerName: string): void {
|
||||
|
@ -44,6 +44,12 @@
|
||||
"id":8,
|
||||
"name":"exit",
|
||||
"opacity":1,
|
||||
"properties":[
|
||||
{
|
||||
"name":"startLayer",
|
||||
"type":"bool",
|
||||
"value":true
|
||||
}],
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":10,
|
||||
|
Loading…
Reference in New Issue
Block a user