2020-07-05 16:59:47 +00:00
|
|
|
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
|
2020-07-29 22:59:08 +00:00
|
|
|
import {Layout} from "./Customizations/Layout";
|
2020-07-20 22:07:04 +00:00
|
|
|
import {FixedUiElement} from "./UI/Base/FixedUiElement";
|
2020-07-29 13:05:19 +00:00
|
|
|
import {InitUiElements} from "./InitUiElements";
|
2020-08-17 15:23:15 +00:00
|
|
|
import {QueryParameters} from "./Logic/Web/QueryParameters";
|
2020-09-05 15:43:30 +00:00
|
|
|
import {UIEventSource} from "./Logic/UIEventSource";
|
2020-09-07 00:25:45 +00:00
|
|
|
import * as $ from "jquery";
|
|
|
|
import {FromJSON} from "./Customizations/JSON/FromJSON";
|
2020-09-10 17:33:06 +00:00
|
|
|
import {TagRendering} from "./UI/TagRendering";
|
2020-06-23 22:35:19 +00:00
|
|
|
|
2020-08-22 00:12:46 +00:00
|
|
|
TagRendering.injectFunction();
|
|
|
|
|
2020-07-11 09:50:03 +00:00
|
|
|
|
2020-07-23 23:12:57 +00:00
|
|
|
// --------------------- Special actions based on the parameters -----------------
|
2020-07-12 21:19:05 +00:00
|
|
|
// @ts-ignore
|
2020-07-15 12:03:44 +00:00
|
|
|
if (location.href.startsWith("http://buurtnatuur.be")) {
|
2020-07-11 09:50:03 +00:00
|
|
|
// Reload the https version. This is important for the 'locate me' button
|
2020-07-15 12:03:44 +00:00
|
|
|
window.location.replace("https://buurtnatuur.be");
|
2020-07-11 09:50:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 15:43:30 +00:00
|
|
|
let testing: UIEventSource<string>;
|
2020-06-25 01:39:31 +00:00
|
|
|
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
|
2020-09-05 15:43:30 +00:00
|
|
|
testing = QueryParameters.GetQueryParameter("test", "true");
|
2020-06-25 01:39:31 +00:00
|
|
|
// Set to true if testing and changes should NOT be saved
|
2020-07-24 11:46:03 +00:00
|
|
|
testing.setData(testing.data ?? "true")
|
2020-06-25 01:39:31 +00:00
|
|
|
// If you have a testfile somewhere, enable this to spoof overpass
|
|
|
|
// This should be hosted independantly, e.g. with `cd assets; webfsd -p 8080` + a CORS plugin to disable cors rules
|
2020-07-17 16:57:07 +00:00
|
|
|
//Overpass.testUrl = "http://127.0.0.1:8080/streetwidths.geojson";
|
2020-09-05 15:43:30 +00:00
|
|
|
} else {
|
|
|
|
testing = QueryParameters.GetQueryParameter("test", "false");
|
2020-06-25 01:39:31 +00:00
|
|
|
}
|
2020-06-23 22:35:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------- SELECT THE RIGHT QUESTSET -----------------
|
|
|
|
|
2020-08-08 00:16:42 +00:00
|
|
|
let defaultLayout = "bookcases"
|
2020-07-13 14:18:04 +00:00
|
|
|
|
2020-07-26 00:01:34 +00:00
|
|
|
const path = window.location.pathname.split("/").slice(-1)[0];
|
2020-09-11 17:14:32 +00:00
|
|
|
if (path !== "index.html" && path !== "") {
|
2020-07-26 00:01:34 +00:00
|
|
|
defaultLayout = path.substr(0, path.length - 5);
|
2020-09-11 17:14:32 +00:00
|
|
|
console.log("Using layout", defaultLayout);
|
2020-07-26 00:01:34 +00:00
|
|
|
}
|
2020-07-15 11:15:36 +00:00
|
|
|
|
|
|
|
// Run over all questsets. If a part of the URL matches a searched-for part in the layout, it'll take that as the default
|
2020-07-13 14:18:04 +00:00
|
|
|
for (const k in AllKnownLayouts.allSets) {
|
|
|
|
const layout = AllKnownLayouts.allSets[k];
|
2020-08-28 01:16:21 +00:00
|
|
|
const possibleParts = (layout.locationContains ?? []);
|
2020-07-13 14:18:04 +00:00
|
|
|
for (const locationMatch of possibleParts) {
|
2020-07-15 11:15:36 +00:00
|
|
|
if (locationMatch === "") {
|
2020-07-13 14:18:04 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-07-15 11:15:36 +00:00
|
|
|
if (window.location.href.toLowerCase().indexOf(locationMatch.toLowerCase()) >= 0) {
|
|
|
|
defaultLayout = layout.name;
|
2020-07-13 14:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 13:05:19 +00:00
|
|
|
defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout).data;
|
2020-07-05 16:59:47 +00:00
|
|
|
|
2020-08-28 01:16:21 +00:00
|
|
|
let layoutToUse: Layout = AllKnownLayouts.allSets[defaultLayout.toLowerCase()] ?? AllKnownLayouts["all"];
|
2020-08-08 15:50:43 +00:00
|
|
|
|
|
|
|
|
2020-08-25 12:28:43 +00:00
|
|
|
const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false");
|
2020-09-07 00:25:45 +00:00
|
|
|
const layoutFromBase64 = decodeURIComponent(userLayoutParam.data);
|
|
|
|
if (layoutFromBase64.startsWith("wiki:")) {
|
|
|
|
console.log("Downloading map theme from the wiki");
|
|
|
|
const themeName = layoutFromBase64.substr("wiki:".length);
|
|
|
|
new FixedUiElement(`Downloading ${themeName} from the wiki...`)
|
|
|
|
.AttachTo("centermessage");
|
2020-09-14 22:25:25 +00:00
|
|
|
const cleanUrl = `https://wiki.openstreetmap.org/wiki/${themeName}`;
|
2020-09-07 00:25:45 +00:00
|
|
|
const url = `https://cors-anywhere.herokuapp.com/` + cleanUrl; // VERY SAFE AND HACKER-PROOF!
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: 'xml',
|
|
|
|
success: function (data) {
|
|
|
|
const layoutJson = data.querySelector('[id="bodyContent"]')
|
|
|
|
.querySelector('[class="mw-parser-output"]')
|
|
|
|
.children[0]
|
|
|
|
.firstChild.textContent;
|
|
|
|
try {
|
|
|
|
console.log("DOWNLOADED:",layoutJson);
|
|
|
|
const layout = FromJSON.LayoutFromJSON(JSON.parse(layoutJson));
|
2020-09-14 22:25:25 +00:00
|
|
|
layout.id = layoutFromBase64;
|
2020-09-07 00:25:45 +00:00
|
|
|
InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64);
|
|
|
|
} catch (e) {
|
|
|
|
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`)
|
|
|
|
.SetClass("clickable")
|
|
|
|
.AttachTo("centermessage");
|
|
|
|
throw e;
|
2020-07-31 02:58:58 +00:00
|
|
|
}
|
2020-09-07 00:25:45 +00:00
|
|
|
},
|
|
|
|
}).fail(e => {
|
|
|
|
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>Could not download - wrong URL?`)
|
|
|
|
.SetClass("clickable")
|
|
|
|
.AttachTo("centermessage");
|
2020-07-29 16:35:46 +00:00
|
|
|
});
|
2020-07-30 23:45:54 +00:00
|
|
|
|
2020-09-14 22:25:25 +00:00
|
|
|
} else if (layoutFromBase64 !== "false") {
|
|
|
|
layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam);
|
|
|
|
InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
|
2020-09-07 00:25:45 +00:00
|
|
|
} else {
|
|
|
|
InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
|
2020-07-29 13:05:19 +00:00
|
|
|
}
|