From 3ac2f96868d7e92b5d8637c75c7b62b1061b7468 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 24 Aug 2024 01:53:06 +0200 Subject: [PATCH] Improve coordiante search formats --- src/Logic/Geocoding/CoordinateSearch.ts | 28 +++++++++++++++++++------ src/UI/BigComponents/MoreScreen.ts | 3 +++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Logic/Geocoding/CoordinateSearch.ts b/src/Logic/Geocoding/CoordinateSearch.ts index 7a28fae745..5036d67bb0 100644 --- a/src/Logic/Geocoding/CoordinateSearch.ts +++ b/src/Logic/Geocoding/CoordinateSearch.ts @@ -1,4 +1,4 @@ -import GeocodingProvider, { GeoCodeResult, GeocodingOptions } from "./GeocodingProvider" +import GeocodingProvider, { GeoCodeResult } from "./GeocodingProvider" import { Utils } from "../../Utils" import { ImmutableStore, Store } from "../UIEventSource" @@ -7,14 +7,19 @@ import { ImmutableStore, Store } from "../UIEventSource" */ export default class CoordinateSearch implements GeocodingProvider { private static readonly latLonRegexes: ReadonlyArray = [ - /([0-9]+\.[0-9]+)[ ,;]+([0-9]+\.[0-9]+)/, - /lat:?[ ]*([0-9]+\.[0-9]+)[ ,;]+lon:?[ ]*([0-9]+\.[0-9]+)/, - /https:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([0-9]+\.[0-9]+)\/([0-9]+\.[0-9]+)/, - /https:\/\/www.google.com\/maps\/@([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]+)['"]?/, + + /https:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/(-?[0-9]+\.[0-9]+)\/(-?[0-9]+\.[0-9]+)/, + /https:\/\/www.google.com\/maps\/@(-?[0-9]+.[0-9]+),(-?[0-9]+.[0-9]+).*/ ] 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]+)['"]?/, + ] /** @@ -35,6 +40,17 @@ 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": "coordinateSearch"} * results[1] // => {lon: 51.2611, lat: 3.2217, display_name: "lon: 51.2611, lat: 3.2217", "category": "coordinate", "source": "coordinateSearch"} * + * // test OSM-XML format + * const ls = new CoordinateSearch() + * const results = ls.directSearch(' lat="57.5802905" lon="12.7202538"') + * results.length // => 1 + * results[0] // => {lat: 57.5802905, lon: 12.7202538, display_name: "lon: 12.7202538, lat: 57.5802905", "category": "coordinate", "source": "coordinateSearch"} + * + * // should work with negative coordinates + * const ls = new CoordinateSearch() + * const results = ls.directSearch(' lat="-57.5802905" lon="-12.7202538"') + * results.length // => 1 + * results[0] // => {lat: -57.5802905, lon: -12.7202538, display_name: "lon: -12.7202538, lat: -57.5802905", "category": "coordinate", "source": "coordinateSearch"} */ private directSearch(query: string): GeoCodeResult[] { diff --git a/src/UI/BigComponents/MoreScreen.ts b/src/UI/BigComponents/MoreScreen.ts index 984570ee8c..7932401920 100644 --- a/src/UI/BigComponents/MoreScreen.ts +++ b/src/UI/BigComponents/MoreScreen.ts @@ -75,6 +75,9 @@ export default class MoreScreen { if (layout.id === "personal") { return false } + if(Utils.simplifyStringForSearch(layout.id) === Utils.simplifyStringForSearch(search)){ + return true + } const entitiesToSearch = [layout.shortDescription, layout.title, ...(layout.keywords ?? [])] for (const entity of entitiesToSearch) { if (entity === undefined) {