2023-07-16 03:26:43 +02:00
import ThemeViewState from "./src/Models/ThemeViewState"
import ThemeViewGUI from "./src/UI/ThemeViewGUI.svelte"
import LayoutConfig from "./src/Models/ThemeConfig/LayoutConfig";
2023-12-06 12:57:13 +01:00
import MetaTagging from "./src/Logic/MetaTagging";
2023-09-27 22:21:35 +02:00
import { FixedUiElement } from "./src/UI/Base/FixedUiElement";
2024-02-20 02:01:08 +01:00
import { Utils } from "./src/Utils"
import Constants from "./src/Models/Constants"
2022-07-25 16:58:30 +02:00
2023-09-25 17:29:17 +02:00
function webgl_support() {
try {
var canvas = document.createElement("canvas")
return (
!!window.WebGLRenderingContext &&
(canvas.getContext("webgl") || canvas.getContext("experimental-webgl"))
)
} catch (e) {
return false
}
}
2024-03-28 16:57:58 +01:00
async function timeout(timeMS: number): Promise<{ layers: string[] }> {
await Utils.waitFor(timeMS)
return { layers: [] }
}
2024-02-20 02:01:08 +01:00
async function getAvailableLayers(): Promise<Set<string>> {
2024-09-24 17:54:18 +02:00
if(!Constants.SummaryServer){
return new Set<string>()
}
2024-02-20 02:01:08 +01:00
try {
2024-09-24 17:54:18 +02:00
const host = new URL(Constants.SummaryServer).host
2024-03-28 16:57:58 +01:00
const status = await Promise.any([
2024-04-30 23:14:57 +02:00
Utils.downloadJson("https://" + host + "/summary/status.json"),
2024-03-28 19:54:07 +01:00
timeout(0)
2024-03-28 16:57:58 +01:00
])
2024-02-20 02:01:08 +01:00
return new Set<string>(status.layers)
} catch (e) {
console.error("Could not get MVT available layers due to", e)
return new Set<string>()
}
}
2023-09-22 11:20:22 +02:00
2024-02-20 02:01:08 +01:00
async function main() {
if (!webgl_support()) {
new FixedUiElement("WebGL is not supported or not enabled. This is essential for MapComplete to function, please enable this.").SetClass("block alert").AttachTo("maindiv")
}else{
const availableLayers = await getAvailableLayers()
MetaTagging.setThemeMetatagging(new ThemeMetaTagging())
// LAYOUT.ADD_LAYERS
2024-07-14 12:07:23 +02:00
// LAYOUT.ADD_CONFIG
2024-02-20 02:01:08 +01:00
const state = new ThemeViewState(new LayoutConfig(<any> layout), availableLayers)
2024-06-18 03:33:11 +02:00
const target = document.getElementById("maindiv")
const childs = Array.from(target.children)
2024-06-15 02:21:18 +02:00
new ThemeViewGUI({
2024-06-18 03:33:11 +02:00
target,
props: { state },
2024-06-15 02:21:18 +02:00
})
2024-06-18 03:33:11 +02:00
childs.forEach(ch => target.removeChild(ch))
2024-03-21 22:39:36 +01:00
Array.from(document.getElementsByClassName("delete-on-load")).forEach(el => {
el.parentElement.removeChild(el)
})
2024-02-20 02:01:08 +01:00
}
}
main()