improved way of getting hash parameters

This commit is contained in:
Hanusiak Piotr 2022-01-25 10:05:04 +01:00
parent b5887bceb4
commit 934a59e59f
2 changed files with 24 additions and 11 deletions

View File

@ -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 {

View File

@ -44,6 +44,12 @@
"id":8,
"name":"exit",
"opacity":1,
"properties":[
{
"name":"startLayer",
"type":"bool",
"value":true
}],
"type":"tilelayer",
"visible":true,
"width":10,