Skip to content

Commit cda5a8c

Browse files
mpothierVladislavMedved
authored andcommitted
enable multiple reverse results when no types or limit specified
fix promise resolution
1 parent 6a88b7f commit cda5a8c

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

lib/index.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ MapboxGeocoder.prototype = {
692692

693693
config = extend(config,
694694
this.options.version === 'v6' ? { longitude: coords[0], latitude: coords[1]} : { query: coords },
695-
!config.types || config.types.length !== 1 ? {limit: 1 } : {}
695+
!config.types && config.limit && config.limit !== 1 ? {limit: 1} : {}, // force limit=1 if no types and limit > 1
696+
config.types && config.types.length !== 1 ? {limit: 1 } : {} // force limit=1 if multiple types
696697
);
697698
} break;
698699
case GEOCODE_REQUEST_TYPE.FORWARD: {
@@ -734,16 +735,35 @@ MapboxGeocoder.prototype = {
734735

735736
const requestType = this._requestType(this.options, searchInput);
736737

737-
let config;
738+
var config;
738739
// setup request parameters config and pre-validate values
739740
try {
740741
config = this._setupConfig(requestType, searchInput);
741742
} catch (err) {
742-
this._hideLoadingIcon();
743-
this._hideAttribution();
744-
this._typeahead.selected = null;
745-
this._renderCustomError(err.message);
746-
return Promise.resolve();
743+
const request = new Promise(function (resolve) {
744+
resolve();
745+
});
746+
request.then(function() {
747+
return {
748+
type: 'FeatureCollection',
749+
features: [],
750+
config
751+
}
752+
}.bind(this))
753+
.then(function(){
754+
this._hideLoadingIcon();
755+
this._hideAttribution();
756+
this._typeahead.selected = null;
757+
this._renderCustomError(err.message);
758+
this._eventEmitter.emit('results', {
759+
type: 'FeatureCollection',
760+
features: [],
761+
config
762+
});
763+
this._eventEmitter.emit('error', { error: err });
764+
765+
}.bind(this))
766+
return request
747767
}
748768

749769
var request;

0 commit comments

Comments
 (0)