forked from MapComplete/MapComplete
Fix custom layouts
This commit is contained in:
parent
8e2e367a0c
commit
4b6769d601
5 changed files with 76 additions and 23 deletions
|
@ -20,23 +20,18 @@ export default class DetermineLayout {
|
|||
/**
|
||||
* Gets the correct layout for this website
|
||||
*/
|
||||
public static async GetLayout(): Promise<[LayoutConfig, string]> {
|
||||
public static async GetLayout(): Promise<LayoutConfig> {
|
||||
|
||||
const loadCustomThemeParam = QueryParameters.GetQueryParameter("userlayout", "false", "If not 'false', a custom (non-official) theme is loaded. This custom layout can be done in multiple ways: \n\n- The hash of the URL contains a base64-encoded .json-file containing the theme definition\n- The hash of the URL contains a lz-compressed .json-file, as generated by the custom theme generator\n- The parameter itself is an URL, in which case that URL will be downloaded. It should point to a .json of a theme")
|
||||
const layoutFromBase64 = decodeURIComponent(loadCustomThemeParam.data);
|
||||
|
||||
if (layoutFromBase64.startsWith("http")) {
|
||||
const layout = await DetermineLayout.LoadRemoteTheme(layoutFromBase64)
|
||||
return [layout, undefined]
|
||||
return await DetermineLayout.LoadRemoteTheme(layoutFromBase64)
|
||||
}
|
||||
|
||||
if (layoutFromBase64 !== "false") {
|
||||
// We have to load something from the hash (or from disk)
|
||||
let loaded = DetermineLayout.LoadLayoutFromHash(loadCustomThemeParam);
|
||||
if (loaded === null) {
|
||||
return [null, undefined]
|
||||
}
|
||||
return loaded
|
||||
return DetermineLayout.LoadLayoutFromHash(loadCustomThemeParam)
|
||||
}
|
||||
|
||||
let layoutId: string = undefined
|
||||
|
@ -64,12 +59,12 @@ export default class DetermineLayout {
|
|||
}
|
||||
}
|
||||
|
||||
return [layoutToUse, undefined]
|
||||
return layoutToUse
|
||||
}
|
||||
|
||||
public static LoadLayoutFromHash(
|
||||
userLayoutParam: UIEventSource<string>
|
||||
): [LayoutConfig, string] | null {
|
||||
): LayoutConfig | null {
|
||||
let hash = location.hash.substr(1);
|
||||
try {
|
||||
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
|
||||
|
@ -109,7 +104,9 @@ export default class DetermineLayout {
|
|||
|
||||
const knownLayersDict = new Map<string, LayerConfigJson>()
|
||||
for (const key in known_layers["default"]) {
|
||||
knownLayersDict.set(key, known_layers["default"][key])
|
||||
const layer = known_layers["default"][key]
|
||||
console.log("Found shared layer "+layer.id)
|
||||
knownLayersDict.set(layer.id, layer)
|
||||
}
|
||||
|
||||
const converState = {
|
||||
|
@ -123,7 +120,7 @@ export default class DetermineLayout {
|
|||
|
||||
const layoutToUse = new LayoutConfig(json, false);
|
||||
userLayoutParam.setData(layoutToUse.id);
|
||||
return [layoutToUse, btoa(Utils.MinifyJSON(JSON.stringify(json)))];
|
||||
return layoutToUse;
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
if (hash === undefined || hash.length < 10) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue