From 8cb4dd66e87ba694fd981f20e387f0136194ce20 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sun, 26 Nov 2023 19:49:26 +0100 Subject: [PATCH] proxy nominatim search through the server, reset pitch when flying to result Signed-off-by: Julien Veyssier --- lib/Controller/PageController.php | 13 +++++++++++-- lib/Service/MapService.php | 15 +++++++++------ src/components/map/MaplibreMap.vue | 1 + src/nominatimGeocoder.js | 5 +++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 56e1ebb18..3af6da576 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -118,8 +118,17 @@ public function getRasterTile(string $service, int $x, int $y, int $z): DataDisp * @param string $query * @return DataResponse */ - public function nominatimSearch(string $query): DataResponse { - $searchResults = $this->mapService->searchLocation($this->userId, $query, 0, 10); + public function nominatimSearch( + string $q, string $rformat = 'json', ?int $polygon_geojson = null, ?int $addressdetails = null, + ?int $namedetails = null, ?int $extratags = null, int $limit = 10 + ): DataResponse { + $extraParams = [ + 'polygon_geojson' => $polygon_geojson, + 'addressdetails' => $addressdetails, + 'namedetails' => $namedetails, + 'extratags' => $extratags, + ]; + $searchResults = $this->mapService->searchLocation($this->userId, $q, $rformat, $extraParams, 0, $limit); if (isset($searchResults['error'])) { return new DataResponse('', Http::STATUS_BAD_REQUEST); } diff --git a/lib/Service/MapService.php b/lib/Service/MapService.php index b5ad4ada5..e9937628e 100644 --- a/lib/Service/MapService.php +++ b/lib/Service/MapService.php @@ -119,17 +119,20 @@ public function getRasterTile(string $service, int $x, int $y, int $z): ?string * @param int $limit * @return array request result */ - public function searchLocation(string $userId, string $query, int $offset = 0, int $limit = 5): array { + public function searchLocation(string $userId, string $query, string $format = 'json', array $extraParams = [], int $offset = 0, int $limit = 5): array { // no pagination... $limitParam = $offset + $limit; $params = [ - 'format' => 'json', - 'addressdetails' => 1, - 'extratags' => 1, - 'namedetails' => 1, + 'q' => $query, + 'format' => $format, 'limit' => $limitParam, ]; - $result = $this->request($userId, 'search/' . urlencode($query), $params); + foreach ($extraParams as $k => $v) { + if ($v !== null) { + $params[$k] = $v; + } + } + $result = $this->request($userId, 'search', $params); if (!isset($result['error'])) { return array_slice($result, $offset, $limit); } diff --git a/src/components/map/MaplibreMap.vue b/src/components/map/MaplibreMap.vue index 17be066d3..cd532ff30 100644 --- a/src/components/map/MaplibreMap.vue +++ b/src/components/map/MaplibreMap.vue @@ -284,6 +284,7 @@ export default { debounceSearch: 400, popup: true, showResultsWhileTyping: true, + flyTo: { pitch: 0 }, }), 'top-left', ) diff --git a/src/nominatimGeocoder.js b/src/nominatimGeocoder.js index 093928df6..cfdcd10d9 100644 --- a/src/nominatimGeocoder.js +++ b/src/nominatimGeocoder.js @@ -58,13 +58,14 @@ export async function maplibreForwardGeocode(config) { const req = { params: { q: config.query, - format: 'geojson', + rformat: 'geojson', polygon_geojson: 1, addressdetails: 1, limit: config.limit, }, } - const url = 'https://nominatim.openstreetmap.org/search' + // const url = 'https://nominatim.openstreetmap.org/search' + const url = generateUrl('/apps/gpxpod/nominatim/search') const response = await axios.get(url, req) const geojson = response.data for (const feature of geojson.features) {