diff --git a/src/Logic/Geocoding/CoordinateSearch.ts b/src/Logic/Geocoding/CoordinateSearch.ts index 8396691308..256a56c363 100644 --- a/src/Logic/Geocoding/CoordinateSearch.ts +++ b/src/Logic/Geocoding/CoordinateSearch.ts @@ -7,7 +7,7 @@ import { ImmutableStore, Store } from "../UIEventSource" */ export default class CoordinateSearch implements GeocodingProvider { private static readonly latLonRegexes: ReadonlyArray = [ - /(-?[0-9]+\.[0-9]+)[ ,;]+(-?[0-9]+\.[0-9]+)/, + /^(-?[0-9]+\.[0-9]+)[ ,;/\\]+(-?[0-9]+\.[0-9]+)/, /lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lon[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/, /lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lng[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/, @@ -16,7 +16,7 @@ export default class CoordinateSearch implements GeocodingProvider { ] private static readonly lonLatRegexes: ReadonlyArray = [ - /(-?[0-9]+\.[0-9]+)[ ,;]+(-?[0-9]+\.[0-9]+)/, + /^(-?[0-9]+\.[0-9]+)[ ,;/\\]+(-?[0-9]+\.[0-9]+)/, /lon[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/, /lng[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/, @@ -40,6 +40,13 @@ export default class CoordinateSearch implements GeocodingProvider { * results[0] // => {lat: 51.2611, lon: 3.2217, display_name: "lon: 3.2217, lat: 51.2611", "category": "coordinate", "source": "coordinate:latlon"} * results[1] // => {lon: 51.2611, lat: 3.2217, display_name: "lon: 51.2611, lat: 3.2217", "category": "coordinate", "source": "coordinate:lonlat"} * + * // Test format mentioned in 1599 + * const ls = new CoordinateSearch() + * const results = ls.directSearch("51.2611/3.2217") + * results.length // => 2 + * results[0] // => {lat: 51.2611, lon: 3.2217, display_name: "lon: 3.2217, lat: 51.2611", "category": "coordinate", "source": "coordinate:latlon"} + * results[1] // => {lon: 51.2611, lat: 3.2217, display_name: "lon: 51.2611, lat: 3.2217", "category": "coordinate", "source": "coordinate:lonlat"} + * * // test OSM-XML format * const ls = new CoordinateSearch() * const results = ls.directSearch(' lat="57.5802905" lon="12.7202538"') diff --git a/src/Logic/Geocoding/OpenStreetMapIdSearch.ts b/src/Logic/Geocoding/OpenStreetMapIdSearch.ts index 168ecca840..a6bc10bece 100644 --- a/src/Logic/Geocoding/OpenStreetMapIdSearch.ts +++ b/src/Logic/Geocoding/OpenStreetMapIdSearch.ts @@ -4,7 +4,13 @@ import { OsmId } from "../../Models/OsmFeature" import { SpecialVisualizationState } from "../../UI/SpecialVisualization" export default class OpenStreetMapIdSearch implements GeocodingProvider { - private static regex = /((https?:\/\/)?(www.)?(osm|openstreetmap).org\/)?(node|way|relation)\/([0-9]+)/ + private static readonly regex = /((https?:\/\/)?(www.)?(osm|openstreetmap).org\/)?(n|node|w|way|r|relation)[\/ ]?([0-9]+)/ + + private static readonly types: Readonly> = { + "n":"node", + "w":"way", + "r":"relation", + } private readonly _state: SpecialVisualizationState @@ -18,13 +24,22 @@ export default class OpenStreetMapIdSearch implements GeocodingProvider { * OpenStreetMapIdSearch.extractId("https://openstreetmap.org/node/42#map=19/51.204245/3.212731") // => "node/42" * OpenStreetMapIdSearch.extractId("node/42") // => "node/42" * OpenStreetMapIdSearch.extractId("way/42") // => "way/42" + * OpenStreetMapIdSearch.extractId("n123456789") // => "node/123456789" + * OpenStreetMapIdSearch.extractId("node123456789") // => "node/123456789" + * OpenStreetMapIdSearch.extractId("node 123456789") // => "node/123456789" + * OpenStreetMapIdSearch.extractId("w123456789") // => "way/123456789" + * OpenStreetMapIdSearch.extractId("way123456789") // => "way/123456789" + * OpenStreetMapIdSearch.extractId("way 123456789") // => "way/123456789" * OpenStreetMapIdSearch.extractId("https://www.openstreetmap.org/node/5212733638") // => "node/5212733638" */ public static extractId(query: string): OsmId | undefined { const match = query.match(OpenStreetMapIdSearch.regex) if (match) { - const type = match.at(-2) + let type = match.at(-2) const id = match.at(-1) + if(type.length === 1){ + type = OpenStreetMapIdSearch.types[type] + } return (type + "/" + id) } return undefined