Skip to content

Commit fc28df1

Browse files
add version to event payload
1 parent 57118b9 commit fc28df1

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ MapboxEventManager.prototype = {
179179
routing: geocoder.options.routing,
180180
worldview: geocoder.options.worldview,
181181
mapZoom: zoom,
182-
keyboardLocale: this.locale
182+
keyboardLocale: this.locale,
183+
version: geocoder.options.version
183184
}
184185

185186
// get the text in the search bar

lib/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,13 @@ MapboxGeocoder.prototype = {
568568

569569
_fly: function(selected) {
570570
var flyOptions;
571-
const { context, short_code } = selected.properties;
572-
const countryCode = this.options.version === 'v6' ?
573-
context && context.country && context.country.country_code.toLowerCase() :
574-
short_code;
575-
if (selected.properties && exceptions[countryCode]) {
571+
let exceptionCode;
572+
if (this.options.version === 'v6' && selected.properties.feature_type === 'country') {
573+
exceptionCode = selected.properties.context.country.country_code.toLowerCase();
574+
} else if (this.options.version === 'v5') {
575+
exceptionCode = selected.properties && selected.properties.short_code;
576+
}
577+
if (selected.properties && exceptions[exceptionCode]) {
576578
// Certain geocoder search results return (and therefore zoom to fit)
577579
// an unexpectedly large bounding box: for example, both Russia and the
578580
// USA span both sides of -180/180, or France includes the island of
@@ -581,7 +583,7 @@ MapboxGeocoder.prototype = {
581583
// short-term solution; this may be amended as necessary.
582584
flyOptions = extend({}, this.options.flyTo);
583585
if (this._map){
584-
this._map.fitBounds(exceptions[countryCode].bbox, flyOptions);
586+
this._map.fitBounds(exceptions[exceptionCode].bbox, flyOptions);
585587
}
586588
} else if (selected.bbox) {
587589
var bbox = selected.bbox;
@@ -899,7 +901,9 @@ MapboxGeocoder.prototype = {
899901
if (!results.features.length) return;
900902
var result = results.features[0];
901903
this._typeahead.selected = result;
902-
this._inputEl.value = this.options.version === 'v6' ? result.properties.name : result.place_name;
904+
this._inputEl.value = this.options.version === 'v6' ?
905+
(result.properties.name + (result.properties.place_formatted ? `, ${result.properties.place_formatted}` : "")) :
906+
result.place_name;
903907
this._onChange();
904908
},
905909

lib/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ function getV6AddressInfo(feature) {
8686

8787
for (const contextProp in feature.context) {
8888
if (contextProp) {
89-
const layer = contextProp.id.split(".")[0];
90-
addrInfo[layer] = contextProp.name;
89+
addrInfo[contextProp] = feature.context[contextProp].name;
9190
}
9291
}
9392

0 commit comments

Comments
 (0)