2021-10-15 05:20:02 +02:00
|
|
|
import DetermineLayout from "./Logic/DetermineLayout"
|
2023-04-13 23:40:28 +02:00
|
|
|
import ThemeViewState from "./Models/ThemeViewState"
|
|
|
|
import SvelteUIElement from "./UI/Base/SvelteUIElement"
|
|
|
|
import ThemeViewGUI from "./UI/ThemeViewGUI.svelte"
|
2023-06-14 20:39:36 +02:00
|
|
|
import { FixedUiElement } from "./UI/Base/FixedUiElement"
|
2023-07-08 02:53:45 +02:00
|
|
|
import Combine from "./UI/Base/Combine"
|
|
|
|
import { SubtleButton } from "./UI/Base/SubtleButton"
|
|
|
|
import { Utils } from "./Utils"
|
2024-01-16 23:03:33 +01:00
|
|
|
import Download from "./assets/svg/Download.svelte"
|
2024-02-18 15:59:28 +01:00
|
|
|
import Constants from "./Models/Constants"
|
2024-01-16 23:03:33 +01:00
|
|
|
|
2023-09-16 02:55:13 +02:00
|
|
|
function webgl_support() {
|
|
|
|
try {
|
2024-01-16 23:03:33 +01:00
|
|
|
const canvas = document.createElement("canvas")
|
2023-09-16 02:55:13 +02:00
|
|
|
return (
|
|
|
|
!!window.WebGLRenderingContext &&
|
|
|
|
(canvas.getContext("webgl") || canvas.getContext("experimental-webgl"))
|
|
|
|
)
|
|
|
|
} catch (e) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2024-02-18 15:59:28 +01:00
|
|
|
async function availableLayers(): Promise<Set<string>> {
|
|
|
|
const status = await Utils.downloadJson(Constants.VectorTileServer + "/status.json")
|
|
|
|
return new Set<string>(status.layers)
|
|
|
|
}
|
|
|
|
async function main() {
|
|
|
|
// @ts-ignore
|
|
|
|
try {
|
|
|
|
if (!webgl_support()) {
|
|
|
|
throw "WebGL is not supported or not enabled. This is essential for MapComplete to function, please enable this."
|
|
|
|
}
|
|
|
|
const [layout, availableLayers] = await Promise.all([
|
|
|
|
DetermineLayout.GetLayout(),
|
|
|
|
await availableLayers(),
|
|
|
|
])
|
|
|
|
const state = new ThemeViewState(layout)
|
|
|
|
const main = new SvelteUIElement(ThemeViewGUI, { state })
|
|
|
|
main.AttachTo("maindiv")
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error while initializing: ", err, err.stack)
|
|
|
|
const customDefinition = DetermineLayout.getCustomDefinition()
|
|
|
|
new Combine([
|
|
|
|
new FixedUiElement(err).SetClass("block alert"),
|
2024-01-16 23:03:33 +01:00
|
|
|
|
2024-02-18 15:59:28 +01:00
|
|
|
customDefinition?.length > 0
|
|
|
|
? new SubtleButton(new SvelteUIElement(Download), "Download the raw file").onClick(
|
|
|
|
() =>
|
2024-01-16 23:03:33 +01:00
|
|
|
Utils.offerContentsAsDownloadableFile(
|
|
|
|
DetermineLayout.getCustomDefinition(),
|
|
|
|
"mapcomplete-theme.json",
|
|
|
|
{ mimetype: "application/json" }
|
|
|
|
)
|
2024-02-18 15:59:28 +01:00
|
|
|
)
|
|
|
|
: undefined,
|
|
|
|
]).AttachTo("maindiv")
|
|
|
|
}
|
2023-06-26 11:11:22 +02:00
|
|
|
}
|
2024-02-18 15:59:28 +01:00
|
|
|
|
|
|
|
main().then((_) => {})
|