Skip to content

Commit

Permalink
Fix custom layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Dec 21, 2021
1 parent 8e2e367 commit 4b6769d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 23 deletions.
56 changes: 56 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
<link href="./css/mobile.css" rel="stylesheet"/>
<link href="./css/tagrendering.css" rel="stylesheet"/>
<link href="./css/index-tailwind-output.css" rel="stylesheet"/>
<meta content="website" property="og:type">

<title>MapComplete - page not found</title>
<link href="./index.manifest" rel="manifest">
<link href="./assets/svg/add.svg" rel="icon" sizes="any" type="image/svg+xml">
<meta content="MapComplete - Page not found" property="og:title">
<meta content="MapComplete is a platform to visualize OpenStreetMap on a specific topic and to easily contribute data back to it."
property="og:description">

<link href="./assets/generated/svg_mapcomplete_logo512.png" rel="apple-touch-icon" sizes="512x512">
<link href="./assets/generated/svg_mapcomplete_logo384.png" rel="apple-touch-icon" sizes="384x384">
<link href="./assets/generated/svg_mapcomplete_logo192.png" rel="apple-touch-icon" sizes="192x192">
<link href="./assets/generated/svg_mapcomplete_logo180.png" rel="apple-touch-icon" sizes="180x180">
<link href="./assets/generated/svg_mapcomplete_logo152.png" rel="apple-touch-icon" sizes="152x152">
<link href="./assets/generated/svg_mapcomplete_logo144.png" rel="apple-touch-icon" sizes="144x144">
<link href="./assets/generated/svg_mapcomplete_logo128.png" rel="apple-touch-icon" sizes="128x128">
<link href="./assets/generated/svg_mapcomplete_logo120.png" rel="apple-touch-icon" sizes="120x120">
<link href="./assets/generated/svg_mapcomplete_logo96.png" rel="apple-touch-icon" sizes="96x96">
<link href="./assets/generated/svg_mapcomplete_logo72.png" rel="apple-touch-icon" sizes="72x72">


<style>
#decoration-desktop img {
width: 100%;
height: 100%;
}
</style>

</head>
<body>

<div id="decoration-desktop" style="position: fixed; left: 1em; bottom: 1em; width:35vh; height:35vh;">
<!-- A nice decoration while loading or on errors -->
<!-- DECORATION 0 START -->
<img src="./assets/svg/add.svg"/>
<!-- DECORATION 0 END -->
</div>

<div class="clutter absolute h-24 left-24 right-24 top-56 text-xl text-center"
id="maindiv" style="z-index: 4000">
Not found...
</div>

<script src="./notfound.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"></script>

</body>
</html>
21 changes: 9 additions & 12 deletions Logic/DetermineLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions Models/ThemeConfig/LegacyJsonConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,21 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
}

if (config.tagRenderings !== undefined) {
let i =0;
for (const tagRendering of config.tagRenderings) {
i++;
if(typeof tagRendering === "string" || tagRendering["builtin"] !== undefined){
continue
}
if (tagRendering["id"] === undefined) {

if (tagRendering["#"] !== undefined) {
tagRendering["id"] = tagRendering["#"]
delete tagRendering["#"]
} else if (tagRendering["freeform"]?.key !== undefined) {
tagRendering["id"] = config.id + "-" + tagRendering["freeform"]["key"]
}else{
tagRendering["id"] = "tr-"+i
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ShowOverlayLayerImplementation.Implement();
Utils.DisableLongPresses()

class Init {
public static Init(layoutToUse: LayoutConfig, encoded: string) {
public static Init(layoutToUse: LayoutConfig) {

if (layoutToUse === null) {
// Something went wrong, error message is already on screen
Expand All @@ -41,14 +41,7 @@ class Init {
window.mapcomplete_state = State.state;
new DefaultGUI(State.state, guiState)

if (encoded !== undefined && encoded.length > 10) {
// We save the layout to the user settings and local storage
State.state.osmConnection.OnLoggedIn(() => {
State.state.osmConnection
.GetLongPreference("installed-theme-" + layoutToUse.id)
.setData(encoded);
});
}

}
}

Expand All @@ -67,7 +60,7 @@ new Combine(["Initializing... <br/>",
// @ts-ignore
DetermineLayout.GetLayout().then(value => {
console.log("Got ", value)
Init.Init(value[0], value[1])
Init.Init(value)
}).catch(err => {
console.error("Error while initializing: ", err, err.stack)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"deploy:production": "cd ~/git/mapcomplete.github.io/ && git pull && cd - && rm -rf ./assets/generated && npm run prepare-deploy && npm run optimize-images && rm -rf ~/git/mapcomplete.github.io/* && cp -r dist/* ~/git/mapcomplete.github.io/ && cd ~/git/mapcomplete.github.io/ && echo \"mapcomplete.osm.be\" > CNAME && git add * && git commit -m 'New MapComplete Version' && git push && cd - && npm run clean && npm run gittag",
"gittag": "ts-node scripts/printVersion.ts | bash",
"lint": "tslint --project . -c tslint.json '**.ts' ",
"clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | xargs rm)",
"clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404\\|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | xargs rm)",
"generate:dependency-graph": "node_modules/.bin/depcruise --exclude \"^node_modules\" --output-type dot Logic/State/MapState.ts > dependencies.dot && dot dependencies.dot -T svg -o dependencies.svg && rm dependencies.dot",
"genPostal": " ts-node ./scripts/postal_code_tools/createRoutablePoint.ts /home/pietervdvn/Downloads/postal_codes/postal_codes_town_hall_points.geojson /home/pietervdvn/Downloads/31370/Postcodes.geojson\n"
},
Expand Down

0 comments on commit 4b6769d

Please sign in to comment.