Fix: linked data vis for velopark does no longer rely on country codes

This commit is contained in:
Pieter Vander Vennet 2024-12-11 21:55:36 +01:00
parent d19719afc3
commit c26b9ae7f7
2 changed files with 68 additions and 68 deletions

View file

@ -15,7 +15,6 @@ import {
import { Tiles } from "../Models/TileRange" import { Tiles } from "../Models/TileRange"
import { Utils } from "../Utils" import { Utils } from "../Utils"
import { NearestPointOnLine } from "@turf/nearest-point-on-line" import { NearestPointOnLine } from "@turf/nearest-point-on-line"
;("use strict") ;("use strict")
export class GeoOperations { export class GeoOperations {

View file

@ -2,11 +2,7 @@ import Combine from "./Base/Combine"
import { FixedUiElement } from "./Base/FixedUiElement" import { FixedUiElement } from "./Base/FixedUiElement"
import BaseUIElement from "./BaseUIElement" import BaseUIElement from "./BaseUIElement"
import Title from "./Base/Title" import Title from "./Base/Title"
import { import { RenderingSpecification, SpecialVisualization, SpecialVisualizationState } from "./SpecialVisualization"
RenderingSpecification,
SpecialVisualization,
SpecialVisualizationState,
} from "./SpecialVisualization"
import { HistogramViz } from "./Popup/HistogramViz" import { HistogramViz } from "./Popup/HistogramViz"
import MinimapViz from "./Popup/MinimapViz.svelte" import MinimapViz from "./Popup/MinimapViz.svelte"
import { ShareLinkViz } from "./Popup/ShareLinkViz" import { ShareLinkViz } from "./Popup/ShareLinkViz"
@ -1853,25 +1849,28 @@ export default class SpecialVisualizations {
const key = argument[0] ?? "website" const key = argument[0] ?? "website"
const useProxy = argument[1] !== "no" const useProxy = argument[1] !== "no"
const readonly = argument[3] === "readonly" const readonly = argument[3] === "readonly"
const isClosed = (arguments[4] ?? "yes") === "yes" const isClosed = (argument[4] ?? "yes") === "yes"
const url = tags const countryStore: Store<string | undefined> = tags.mapD(
.mapD((tags) => { (tags) => tags._country
if (!tags._country || !tags[key] || tags[key] === "undefined") { )
const sourceUrl: Store<string | undefined> = tags.mapD((tags) => {
if (!tags[key] || tags[key] === "undefined") {
return null return null
} }
return JSON.stringify({ url: tags[key], country: tags._country }) return tags[key]
}) })
.mapD((data) => JSON.parse(data))
const sourceUrl: Store<string | undefined> = url.mapD((url) => url.url)
const externalData: Store<{ success: GeoJsonProperties } | { error: any }> = const externalData: Store<{ success: GeoJsonProperties } | { error: any }> =
url.bindD(({ url, country }) => { sourceUrl.bindD(
url => {
const country = countryStore.data
if (url.startsWith("https://data.velopark.be/")) { if (url.startsWith("https://data.velopark.be/")) {
return Stores.FromPromiseWithErr( return Stores.FromPromiseWithErr(
(async () => { (async () => {
try { try {
const loadAll = const loadAll =
layer.id.toLowerCase().indexOf("maproulette") >= 0 // Dirty hack layer.id.toLowerCase().indexOf("maproulette") >=
0 // Dirty hack
const features = const features =
await LinkedDataLoader.fetchVeloparkEntry( await LinkedDataLoader.fetchVeloparkEntry(
url, url,
@ -1883,7 +1882,10 @@ export default class SpecialVisualizations {
) ?? features[0] ) ?? features[0]
const properties = feature.properties const properties = feature.properties
properties["ref:velopark"] = url properties["ref:velopark"] = url
console.log("Got properties from velopark:", properties) console.log(
"Got properties from velopark:",
properties
)
return properties return properties
} catch (e) { } catch (e) {
console.error(e) console.error(e)
@ -1892,6 +1894,9 @@ export default class SpecialVisualizations {
})() })()
) )
} }
if (country === undefined) {
return undefined
}
return Stores.FromPromiseWithErr( return Stores.FromPromiseWithErr(
(async () => { (async () => {
try { try {
@ -1915,7 +1920,9 @@ export default class SpecialVisualizations {
} }
})() })()
) )
}) },
[countryStore]
)
externalData.addCallbackAndRunD((lod) => externalData.addCallbackAndRunD((lod) =>
console.log("linked_data_from_website received the following data:", lod) console.log("linked_data_from_website received the following data:", lod)
@ -1933,7 +1940,7 @@ export default class SpecialVisualizations {
collapsed: isClosed, collapsed: isClosed,
}), }),
undefined, undefined,
url.map((url) => !!url) sourceUrl.map((url) => !!url)
) )
}, },
}, },
@ -1988,13 +1995,7 @@ export default class SpecialVisualizations {
funcName: "pending_changes", funcName: "pending_changes",
docs: "A module showing the pending changes, with the option to clear the pending changes", docs: "A module showing the pending changes, with the option to clear the pending changes",
args: [], args: [],
constr( constr(state: SpecialVisualizationState): BaseUIElement {
state: SpecialVisualizationState,
tagSource: UIEventSource<Record<string, string>>,
argument: string[],
feature: Feature,
layer: LayerConfig
): BaseUIElement {
return new SvelteUIElement(PendingChangesIndicator, { state, compact: false }) return new SvelteUIElement(PendingChangesIndicator, { state, compact: false })
}, },
}, },