forked from MapComplete/MapComplete
		
	
							parent
							
								
									d313153f4c
								
							
						
					
					
						commit
						c0d1cabac0
					
				
					 2 changed files with 26 additions and 4 deletions
				
			
		| 
						 | 
					@ -7,7 +7,7 @@ import { ImmutableStore, Store } from "../UIEventSource"
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export default class CoordinateSearch implements GeocodingProvider {
 | 
					export default class CoordinateSearch implements GeocodingProvider {
 | 
				
			||||||
    private static readonly latLonRegexes: ReadonlyArray<RegExp> = [
 | 
					    private static readonly latLonRegexes: ReadonlyArray<RegExp> = [
 | 
				
			||||||
        /(-?[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]+)['"]?[ ,;&]+lon[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/,
 | 
				
			||||||
        /lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lng[:=]? *['"]?(-?[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<RegExp> = [
 | 
					    private static readonly lonLatRegexes: ReadonlyArray<RegExp> = [
 | 
				
			||||||
        /(-?[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]+)['"]?/,
 | 
					        /lon[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/,
 | 
				
			||||||
        /lng[:=]? *['"]?(-?[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[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"}
 | 
					     * 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
 | 
					     * // test OSM-XML format
 | 
				
			||||||
     * const ls = new CoordinateSearch()
 | 
					     * const ls = new CoordinateSearch()
 | 
				
			||||||
     * const results = ls.directSearch('  lat="57.5802905" lon="12.7202538"')
 | 
					     * const results = ls.directSearch('  lat="57.5802905" lon="12.7202538"')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,13 @@ import { OsmId } from "../../Models/OsmFeature"
 | 
				
			||||||
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
 | 
					import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class OpenStreetMapIdSearch implements GeocodingProvider {
 | 
					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<Record<string, "node" | "way" | "relation">> = {
 | 
				
			||||||
 | 
					        "n":"node",
 | 
				
			||||||
 | 
					        "w":"way",
 | 
				
			||||||
 | 
					        "r":"relation",
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private readonly _state: SpecialVisualizationState
 | 
					    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("https://openstreetmap.org/node/42#map=19/51.204245/3.212731") // => "node/42"
 | 
				
			||||||
     * OpenStreetMapIdSearch.extractId("node/42") // => "node/42"
 | 
					     * OpenStreetMapIdSearch.extractId("node/42") // => "node/42"
 | 
				
			||||||
     * OpenStreetMapIdSearch.extractId("way/42") // => "way/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"
 | 
					     * OpenStreetMapIdSearch.extractId("https://www.openstreetmap.org/node/5212733638") // => "node/5212733638"
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static extractId(query: string): OsmId | undefined {
 | 
					    public static extractId(query: string): OsmId | undefined {
 | 
				
			||||||
        const match = query.match(OpenStreetMapIdSearch.regex)
 | 
					        const match = query.match(OpenStreetMapIdSearch.regex)
 | 
				
			||||||
        if (match) {
 | 
					        if (match) {
 | 
				
			||||||
            const type = match.at(-2)
 | 
					            let type = match.at(-2)
 | 
				
			||||||
            const id = match.at(-1)
 | 
					            const id = match.at(-1)
 | 
				
			||||||
 | 
					            if(type.length === 1){
 | 
				
			||||||
 | 
					               type = OpenStreetMapIdSearch.types[type]
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            return <OsmId>(type + "/" + id)
 | 
					            return <OsmId>(type + "/" + id)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return undefined
 | 
					        return undefined
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue