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 {
|
public getStartLayerNameFromUrl(): string | null {
|
||||||
const hash = window.location.hash;
|
const parameters = this.getHashParameters();
|
||||||
let layerName = null;
|
for (const key in parameters) {
|
||||||
if (hash.length > 1) {
|
if (parameters[key] === undefined) {
|
||||||
layerName = hash.includes("&") ? hash.split("&")[0].substring(1) : hash.substring(1);
|
return key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return layerName;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHashParameter(name: string): string | undefined {
|
public getHashParameter(name: string): string | undefined {
|
||||||
const parameters = window.location.hash.split("&").reduce((res: Record<string, string>, item: string) => {
|
return this.getHashParameters()[name];
|
||||||
const parts = item.split("=");
|
}
|
||||||
res[parts[0]] = parts[1];
|
|
||||||
return res;
|
private getHashParameters(): Record<string, string> {
|
||||||
}, {});
|
return window.location.hash
|
||||||
return parameters[name];
|
.substring(1)
|
||||||
|
.split("&")
|
||||||
|
.reduce((res: Record<string, string>, item: string) => {
|
||||||
|
const parts = item.split("=");
|
||||||
|
res[parts[0]] = parts[1];
|
||||||
|
return res;
|
||||||
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
pushStartLayerNameToUrl(startLayerName: string): void {
|
pushStartLayerNameToUrl(startLayerName: string): void {
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
"id":8,
|
"id":8,
|
||||||
"name":"exit",
|
"name":"exit",
|
||||||
"opacity":1,
|
"opacity":1,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"startLayer",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}],
|
||||||
"type":"tilelayer",
|
"type":"tilelayer",
|
||||||
"visible":true,
|
"visible":true,
|
||||||
"width":10,
|
"width":10,
|
||||||
|
Loading…
Reference in New Issue
Block a user