You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently results will be displayed in whichever language was set in the options.
{ language: 'en', country: 'au' }
{ language: 'zh', country: 'au' }
To get results displayed in one language, but still display the matching text if the query was in another language you need to do something like:
geocoder._typeahead.getItemValue = function (item) {
if (item.matching_text) { // matching text is the text the query matched, so will be in the same language that the user queried in
return item.matching_text + ' (' + item.place_name + ')';
} else {
return item.place_name;
}
};
That feels a bit hacky though, I'm thinking if doing this be better supported without overwriting the internal _typeahead.getItemValue method, or even if this should become the default?
What about adding a constructor option to provide a function that allows implementation-specific customization over how the results are displayed?
Something like:
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
render: function(result){
return item.matching_text + ' (' + item.place_name + ')'
}
})
We could provide a sensible default (either keep it the same as it is now (use place_name) or use a function that renders the matching text in the dropdown), but provide the ability to override with something different if desired.
The ability to do this was introduced in #208. While the defaults have not changed, once version 4 is released, additional fields can be accessed via the render function.
Activity
scottsfarley93 commentedon Mar 13, 2019
What about adding a constructor option to provide a function that allows implementation-specific customization over how the results are displayed?
Something like:
We could provide a sensible default (either keep it the same as it is now (use
place_name) or use a function that renders the matching text in the dropdown), but provide the ability to override with something different if desired.andrewharvey commentedon Mar 14, 2019
👍 I think that's the way to go.
Rethinking about this, the current defaults are probably good as they are.
scottsfarley93 commentedon Mar 21, 2019
The ability to do this was introduced in #208. While the defaults have not changed, once version 4 is released, additional fields can be accessed via the
renderfunction.