Skip to content

Commit

Permalink
BUGFIX: do not use nominatim "display name" because it is not a displ…
Browse files Browse the repository at this point in the history
…ay name.

See upstream issue osm-search/Nominatim#213
  • Loading branch information
rotdrop committed Jun 28, 2022
1 parent 6dc92da commit 2493355
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import TracksController from './tracksController';

import { brify, getUrlParameter, formatAddress } from './utils';

import addressFormatter from '@fragaria/address-formatter';

(function($, OC) {
var geoLinkController = {
marker: null,
Expand Down Expand Up @@ -1640,6 +1642,15 @@ import { brify, getUrlParameter, formatAddress } from './utils';
this.search(str, this.handleSearchResult, this);
},


formatAddress: function(searchResult) {
const displayName = addressFormatter.format(searchResult.address, {
countryCode: OC.getLocale(),
output: 'array',
});
return displayName.join(', ');
},

handleSearchResult: function(results, that, isCoordinateSearch = false, searchString = '') {
if (results.length === 0) {
OC.Notification.showTemporary(t('maps', 'No search result'));
Expand All @@ -1653,7 +1664,8 @@ import { brify, getUrlParameter, formatAddress } from './utils';
var newData = [];
for (var i=0; i < results.length; i++) {
if (isCoordinateSearch && !results[i].maps_type) {
const label = results[i].display_name + ' (' + searchString + ')'
const displayName = searchController.formatAddress(results[i]);
const label = displayName + ' (' + searchString + ')'
newData.push({
type: 'address',
label: label,
Expand All @@ -1672,10 +1684,11 @@ import { brify, getUrlParameter, formatAddress } from './utils';
lng: results[i].lon
});
} else {
const displayName = searchController.formatAddress(results[i]);
newData.push({
type: results[i].maps_type ?? 'address',
label: results[i].display_name,
value: results[i].display_name,
label: displayName,
value: displayName,
result: results[i],
lat: results[i].lat,
lng: results[i].lon
Expand Down

0 comments on commit 2493355

Please sign in to comment.