Skip to content

Commit

Permalink
proxy nominatim search through the server, reset pitch when flying to…
Browse files Browse the repository at this point in the history
… result

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Nov 26, 2023
1 parent 243df32 commit 8cb4dd6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
13 changes: 11 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 9 additions & 6 deletions lib/Service/MapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/map/MaplibreMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export default {
debounceSearch: 400,
popup: true,
showResultsWhileTyping: true,
flyTo: { pitch: 0 },
}),
'top-left',
)
Expand Down
5 changes: 3 additions & 2 deletions src/nominatimGeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8cb4dd6

Please sign in to comment.