From bb33c439509add9da3cf9317c47667543222ee2d Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 7 May 2025 15:35:35 +0200 Subject: [PATCH] Refactoring: reorder parameters in overpass, remove old script --- scripts/importscripts/cleanRepair.ts | 2 +- scripts/repairPanoramax.ts | 101 ------------------ scripts/velopark/veloParkToGeojson.ts | 8 +- .../Sources/OverpassFeatureSource.ts | 8 +- src/Logic/Osm/Overpass.ts | 9 +- src/UI/InspectorGUI.svelte | 7 +- 6 files changed, 13 insertions(+), 122 deletions(-) delete mode 100644 scripts/repairPanoramax.ts diff --git a/scripts/importscripts/cleanRepair.ts b/scripts/importscripts/cleanRepair.ts index 3549fb9dca..d7543211bb 100644 --- a/scripts/importscripts/cleanRepair.ts +++ b/scripts/importscripts/cleanRepair.ts @@ -33,7 +33,7 @@ export default class CleanRepair extends Script { "repair!=assisted_self_service", ], }) - const overpass = new Overpass(criteria, [], "https://overpass-api.de/api/interpreter") + const overpass = new Overpass("https://overpass-api.de/api/interpreter", criteria) const data: Feature>[] = ( await overpass.queryGeoJson(BBox.global) )[0].features diff --git a/scripts/repairPanoramax.ts b/scripts/repairPanoramax.ts deleted file mode 100644 index 1f8d842b4b..0000000000 --- a/scripts/repairPanoramax.ts +++ /dev/null @@ -1,101 +0,0 @@ -import Script from "./Script" -import { Overpass } from "../src/Logic/Osm/Overpass" -import { Or } from "../src/Logic/Tags/Or" -import { RegexTag } from "../src/Logic/Tags/RegexTag" -import { Utils } from "../src/Utils" -import Constants from "../src/Models/Constants" -import { ImmutableStore } from "../src/Logic/UIEventSource" -import { BBox } from "../src/Logic/BBox" -import ChangeTagAction from "../src/Logic/Osm/Actions/ChangeTagAction" -import { Tag } from "../src/Logic/Tags/Tag" -import { Panoramax } from "panoramax-js/dist" -import { Changes } from "../src/Logic/Osm/Changes" -import OsmChangeAction from "../src/Logic/Osm/Actions/OsmChangeAction" -import { writeFileSync } from "fs" -import { Feature } from "geojson" - -class RepairPanoramax extends Script { - private static readonly europe: Feature = { - type: "Feature", - properties: {}, - geometry: { - coordinates: [ - [ - [-20.091159690050006, 25.773375277790038], - [46.12276429398841, 25.773375277790038], - [46.12276429398841, 65.41389761819318], - [-20.091159690050006, 65.41389761819318], - [-20.091159690050006, 25.773375277790038], - ], - ], - type: "Polygon", - }, - } - - constructor() { - super( - "See https://source.mapcomplete.org/MapComplete/MapComplete/issues/2372\n" + - "We accidentally added the full image URL instead of the hash due to a bug. This scripts rewrites all" - ) - } - - async main(args: string[]): Promise { - const keys = ["panoramax", ...Utils.TimesT(10, (i) => "panoramax:" + i)] - const overpass = new Overpass( - new Or(keys.map((k) => new RegexTag(k, /^https:\/\/panoramax.mapcomplete.org\/.*/))), - [], - Constants.defaultOverpassUrls[0], - new ImmutableStore(500) - ) - - const [wrongFeatures] = await overpass.queryGeoJson(BBox.global) - const allChanges: OsmChangeAction[] = [] - for (const f of wrongFeatures.features) { - for (const key of keys) { - const v = f.properties[key] - if (!v) { - continue - } - const pre = "https://panoramax.mapcomplete.org/api/pictures/" - const pre1 = "https://panoramax.mapcomplete.org/permanent/" - let correct: string - if (v.startsWith(pre)) { - correct = v.substring(pre.length) - correct = correct.substring(0, correct.indexOf("/")) - } else if (v.startsWith(pre1)) { - const stripped = v.substring(pre1.length) - correct = stripped.replace(/\//g, "").replace(/\.jpg$/, "") - correct = correct.substring(0, 8) + "-" + correct.substring(8) - } else if (Panoramax.isId(v)) { - // This is a valid ID that came on an object also having an _invalid_ id - // We can safely skip this - continue - } else { - throw "Unknown url " + v - } - console.log(key, correct, " old: ", v) - if (!Panoramax.isId(correct)) { - throw "Constructed an invalid id:" + correct - } - const change = new ChangeTagAction( - f.properties.id, - new Tag(key, correct), - f.properties, - { - theme: "fix", - changeType: "fix", - } - ) - allChanges.push(change) - } - } - - const xml = await Changes.createChangesetXMLForJosm(allChanges) - console.log(xml) - const path = "repairPanoramax.osc" - writeFileSync(path, xml) - console.log("Written XML to", path) - } -} - -new RepairPanoramax().run() diff --git a/scripts/velopark/veloParkToGeojson.ts b/scripts/velopark/veloParkToGeojson.ts index b1835b74df..5173812039 100644 --- a/scripts/velopark/veloParkToGeojson.ts +++ b/scripts/velopark/veloParkToGeojson.ts @@ -186,13 +186,7 @@ class VeloParkToGeojson extends Script { [6.15665815596, 51.4750237087], ]) - const alreadyLinkedQuery = new Overpass( - new RegexTag("ref:velopark", /.+/), - [], - Constants.defaultOverpassUrls[0], - new ImmutableStore(60 * 5), - false - ) + const alreadyLinkedQuery = new Overpass(Constants.defaultOverpassUrls[0], new RegexTag("ref:velopark", /.+/), [], new ImmutableStore(60 * 5), false) const alreadyLinkedFeatures = (await alreadyLinkedQuery.queryGeoJson(bboxBelgium))[0] const seenIds = new Set( alreadyLinkedFeatures.features.map((f) => f.properties?.["ref:velopark"]) diff --git a/src/Logic/FeatureSource/Sources/OverpassFeatureSource.ts b/src/Logic/FeatureSource/Sources/OverpassFeatureSource.ts index bb67066d83..e10a44fb10 100644 --- a/src/Logic/FeatureSource/Sources/OverpassFeatureSource.ts +++ b/src/Logic/FeatureSource/Sources/OverpassFeatureSource.ts @@ -1,4 +1,4 @@ -import { Feature, Geometry } from "geojson" +import { Feature, FeatureCollection, Geometry } from "geojson" import { UpdatableFeatureSource } from "../FeatureSource" import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource" import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" @@ -7,9 +7,9 @@ import { Overpass } from "../../Osm/Overpass" import { Utils } from "../../../Utils" import { TagsFilter } from "../../Tags/TagsFilter" import { BBox } from "../../BBox" -import { FeatureCollection } from "@turf/turf" import { OsmTags } from "../../../Models/OsmFeature" -;("use strict") + +("use strict") /** * A wrapper around the 'Overpass'-object. @@ -204,7 +204,7 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource { if (filters.length === 0) { return undefined } - return new Overpass(new Or(filters), [], interpreterUrl, this.state.overpassTimeout) + return new Overpass(interpreterUrl, new Or(filters), [], this.state.overpassTimeout) } /** diff --git a/src/Logic/Osm/Overpass.ts b/src/Logic/Osm/Overpass.ts index 0dceed5327..d9899fa4aa 100644 --- a/src/Logic/Osm/Overpass.ts +++ b/src/Logic/Osm/Overpass.ts @@ -5,7 +5,8 @@ import { BBox } from "../BBox" import osmtogeojson from "osmtogeojson" import { FeatureCollection, Geometry } from "geojson" import { OsmTags } from "../../Models/OsmFeature" -;("use strict") + +("use strict") /** * Interfaces overpass to get all the latest data */ @@ -17,9 +18,9 @@ export class Overpass { private readonly _includeMeta: boolean constructor( - filter: TagsFilter, - extraScripts: string[], interpreterUrl: string, + filter: TagsFilter, + extraScripts: string[] = [], timeout?: Store, includeMeta = true ) { @@ -146,7 +147,7 @@ export class Overpass { * Little helper method to quickly open overpass-turbo in the browser */ public static AsOverpassTurboLink(tags: TagsFilter) { - const overpass = new Overpass(tags, [], "", undefined, false) + const overpass = new Overpass("", tags, [], undefined, false) const script = overpass.buildScript("", "({{bbox}})", true) const url = "http://overpass-turbo.eu/?Q=" return url + encodeURIComponent(script) diff --git a/src/UI/InspectorGUI.svelte b/src/UI/InspectorGUI.svelte index 978c87dd85..ad4fa9c41e 100644 --- a/src/UI/InspectorGUI.svelte +++ b/src/UI/InspectorGUI.svelte @@ -135,11 +135,8 @@ step.setData("loading") featuresStore.set([]) - const overpass = new Overpass( - undefined, - user.split(";").map((user) => 'nw(user_touched:"' + user + '");'), - Constants.defaultOverpassUrls[0] - ) + const overpass = new Overpass(Constants.defaultOverpassUrls[0], undefined, + user.split(";").map((user) => "nw(user_touched:\"" + user + "\");")) if (!maplibremap.bounds.data) { return }