Merge branch 'master' into develop

This commit is contained in:
Pieter Vander Vennet 2025-07-11 03:31:03 +02:00
commit 7d7cee3624
4 changed files with 40 additions and 21 deletions

View file

@ -691,7 +691,7 @@
"popup": [ "popup": [
{ {
"id": "jozin-belgium-block", "id": "jozin-belgium-block",
"condition": "_name=Pieter Vander Vennet", "condition": "_name=jozin-belgium",
"dismissable": false, "dismissable": false,
"title": { "title": {
"render": "Gelieve ons te contacteren" "render": "Gelieve ons te contacteren"

View file

@ -205,6 +205,10 @@ export default class ScriptUtils {
headers?: any, headers?: any,
timeoutSecs?: number timeoutSecs?: number
): Promise<{ content: string } | { redirect: string } | "timeout"> { ): Promise<{ content: string } | { redirect: string } | "timeout"> {
if (url === undefined || url === null) {
console.trace("URL is null or undefined")
throw ("Invalid url: " + url)
}
if (url.startsWith("./assets")) { if (url.startsWith("./assets")) {
return Promise.resolve({ content: readFileSync("./public/" + url, "utf8") }) return Promise.resolve({ content: readFileSync("./public/" + url, "utf8") })
} }

View file

@ -88,7 +88,7 @@ export default class FilteredLayer {
let isDisplayed: UIEventSource<boolean> let isDisplayed: UIEventSource<boolean>
let syncSelection: string = layer.syncSelection let syncSelection: string = layer.syncSelection
const userpreference: "default" | "no" | "local" | "theme-only" | "global" | string = const userpreference: "default" | "no" | "local" | "theme-only" | "global" | string =
osmConnection.getPreference("layer-override-sync-selection").data osmConnection?.getPreference("layer-override-sync-selection")?.data ?? "local"
if (userpreference !== "default") { if (userpreference !== "default") {
syncSelection = userpreference ?? syncSelection syncSelection = userpreference ?? syncSelection
} }

View file

@ -10,7 +10,9 @@ import ThemeConfig from "../../src/Models/ThemeConfig/ThemeConfig"
import { ThemeConfigJson } from "../../src/Models/ThemeConfig/Json/ThemeConfigJson" import { ThemeConfigJson } from "../../src/Models/ThemeConfig/Json/ThemeConfigJson"
import SpecialVisualizations from "../../src/UI/SpecialVisualizations" import SpecialVisualizations from "../../src/UI/SpecialVisualizations"
import ValidationUtils from "../../src/Models/ThemeConfig/Conversion/ValidationUtils" import ValidationUtils from "../../src/Models/ThemeConfig/Conversion/ValidationUtils"
import { QuestionableTagRenderingConfigJson } from "../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson" import {
QuestionableTagRenderingConfigJson
} from "../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import { LayerConfigJson } from "../../src/Models/ThemeConfig/Json/LayerConfigJson" import { LayerConfigJson } from "../../src/Models/ThemeConfig/Json/LayerConfigJson"
export interface ServerSourceInfo { export interface ServerSourceInfo {
@ -66,7 +68,7 @@ export class SourceOverview {
} }
const neededUrls = usedSpecialVisualisation.func.needsUrls ?? [] const neededUrls = usedSpecialVisualisation.func.needsUrls ?? []
if (typeof neededUrls === "function") { if (typeof neededUrls === "function") {
let needed: string | string[] | ServerSourceInfo | ServerSourceInfo[] = neededUrls( const needed: string | string[] | ServerSourceInfo | ServerSourceInfo[] = neededUrls(
usedSpecialVisualisation.args usedSpecialVisualisation.args
) )
if (Array.isArray(needed)) { if (Array.isArray(needed)) {
@ -105,11 +107,11 @@ export class SourceOverview {
const url = f.properties.url const url = f.properties.url
const match = url.match(regex) const match = url.match(regex)
const packageInInfo = (url: string) => { const packageInInfo: (url: (string | string[])) => ServerSourceInfo[] = (urls: string | string[]) => {
if (typeof url !== "string") { if (typeof urls === "string") {
throw "invalid url" + url urls = [urls]
} }
return <ServerSourceInfo>{ return urls.map(url => <ServerSourceInfo>{
url, url,
description: description:
"Background layer source or supporting sources for " + f.properties.id, "Background layer source or supporting sources for " + f.properties.id,
@ -119,18 +121,27 @@ export class SourceOverview {
"https://github.com/osmlab/editor-layer-index", "https://github.com/osmlab/editor-layer-index",
f.properties?.attribution?.url, f.properties?.attribution?.url,
]), ]),
})
}
urls.push(...packageInInfo(["https://protomaps.github.io"]))
const packageInInfoD: (url: (string | string[])) => (ServerSourceInfo[]) = (url: string | string[]) => {
if (!url) {
return []
} }
return packageInInfo(url)
} }
if (match) { if (match) {
const domains = match[1].split(",") const domains = match[1].split(",")
const subpart = match[0] const subpart = match[0]
const info: ServerSourceInfo[] = domains.map((d) => const info: ServerSourceInfo[] = domains.flatMap((d) =>
packageInInfo(url.replace(subpart, d)) packageInInfo(url.replace(subpart, d))
) )
urls.push(...info) urls.push(...info)
} else { } else {
urls.push(packageInInfo(url)) urls.push(...packageInInfo(url))
} }
if (f.properties.type === "vector") { if (f.properties.type === "vector") {
@ -145,42 +156,46 @@ export class SourceOverview {
} }
try { try {
console.log("Downloading ", url) console.log("Downloading ", url)
urls.push(...packageInInfo(url))
const styleSpec = await Utils.downloadJsonCached(url, 1000 * 120, { const styleSpec = await Utils.downloadJsonCached(url, 1000 * 120, {
Origin: "https://mapcomplete.org", Origin: "https://mapcomplete.org",
}) })
for (const key of Object.keys(styleSpec?.["sources"] ?? {})) { for (const key of Object.keys(styleSpec?.["sources"] ?? {})) {
const url = styleSpec["sources"][key].url let url = styleSpec["sources"][key].url
if (!url) { if (!url) {
continue continue
} }
console.log(">>> SPlitting", url)
const split = url.split(",https://")
console.log("Multisplit:", split)
url = split[0]
let urlClipped = url let urlClipped = url
if (url.indexOf("?") > 0) { if (url.indexOf("?") > 0) {
urlClipped = url?.substring(0, url.indexOf("?")) urlClipped = url?.substring(0, url.indexOf("?"))
} }
console.log("Source url ", key, url) urls.push(...packageInInfo(url))
urls.push(packageInInfo(url))
if (urlClipped.endsWith(".json")) { if (urlClipped.endsWith(".json")) {
const tileInfo = await Utils.downloadJsonCached(url, 1000 * 120, { const tileInfo = await Utils.downloadJsonCached(url, 1000 * 120, {
Origin: "https://mapcomplete.org", Origins: "https://mapcomplete.org"
}) })
urls.push(packageInInfo(tileInfo["tiles"] ?? [])) urls.push(...packageInInfo(tileInfo["tiles"] ?? []))
} }
} }
urls.push( urls.push(
...(styleSpec["tiles"] ?? []) ...(styleSpec["tiles"] ?? [])
.flatMap((ls) => ls) .flatMap((ls) => ls)
.map((url) => packageInInfo(url)) .map((url) => packageInInfoD(url))
) )
urls.push(packageInInfo(styleSpec["sprite"])) urls.push(...packageInInfoD(styleSpec["sprite"]))
urls.push(packageInInfo(styleSpec["glyphs"])) urls.push(...packageInInfoD(styleSpec["glyphs"]))
} catch (e) { } catch (e) {
console.error(e)
console.error( console.error(
"ERROR: could not download a resource, some sprites might not be whitelisted and thus not load" "ERROR: could not download a resource: " + url + "\nSome sprites might not be whitelisted and thus not load")
)
} }
} }
} }
urls = urls.filter((item) => !!item.url) urls = urls.filter((item) => !!item?.url)
urls.sort((a, b) => (a < b ? -1 : 1)) urls.sort((a, b) => (a < b ? -1 : 1))
urls = Utils.DedupOnId(urls, (item) => item.url) urls = Utils.DedupOnId(urls, (item) => item.url)
this.eliUrlsCached = urls this.eliUrlsCached = urls