2020-08-22 02:12:46 +02:00
|
|
|
import {TagRendering} from "./Customizations/TagRendering";
|
2020-06-24 00:35:19 +02:00
|
|
|
import {UserBadge} from "./UI/UserBadge";
|
|
|
|
import {CenterMessageBox} from "./UI/CenterMessageBox";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {TagUtils} from "./Logic/TagsFilter";
|
2020-07-21 02:55:28 +02:00
|
|
|
import {FullScreenMessageBoxHandler} from "./UI/FullScreenMessageBoxHandler";
|
2020-06-27 03:06:51 +02:00
|
|
|
import {FeatureInfoBox} from "./UI/FeatureInfoBox";
|
2020-06-29 03:12:44 +02:00
|
|
|
import {SimpleAddUI} from "./UI/SimpleAddUI";
|
2020-07-01 02:12:33 +02:00
|
|
|
import {SearchAndGo} from "./UI/SearchAndGo";
|
2020-07-05 18:59:47 +02:00
|
|
|
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {Layout} from "./Customizations/Layout";
|
2020-07-21 00:07:04 +02:00
|
|
|
import {FixedUiElement} from "./UI/Base/FixedUiElement";
|
2020-07-29 15:05:19 +02:00
|
|
|
import {InitUiElements} from "./InitUiElements";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {StrayClickHandler} from "./Logic/Leaflet/StrayClickHandler";
|
|
|
|
import {GeoLocationHandler} from "./Logic/Leaflet/GeoLocationHandler";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {State} from "./State";
|
2020-07-31 16:17:16 +02:00
|
|
|
import {CustomLayout} from "./Logic/CustomLayers";
|
2020-08-08 17:50:43 +02:00
|
|
|
import {CustomLayoutFromJSON} from "./Customizations/JSON/CustomLayoutFromJSON";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {QueryParameters} from "./Logic/Web/QueryParameters";
|
2020-08-23 01:49:19 +02:00
|
|
|
import {LocalStorageSource} from "./Logic/Web/LocalStorageSource";
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-08-22 02:12:46 +02:00
|
|
|
TagRendering.injectFunction();
|
|
|
|
|
2020-07-11 11:50:03 +02:00
|
|
|
|
2020-07-24 01:12:57 +02:00
|
|
|
// --------------------- Special actions based on the parameters -----------------
|
2020-07-11 11:50:03 +02:00
|
|
|
|
2020-07-12 23:19:05 +02:00
|
|
|
// @ts-ignore
|
2020-07-15 14:03:44 +02:00
|
|
|
if (location.href.startsWith("http://buurtnatuur.be")) {
|
2020-07-11 11:50:03 +02:00
|
|
|
// Reload the https version. This is important for the 'locate me' button
|
2020-07-15 14:03:44 +02:00
|
|
|
window.location.replace("https://buurtnatuur.be");
|
2020-07-11 11:50:03 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 03:39:31 +02:00
|
|
|
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
|
|
|
|
// Set to true if testing and changes should NOT be saved
|
2020-07-29 15:05:19 +02:00
|
|
|
const testing = QueryParameters.GetQueryParameter("test", "true");
|
2020-07-24 13:46:03 +02:00
|
|
|
testing.setData(testing.data ?? "true")
|
2020-06-25 03:39:31 +02: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 18:57:07 +02:00
|
|
|
//Overpass.testUrl = "http://127.0.0.1:8080/streetwidths.geojson";
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|
2020-06-24 00:35:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------- SELECT THE RIGHT QUESTSET -----------------
|
|
|
|
|
2020-08-08 02:16:42 +02:00
|
|
|
let defaultLayout = "bookcases"
|
2020-08-08 17:50:43 +02:00
|
|
|
let hash = window.location.hash;
|
2020-07-13 16:18:04 +02:00
|
|
|
|
2020-07-26 02:01:34 +02:00
|
|
|
const path = window.location.pathname.split("/").slice(-1)[0];
|
|
|
|
if (path !== "index.html") {
|
|
|
|
defaultLayout = path.substr(0, path.length - 5);
|
|
|
|
console.log("Using", defaultLayout)
|
|
|
|
}
|
2020-07-15 13:15:36 +02: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 16:18:04 +02:00
|
|
|
for (const k in AllKnownLayouts.allSets) {
|
|
|
|
const layout = AllKnownLayouts.allSets[k];
|
|
|
|
const possibleParts = layout.locationContains ?? [];
|
|
|
|
for (const locationMatch of possibleParts) {
|
2020-07-15 13:15:36 +02:00
|
|
|
if (locationMatch === "") {
|
2020-07-13 16:18:04 +02:00
|
|
|
continue
|
|
|
|
}
|
2020-07-15 13:15:36 +02:00
|
|
|
if (window.location.href.toLowerCase().indexOf(locationMatch.toLowerCase()) >= 0) {
|
|
|
|
defaultLayout = layout.name;
|
2020-07-13 16:18:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:05:19 +02:00
|
|
|
defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout).data;
|
2020-07-05 18:59:47 +02:00
|
|
|
|
2020-08-08 17:50:43 +02:00
|
|
|
let layoutToUse: Layout = AllKnownLayouts.allSets[defaultLayout] ?? AllKnownLayouts["all"];
|
|
|
|
|
|
|
|
|
2020-08-25 14:28:43 +02:00
|
|
|
const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false");
|
|
|
|
const layoutFromBase64 = userLayoutParam.data;
|
2020-08-22 02:12:46 +02:00
|
|
|
if (layoutFromBase64 !== "false") {
|
|
|
|
try {
|
2020-08-25 14:28:43 +02:00
|
|
|
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
|
|
|
|
|
|
|
|
const dedicatedHashFromLocalStorage = LocalStorageSource.Get("user-layout-" + layoutFromBase64.replace(" ", "_"));
|
|
|
|
if(dedicatedHashFromLocalStorage.data?.length < 10){
|
|
|
|
dedicatedHashFromLocalStorage.setData(undefined);
|
|
|
|
}
|
|
|
|
|
2020-08-23 01:49:19 +02:00
|
|
|
const hashFromLocalStorage = LocalStorageSource.Get("last-loaded-user-layout");
|
2020-08-25 14:28:43 +02:00
|
|
|
if (hash.length < 10) {
|
|
|
|
hash = dedicatedHashFromLocalStorage.data ?? hashFromLocalStorage.data;
|
|
|
|
} else {
|
2020-08-23 01:49:19 +02:00
|
|
|
console.log("Saving hash to local storage")
|
|
|
|
hashFromLocalStorage.setData(hash);
|
2020-08-25 14:28:43 +02:00
|
|
|
dedicatedHashFromLocalStorage.setData(hash);
|
2020-08-23 01:49:19 +02:00
|
|
|
}
|
2020-08-22 02:12:46 +02:00
|
|
|
layoutToUse = CustomLayoutFromJSON.FromQueryParam(hash.substr(1));
|
2020-08-25 14:28:43 +02:00
|
|
|
userLayoutParam.setData(layoutToUse.name);
|
2020-08-22 02:12:46 +02:00
|
|
|
} catch (e) {
|
|
|
|
new FixedUiElement("Error: could not parse the custom layout:<br/> "+e).AttachTo("centermessage");
|
|
|
|
throw e;
|
|
|
|
}
|
2020-08-08 17:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (layoutToUse === undefined) {
|
2020-07-26 02:01:34 +02:00
|
|
|
console.log("Incorrect layout")
|
2020-07-31 18:07:55 +02:00
|
|
|
new FixedUiElement("Error: incorrect layout <i>" + defaultLayout + "</i><br/><a href='https://pietervdvn.github.io/MapComplete/index.html'>Go back</a>").AttachTo("centermessage").onClick(() => {
|
2020-07-31 04:58:58 +02:00
|
|
|
});
|
|
|
|
throw "Incorrect layout"
|
2020-07-26 02:01:34 +02:00
|
|
|
}
|
2020-07-15 13:15:36 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
console.log("Using layout: ", layoutToUse.name);
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
State.state = new State(layoutToUse);
|
2020-08-22 02:12:46 +02:00
|
|
|
if (layoutFromBase64 !== "false") {
|
2020-08-08 21:17:17 +02:00
|
|
|
State.state.layoutDefinition = hash.substr(1);
|
2020-08-08 21:49:39 +02:00
|
|
|
console.log(State.state.layoutDefinition)
|
2020-08-08 21:17:17 +02:00
|
|
|
}
|
2020-07-31 17:38:03 +02:00
|
|
|
InitUiElements.InitBaseMap();
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-31 18:48:37 +02:00
|
|
|
new FixedUiElement("").AttachTo("decoration"); // Remove the decoration
|
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
function setupAllLayerElements() {
|
2020-07-29 15:05:19 +02:00
|
|
|
|
2020-07-31 18:48:37 +02:00
|
|
|
// ------------- Setup the layers -------------------------------
|
2020-07-29 19:43:15 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
InitUiElements.InitLayers();
|
|
|
|
InitUiElements.InitLayerSelection();
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-22 17:54:59 +02:00
|
|
|
|
2020-07-31 18:48:37 +02:00
|
|
|
// ------------------ Setup various other UI elements ------------
|
2020-07-22 17:54:59 +02:00
|
|
|
|
2020-07-29 18:35:46 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
InitUiElements.OnlyIf(State.state.featureSwitchAddNew, () => {
|
2020-08-22 02:12:46 +02:00
|
|
|
|
|
|
|
let presetCount = 0;
|
|
|
|
for (const layer of State.state.filteredLayers.data) {
|
|
|
|
for (const preset of layer.layerDef.presets) {
|
|
|
|
presetCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (presetCount == 0) {
|
|
|
|
console.log("No presets defined - not creating the StrayClickHandler");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
new StrayClickHandler(() => {
|
2020-07-31 16:17:16 +02:00
|
|
|
return new SimpleAddUI();
|
2020-07-31 04:58:58 +02:00
|
|
|
}
|
|
|
|
);
|
2020-07-29 18:35:46 +02:00
|
|
|
});
|
2020-07-31 01:45:54 +02:00
|
|
|
|
2020-08-22 02:12:46 +02:00
|
|
|
new CenterMessageBox().AttachTo("centermessage");
|
2020-07-24 01:12:57 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
}
|
2020-07-21 00:07:04 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
setupAllLayerElements();
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
if (layoutToUse === AllKnownLayouts.allSets[CustomLayout.NAME]) {
|
2020-07-31 04:58:58 +02:00
|
|
|
State.state.favourteLayers.addCallback((favs) => {
|
2020-07-31 16:17:16 +02:00
|
|
|
layoutToUse.layers = [];
|
2020-07-31 04:58:58 +02:00
|
|
|
for (const fav of favs) {
|
|
|
|
const layer = AllKnownLayouts.allLayers[fav];
|
|
|
|
if (!!layer) {
|
|
|
|
layoutToUse.layers.push(layer);
|
|
|
|
}
|
|
|
|
setupAllLayerElements();
|
2020-07-31 16:17:16 +02:00
|
|
|
};
|
|
|
|
State.state.locationControl.ping();
|
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
})
|
|
|
|
}
|
2020-07-29 15:05:19 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
/**
|
2020-07-24 01:12:57 +02:00
|
|
|
* Show the questions and information for the selected element
|
|
|
|
* This is given to the div which renders fullscreen on mobile devices
|
2020-06-27 03:06:51 +02:00
|
|
|
*/
|
2020-07-31 01:45:54 +02:00
|
|
|
State.state.selectedElement.addCallback((feature) => {
|
2020-07-29 19:43:15 +02:00
|
|
|
if (feature?.feature?.properties === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-22 01:07:32 +02:00
|
|
|
const data = feature.feature.properties;
|
2020-06-29 03:12:44 +02:00
|
|
|
// Which is the applicable set?
|
2020-07-15 13:15:36 +02:00
|
|
|
for (const layer of layoutToUse.layers) {
|
2020-06-29 03:12:44 +02:00
|
|
|
|
|
|
|
const applicable = layer.overpassFilter.matches(TagUtils.proprtiesToKV(data));
|
|
|
|
if (applicable) {
|
|
|
|
// This layer is the layer that gives the questions
|
2020-07-21 00:07:04 +02:00
|
|
|
|
|
|
|
const featureBox = new FeatureInfoBox(
|
2020-07-22 01:07:32 +02:00
|
|
|
feature.feature,
|
2020-07-31 01:45:54 +02:00
|
|
|
State.state.allElements.getElement(data.id),
|
2020-07-21 00:07:04 +02:00
|
|
|
layer.title,
|
|
|
|
layer.elementsToShow,
|
|
|
|
);
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
State.state.fullScreenMessage.setData(featureBox);
|
2020-06-29 03:12:44 +02:00
|
|
|
break;
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
);
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
InitUiElements.OnlyIf(State.state.featureSwitchUserbadge, () => {
|
|
|
|
new UserBadge().AttachTo('userbadge');
|
2020-07-25 18:00:08 +02:00
|
|
|
});
|
2020-07-24 01:12:57 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
InitUiElements.OnlyIf((State.state.featureSwitchSearch), () => {
|
|
|
|
new SearchAndGo().AttachTo("searchbox");
|
2020-07-29 15:05:19 +02:00
|
|
|
});
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
new FullScreenMessageBoxHandler(() => {
|
|
|
|
State.state.selectedElement.setData(undefined)
|
2020-07-21 02:55:28 +02:00
|
|
|
}).update();
|
2020-07-24 15:52:21 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
InitUiElements.OnlyIf(State.state.featureSwitchWelcomeMessage, () => {
|
|
|
|
InitUiElements.InitWelcomeMessage()
|
2020-07-29 15:05:19 +02:00
|
|
|
});
|
|
|
|
|
2020-08-08 14:43:48 +02:00
|
|
|
if ((window != window.top && !State.state.featureSwitchWelcomeMessage.data) || State.state.featureSwitchIframe.data) {
|
2020-08-08 15:01:22 +02:00
|
|
|
const currentLocation = State.state.locationControl;
|
|
|
|
const url = `${window.location.origin}${window.location.pathname}?z=${currentLocation.data.zoom}&lat=${currentLocation.data.lat}&lon=${currentLocation.data.lon}`;
|
2020-08-08 15:21:16 +02:00
|
|
|
const content = `<a href='${url}' target='_blank'><span class='iframe-escape'><img src='assets/pop-out.svg'></span></a>`;
|
|
|
|
new FixedUiElement(content).AttachTo("messagesbox");
|
|
|
|
new FixedUiElement(content).AttachTo("help-button-mobile")
|
2020-07-29 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 02:55:28 +02:00
|
|
|
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
new GeoLocationHandler().AttachTo("geolocate-button");
|