Skip to content

Commit

Permalink
Fire data and dataend events
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Apr 19, 2016
1 parent 78de357 commit eafebd9
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ var Map = module.exports = function(options) {

this.on('move', this._update.bind(this, false));
this.on('zoom', this._update.bind(this, true));
this.on('moveend', function() {
this.animationLoop.set(300); // text fading
this._rerender();
}.bind(this));
this.on('moveend', this._onMoveend.bind(this));
this.on('data', this._onData.bind(this));


if (typeof window !== 'undefined') {
window.addEventListener('resize', this._onWindowResize, false);
Expand Down Expand Up @@ -847,9 +846,22 @@ util.extend(Map.prototype, /** @lends Map.prototype */{

this.fire('render');

if (this.isDataStable() && !this._loaded) {
this._loaded = true;
this.fire('load');
if (this._willFireData) {
this.fire('data');
}

if (this.isDataStable()) {
if (!this._wasLoaded) {
this._wasLoaded = true;
this.fire('load');
}

if (!this._wasDataStable) {
this._wasDataStable = true;
this.fire('dataend');
}
} else {
this._wasDataStable = false;
}

this._frameId = null;
Expand Down Expand Up @@ -906,6 +918,7 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
},

_forwardStyleEvent: function(e) {
if (e.type === 'load' || e.type === 'change') this._willFireData = true;
this.fire('style.' + e.type, util.extend({style: e.target}, e));
},

Expand All @@ -918,6 +931,9 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
},

_forwardTileEvent: function(e) {
if (e.type === 'load' || e.type === 'add' || e.type === 'remove') {
this._willFireData = true;
}
this.fire(e.type, util.extend({style: e.target}, e));
},

Expand All @@ -939,22 +955,34 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
if (source.onAdd)
source.onAdd(this);
this._forwardSourceEvent(e);
this._willFireData = true;
},

_onSourceRemove: function(e) {
var source = e.source;
if (source.onRemove)
source.onRemove(this);
this._forwardSourceEvent(e);
this._willFireData = true;
},

_onSourceUpdate: function(e) {
this._update();
this._forwardSourceEvent(e);
this._willFireData = true;
},

_onWindowResize: function() {
this.stop().resize()._update();
},

_onMoveend: function() {
this.animationLoop.set(300); // text fading
this._rerender();
},

_onData: function() {
this._wasDataStable = false;
}
});

Expand Down

0 comments on commit eafebd9

Please sign in to comment.