Skip to content

Commit

Permalink
Implemented 'renderstable' event
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Apr 20, 2016
1 parent d7dacd6 commit d695605
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion debug/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@
'zoomstart', 'zoom', 'zoomend',
'rotatestart', 'rotate', 'rotateend',
'pitchstart', 'pitch', 'pitchend',
'boxzoomstart', 'boxzoomend', 'boxzoomcancel'
'boxzoomstart', 'boxzoomend', 'boxzoomcancel',
'renderstable'
].forEach(function (type) {
var name = 'show-' + type;
var input = document.createElement('input');
Expand Down
38 changes: 24 additions & 14 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,18 +793,11 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
},

/**
* Is this map fully loaded? If the style isn't loaded
* or it has a change to the sources or style that isn't
* propagated to its style, return false.
*
* @returns {boolean} whether the map is loaded
* @returns {boolean} True if all the resources needed to display the
* current viewport have been loaded.
*/
loaded: function() {
if (this._styleDirty || this._sourcesDirty)
return false;
if (!this.style || !this.style.loaded())
return false;
return true;
isRenderStable: function() {
return (!this._styleDirty && !this.sourcesDirty && this.style && this.style.loaded());
},

/**
Expand Down Expand Up @@ -854,9 +847,18 @@ util.extend(Map.prototype, /** @lends Map.prototype */{

this.fire('render');

if (this.loaded() && !this._loaded) {
this._loaded = true;
this.fire('load');
if (this.isRenderStable()) {
if (!this._wasLoaded) {
this._wasLoaded = true;
this.fire('load');
}

if (!this._wasRenderStable) {
this._wasRenderStable = true;
this.fire('renderstable');
}
} else {
this._wasRenderStable = false;
}

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

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

Expand Down Expand Up @@ -962,6 +967,11 @@ util.extend(Map.prototype, /** @lends Map.prototype */{

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

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

Expand Down

0 comments on commit d695605

Please sign in to comment.