| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  | import {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; | 
					
						
							| 
									
										
										
										
											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-08-17 17:23:15 +02:00
										 |  |  | import {QueryParameters} from "./Logic/Web/QueryParameters"; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:43:30 +02:00
										 |  |  | import {UIEventSource} from "./Logic/UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  | import * as $ from "jquery"; | 
					
						
							| 
									
										
										
										
											2020-11-11 16:23:49 +01:00
										 |  |  | import LayoutConfig from "./Customizations/JSON/LayoutConfig"; | 
					
						
							| 
									
										
										
										
											2020-11-14 03:26:09 +01:00
										 |  |  | import {Utils} from "./Utils"; | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | import MoreScreen from "./UI/BigComponents/MoreScreen"; | 
					
						
							|  |  |  | import State from "./State"; | 
					
						
							| 
									
										
										
										
											2021-01-22 01:03:50 +01:00
										 |  |  | import Combine from "./UI/Base/Combine"; | 
					
						
							|  |  |  | import Translations from "./UI/i18n/Translations"; | 
					
						
							| 
									
										
										
										
											2020-08-22 02:12:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 02:45:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import CountryCoder from "latlon2country" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import MetaTagging from "./Logic/MetaTagging"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Workaround for a stupid crash: inject the function
 | 
					
						
							|  |  |  | MetaTagging.coder = new CountryCoder("https://pietervdvn.github.io/latlon2country/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | let defaultLayout = "" | 
					
						
							| 
									
										
										
										
											2020-07-24 01:12:57 +02:00
										 |  |  | // --------------------- Special actions based on the parameters -----------------
 | 
					
						
							| 
									
										
										
										
											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-11-06 01:58:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 22:23:49 +02:00
										 |  |  | if (location.href.indexOf("buurtnatuur.be") >= 0) { | 
					
						
							|  |  |  |     defaultLayout = "buurtnatuur" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-14 03:26:09 +01:00
										 |  |  | const customCssQP = QueryParameters.GetQueryParameter("custom-css", "", "If specified, the custom css from the given link will be loaded additionaly"); | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | if (customCssQP.data !== undefined && customCssQP.data !== "") { | 
					
						
							| 
									
										
										
										
											2020-11-14 03:26:09 +01:00
										 |  |  |     Utils.LoadCustomCss(customCssQP.data); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-18 22:23:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 13:13:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:43:30 +02:00
										 |  |  | let testing: UIEventSource<string>; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { | 
					
						
							| 
									
										
										
										
											2020-09-05 17:43:30 +02:00
										 |  |  |     testing = QueryParameters.GetQueryParameter("test", "true"); | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |     // Set to true if testing and changes should NOT be saved
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							| 
									
										
										
										
											2021-01-02 21:03:40 +01:00
										 |  |  |     // Overpass.testUrl = "http://127.0.0.1:8080/streetwidths.geojson";
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:43:30 +02:00
										 |  |  | } else { | 
					
						
							|  |  |  |     testing = QueryParameters.GetQueryParameter("test", "false"); | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ----------------- SELECT THE RIGHT QUESTSET -----------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 22:23:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 02:01:34 +02:00
										 |  |  | const path = window.location.pathname.split("/").slice(-1)[0]; | 
					
						
							| 
									
										
										
										
											2020-09-11 19:14:32 +02:00
										 |  |  | if (path !== "index.html" && path !== "") { | 
					
						
							| 
									
										
										
										
											2020-12-18 12:16:56 +01:00
										 |  |  |     defaultLayout = path; | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |     if (path.endsWith(".html")) { | 
					
						
							| 
									
										
										
										
											2020-12-18 12:16:56 +01:00
										 |  |  |         defaultLayout = path.substr(0, path.length - 5); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-11 19:14:32 +02:00
										 |  |  |     console.log("Using layout", defaultLayout); | 
					
						
							| 
									
										
										
										
											2020-07-26 02:01:34 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout, "The layout to load into MapComplete").data; | 
					
						
							|  |  |  | let layoutToUse: LayoutConfig = AllKnownLayouts.allSets[defaultLayout.toLowerCase()]; | 
					
						
							| 
									
										
										
										
											2020-08-08 17:50:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 14:28:43 +02:00
										 |  |  | const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false"); | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  | const layoutFromBase64 = decodeURIComponent(userLayoutParam.data); | 
					
						
							| 
									
										
										
										
											2021-01-18 19:36:19 +01:00
										 |  |  | document.getElementById('centermessage').innerText = ''; | 
					
						
							|  |  |  | document.getElementById("decoration-desktop").remove(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 02:37:47 +01:00
										 |  |  | if (layoutFromBase64.startsWith("http")) { | 
					
						
							|  |  |  |     const link = layoutFromBase64; | 
					
						
							|  |  |  |     console.log("Downloading map theme from ", link); | 
					
						
							|  |  |  |     new FixedUiElement(`Downloading the theme from the <a href="${link}">link</a>...`) | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |         .AttachTo("centermessage"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							| 
									
										
										
										
											2021-02-20 02:37:47 +01:00
										 |  |  |         url: link, | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |         success: function (data) { | 
					
						
							| 
									
										
										
										
											2021-03-22 02:45:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |             try { | 
					
						
							| 
									
										
										
										
											2020-11-17 18:23:40 +01:00
										 |  |  |                 const parsed = JSON.parse(data); | 
					
						
							| 
									
										
										
										
											2021-01-15 01:57:46 +01:00
										 |  |  |                 // Overwrite the id to the wiki:value
 | 
					
						
							| 
									
										
										
										
											2021-02-20 02:37:47 +01:00
										 |  |  |                 parsed.id = link; | 
					
						
							| 
									
										
										
										
											2020-11-17 18:23:40 +01:00
										 |  |  |                 const layout = new LayoutConfig(parsed); | 
					
						
							|  |  |  |                 InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64, btoa(data)); | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |             } catch (e) { | 
					
						
							| 
									
										
										
										
											2021-02-20 02:37:47 +01:00
										 |  |  |                 new FixedUiElement(`<a href="${link}">${link}</a> is invalid:<br/>${e}<br/> <a href='https://${window.location.host}/'>Go back</a>")`) | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |                     .SetClass("clickable") | 
					
						
							|  |  |  |                     .AttachTo("centermessage"); | 
					
						
							| 
									
										
										
										
											2021-01-09 00:29:12 +01:00
										 |  |  |                 console.error("Could not parse the text", data) | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |                 throw e; | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-01-15 01:57:46 +01:00
										 |  |  |     }).fail((_, textstatus, error) => { | 
					
						
							|  |  |  |         console.error("Could not download the wiki theme:", textstatus, error) | 
					
						
							| 
									
										
										
										
											2021-02-20 02:37:47 +01:00
										 |  |  |         new FixedUiElement(`<a href="${link}">${link}</a> is invalid:<br/>Could not download - wrong URL?<br/>` + | 
					
						
							| 
									
										
										
										
											2021-01-15 01:57:46 +01:00
										 |  |  |             error + | 
					
						
							|  |  |  |             "<a href='https://${window.location.host}/'>Go back</a>") | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |             .SetClass("clickable") | 
					
						
							|  |  |  |             .AttachTo("centermessage"); | 
					
						
							| 
									
										
										
										
											2020-07-29 18:35:46 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 00:25:25 +02:00
										 |  |  | } else if (layoutFromBase64 !== "false") { | 
					
						
							|  |  |  |     layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam); | 
					
						
							| 
									
										
										
										
											2020-09-15 02:29:31 +02:00
										 |  |  |     InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout, location.hash.substr(1)); | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | } else if (layoutToUse !== undefined) { | 
					
						
							|  |  |  |     // This is the default case: a builtin theme
 | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |     InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout); | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2021-01-15 01:57:46 +01:00
										 |  |  |     // We fall through: no theme loaded: just show a few buttons
 | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |     State.state = new State(undefined); | 
					
						
							| 
									
										
										
										
											2021-01-27 03:08:46 +01:00
										 |  |  |     new Combine([new MoreScreen(true), | 
					
						
							|  |  |  |         Translations.t.general.aboutMapcomplete | 
					
						
							| 
									
										
										
										
											2021-01-25 03:12:09 +01:00
										 |  |  |     ]).SetClass("block m-5 lg:w-3/4 lg:ml-40") | 
					
						
							| 
									
										
										
										
											2021-01-27 03:08:46 +01:00
										 |  |  |         .SetStyle("pointer-events: all;") | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |         .AttachTo("topleft-tools"); | 
					
						
							| 
									
										
										
										
											2020-07-29 15:05:19 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-14 00:04:53 +01:00
										 |  |  | window.addEventListener('contextmenu', function (e) { // Not compatible with IE < 9
 | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							|  |  |  | }, false); |