From c26b9ae7f7fa3de69d499451db14be61e4698721 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 11 Dec 2024 21:55:36 +0100 Subject: [PATCH] Fix: linked data vis for velopark does no longer rely on country codes --- src/Logic/GeoOperations.ts | 1 - src/UI/SpecialVisualizations.ts | 135 ++++++++++++++++---------------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/Logic/GeoOperations.ts b/src/Logic/GeoOperations.ts index 72da928fe..be0657cc4 100644 --- a/src/Logic/GeoOperations.ts +++ b/src/Logic/GeoOperations.ts @@ -15,7 +15,6 @@ import { import { Tiles } from "../Models/TileRange" import { Utils } from "../Utils" import { NearestPointOnLine } from "@turf/nearest-point-on-line" - ;("use strict") export class GeoOperations { diff --git a/src/UI/SpecialVisualizations.ts b/src/UI/SpecialVisualizations.ts index 489d2e107..9b709ef0b 100644 --- a/src/UI/SpecialVisualizations.ts +++ b/src/UI/SpecialVisualizations.ts @@ -2,11 +2,7 @@ import Combine from "./Base/Combine" import { FixedUiElement } from "./Base/FixedUiElement" import BaseUIElement from "./BaseUIElement" import Title from "./Base/Title" -import { - RenderingSpecification, - SpecialVisualization, - SpecialVisualizationState, -} from "./SpecialVisualization" +import { RenderingSpecification, SpecialVisualization, SpecialVisualizationState } from "./SpecialVisualization" import { HistogramViz } from "./Popup/HistogramViz" import MinimapViz from "./Popup/MinimapViz.svelte" import { ShareLinkViz } from "./Popup/ShareLinkViz" @@ -1853,69 +1849,80 @@ export default class SpecialVisualizations { const key = argument[0] ?? "website" const useProxy = argument[1] !== "no" const readonly = argument[3] === "readonly" - const isClosed = (arguments[4] ?? "yes") === "yes" + const isClosed = (argument[4] ?? "yes") === "yes" - const url = tags - .mapD((tags) => { - if (!tags._country || !tags[key] || tags[key] === "undefined") { - return null - } - return JSON.stringify({ url: tags[key], country: tags._country }) - }) - .mapD((data) => JSON.parse(data)) - const sourceUrl: Store = url.mapD((url) => url.url) + const countryStore: Store = tags.mapD( + (tags) => tags._country + ) + const sourceUrl: Store = tags.mapD((tags) => { + if (!tags[key] || tags[key] === "undefined") { + return null + } + return tags[key] + }) const externalData: Store<{ success: GeoJsonProperties } | { error: any }> = - url.bindD(({ url, country }) => { - if (url.startsWith("https://data.velopark.be/")) { + sourceUrl.bindD( + url => { + const country = countryStore.data + if (url.startsWith("https://data.velopark.be/")) { + return Stores.FromPromiseWithErr( + (async () => { + try { + const loadAll = + layer.id.toLowerCase().indexOf("maproulette") >= + 0 // Dirty hack + const features = + await LinkedDataLoader.fetchVeloparkEntry( + url, + loadAll + ) + const feature = + features.find( + (f) => f.properties["ref:velopark"] === url + ) ?? features[0] + const properties = feature.properties + properties["ref:velopark"] = url + console.log( + "Got properties from velopark:", + properties + ) + return properties + } catch (e) { + console.error(e) + throw e + } + })() + ) + } + if (country === undefined) { + return undefined + } return Stores.FromPromiseWithErr( (async () => { try { - const loadAll = - layer.id.toLowerCase().indexOf("maproulette") >= 0 // Dirty hack - const features = - await LinkedDataLoader.fetchVeloparkEntry( - url, - loadAll - ) - const feature = - features.find( - (f) => f.properties["ref:velopark"] === url - ) ?? features[0] - const properties = feature.properties - properties["ref:velopark"] = url - console.log("Got properties from velopark:", properties) - return properties + return await LinkedDataLoader.fetchJsonLd( + url, + { country }, + useProxy ? "proxy" : "fetch-lod" + ) } catch (e) { - console.error(e) - throw e + console.log( + "Could not get with proxy/download LOD, attempting to download directly. Error for ", + url, + "is", + e + ) + return await LinkedDataLoader.fetchJsonLd( + url, + { country }, + "fetch-raw" + ) } })() ) - } - return Stores.FromPromiseWithErr( - (async () => { - try { - return await LinkedDataLoader.fetchJsonLd( - url, - { country }, - useProxy ? "proxy" : "fetch-lod" - ) - } catch (e) { - console.log( - "Could not get with proxy/download LOD, attempting to download directly. Error for ", - url, - "is", - e - ) - return await LinkedDataLoader.fetchJsonLd( - url, - { country }, - "fetch-raw" - ) - } - })() - ) - }) + }, + [countryStore] + ) externalData.addCallbackAndRunD((lod) => console.log("linked_data_from_website received the following data:", lod) @@ -1933,7 +1940,7 @@ export default class SpecialVisualizations { collapsed: isClosed, }), undefined, - url.map((url) => !!url) + sourceUrl.map((url) => !!url) ) }, }, @@ -1988,13 +1995,7 @@ export default class SpecialVisualizations { funcName: "pending_changes", docs: "A module showing the pending changes, with the option to clear the pending changes", args: [], - constr( - state: SpecialVisualizationState, - tagSource: UIEventSource>, - argument: string[], - feature: Feature, - layer: LayerConfig - ): BaseUIElement { + constr(state: SpecialVisualizationState): BaseUIElement { return new SvelteUIElement(PendingChangesIndicator, { state, compact: false }) }, },