diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e190333..96bbb50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Localize placeholder based on language set in constructor options [#150](https://github.com/mapbox/mapbox-gl-geocoder/issues/150) - `trackProximity` turned on by default [#195](https://github.com/mapbox/mapbox-gl-geocoder/issues/195) - Bump suggestions to v1.3.4 +- Fix duplicate event bug ## v3.1.4 diff --git a/lib/index.js b/lib/index.js index 1ef7c0fa..9e1f6ff2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -54,6 +54,7 @@ function MapboxGeocoder(options) { this.options = extend({}, this.options, options); this.inputString = ''; this.fresh = true; + this.lastSelected = null; } MapboxGeocoder.prototype = { @@ -190,8 +191,11 @@ MapboxGeocoder.prototype = { }); } } - this._eventEmitter.emit('result', { result: selected }); - this.eventManager.select(selected, this); + if (selected.id !== this.lastSelected){ + this._eventEmitter.emit('result', { result: selected }); + this.eventManager.select(selected, this); + this.lastSelected = selected.id; + } } },