forked from MapComplete/MapComplete
		
	Fix: linked data vis for velopark does no longer rely on country codes
This commit is contained in:
		
							parent
							
								
									d19719afc3
								
							
						
					
					
						commit
						c26b9ae7f7
					
				
					 2 changed files with 68 additions and 68 deletions
				
			
		|  | @ -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 { | ||||||
|  |  | ||||||
|  | @ -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,69 +1849,80 @@ 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") { |                     ) | ||||||
|                                 return null |                     const sourceUrl: Store<string | undefined> = tags.mapD((tags) => { | ||||||
|                             } |                         if (!tags[key] || tags[key] === "undefined") { | ||||||
|                             return JSON.stringify({ url: tags[key], country: tags._country }) |                             return null | ||||||
|                         }) |                         } | ||||||
|                         .mapD((data) => JSON.parse(data)) |                         return tags[key] | ||||||
|                     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( | ||||||
|                             if (url.startsWith("https://data.velopark.be/")) { |                             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( |                                 return Stores.FromPromiseWithErr( | ||||||
|                                     (async () => { |                                     (async () => { | ||||||
|                                         try { |                                         try { | ||||||
|                                             const loadAll = |                                             return await LinkedDataLoader.fetchJsonLd( | ||||||
|                                                 layer.id.toLowerCase().indexOf("maproulette") >= 0 // Dirty hack
 |                                                 url, | ||||||
|                                             const features = |                                                 { country }, | ||||||
|                                                 await LinkedDataLoader.fetchVeloparkEntry( |                                                 useProxy ? "proxy" : "fetch-lod" | ||||||
|                                                     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) { |                                         } catch (e) { | ||||||
|                                             console.error(e) |                                             console.log( | ||||||
|                                             throw e |                                                 "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( |                             [countryStore] | ||||||
|                                 (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" |  | ||||||
|                                         ) |  | ||||||
|                                     } |  | ||||||
|                                 })() |  | ||||||
|                             ) |  | ||||||
|                         }) |  | ||||||
| 
 | 
 | ||||||
|                     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 }) | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue