Implement @elemoine's requestRenderFrame architecture
This commit is contained in:
110
src/ol/map.js
110
src/ol/map.js
@@ -8,6 +8,7 @@ goog.provide('ol.MapProperty');
|
|||||||
goog.provide('ol.RendererHint');
|
goog.provide('ol.RendererHint');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.async.AnimationDelay');
|
||||||
goog.require('goog.debug.Logger');
|
goog.require('goog.debug.Logger');
|
||||||
goog.require('goog.dispose');
|
goog.require('goog.dispose');
|
||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
@@ -22,8 +23,6 @@ goog.require('goog.events.MouseWheelEvent');
|
|||||||
goog.require('goog.events.MouseWheelHandler');
|
goog.require('goog.events.MouseWheelHandler');
|
||||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||||
goog.require('goog.functions');
|
goog.require('goog.functions');
|
||||||
goog.require('goog.fx.anim');
|
|
||||||
goog.require('goog.fx.anim.Animated');
|
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.BrowserFeature');
|
goog.require('ol.BrowserFeature');
|
||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
@@ -115,7 +114,6 @@ ol.MapProperty = {
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.Object}
|
* @extends {ol.Object}
|
||||||
* @implements {goog.fx.anim.Animated}
|
|
||||||
* @param {ol.MapOptions} mapOptions Map options.
|
* @param {ol.MapOptions} mapOptions Map options.
|
||||||
*/
|
*/
|
||||||
ol.Map = function(mapOptions) {
|
ol.Map = function(mapOptions) {
|
||||||
@@ -146,15 +144,11 @@ ol.Map = function(mapOptions) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {boolean}
|
* @type {goog.async.AnimationDelay}
|
||||||
*/
|
*/
|
||||||
this.animatedRenderer_ = false;
|
this.animationDelay_ =
|
||||||
|
new goog.async.AnimationDelay(this.renderFrame_, undefined, this);
|
||||||
/**
|
this.registerDisposable(this.animationDelay_);
|
||||||
* @private
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
this.animatingCount_ = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -652,14 +646,6 @@ ol.Map.prototype.handleBrowserWindowResize = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {boolean} Is animating.
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.isAnimating = function() {
|
|
||||||
return this.animatingCount_ > 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean} Is defined.
|
* @return {boolean} Is defined.
|
||||||
*/
|
*/
|
||||||
@@ -670,17 +656,6 @@ ol.Map.prototype.isDef = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.onAnimationFrame = function() {
|
|
||||||
if (goog.DEBUG) {
|
|
||||||
this.logger.info('onAnimationFrame');
|
|
||||||
}
|
|
||||||
this.renderFrame_();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@@ -704,33 +679,43 @@ ol.Map.prototype.recalculateTransforms_ = function() {
|
|||||||
* Render.
|
* Render.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.render = function() {
|
ol.Map.prototype.render = function() {
|
||||||
if (this.animatingCount_ < 1) {
|
if (this.animationDelay_.isActive()) {
|
||||||
if (this.freezeRenderingCount_ === 0) {
|
// pass
|
||||||
this.renderFrame_();
|
} else if (this.freezeRenderingCount_ === 0) {
|
||||||
} else {
|
this.animationDelay_.fire();
|
||||||
this.dirty_ = true;
|
} else {
|
||||||
}
|
this.dirty_ = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Request that render be called some time in the future.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.requestRenderFrame = function() {
|
||||||
|
if (this.freezeRenderingCount_ === 0) {
|
||||||
|
if (!this.animationDelay_.isActive()) {
|
||||||
|
this.animationDelay_.start();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.dirty_ = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} time Time.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.renderFrame_ = function() {
|
ol.Map.prototype.renderFrame_ = function(time) {
|
||||||
|
if (this.freezeRenderingCount_ != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (goog.DEBUG) {
|
if (goog.DEBUG) {
|
||||||
this.logger.info('renderFrame_');
|
this.logger.info('renderFrame_');
|
||||||
}
|
}
|
||||||
var animatedRenderer = this.renderer_.render();
|
this.renderer_.render();
|
||||||
this.dirty_ = false;
|
this.dirty_ = false;
|
||||||
if (animatedRenderer != this.animatedRenderer_) {
|
|
||||||
if (animatedRenderer) {
|
|
||||||
this.startAnimating();
|
|
||||||
} else {
|
|
||||||
this.stopAnimating();
|
|
||||||
}
|
|
||||||
this.animatedRenderer_ = animatedRenderer;
|
|
||||||
}
|
|
||||||
if (goog.DEBUG) {
|
if (goog.DEBUG) {
|
||||||
this.logger.info('postrender');
|
this.logger.info('postrender');
|
||||||
}
|
}
|
||||||
@@ -852,42 +837,13 @@ goog.exportProperty(
|
|||||||
ol.Map.prototype.setUserProjection);
|
ol.Map.prototype.setUserProjection);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start animating.
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.startAnimating = function() {
|
|
||||||
if (++this.animatingCount_ == 1) {
|
|
||||||
if (goog.DEBUG) {
|
|
||||||
this.logger.info('startAnimating');
|
|
||||||
}
|
|
||||||
goog.fx.anim.registerAnimation(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop animating.
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.stopAnimating = function() {
|
|
||||||
goog.asserts.assert(this.animatingCount_ > 0);
|
|
||||||
if (--this.animatingCount_ === 0) {
|
|
||||||
if (goog.DEBUG) {
|
|
||||||
this.logger.info('stopAnimating');
|
|
||||||
}
|
|
||||||
goog.fx.anim.unregisterAnimation(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unfreeze rendering.
|
* Unfreeze rendering.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.unfreezeRendering = function() {
|
ol.Map.prototype.unfreezeRendering = function() {
|
||||||
goog.asserts.assert(this.freezeRenderingCount_ > 0);
|
goog.asserts.assert(this.freezeRenderingCount_ > 0);
|
||||||
if (--this.freezeRenderingCount_ === 0 &&
|
if (--this.freezeRenderingCount_ === 0 && this.dirty_) {
|
||||||
this.animatingCount_ < 1 &&
|
this.animationDelay_.fire();
|
||||||
this.dirty_) {
|
|
||||||
this.renderFrame_();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -184,13 +184,11 @@ ol.renderer.dom.Map.prototype.handleSizeChanged = function() {
|
|||||||
/**
|
/**
|
||||||
* Render the map. Sets up the layers pane on first render and adjusts its
|
* Render the map. Sets up the layers pane on first render and adjusts its
|
||||||
* position as needed on subsequent calls.
|
* position as needed on subsequent calls.
|
||||||
*
|
|
||||||
* @return {boolean} Animating.
|
|
||||||
*/
|
*/
|
||||||
ol.renderer.dom.Map.prototype.render = function() {
|
ol.renderer.dom.Map.prototype.render = function() {
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
if (!map.isDef()) {
|
if (!map.isDef()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapCenter = map.getCenter();
|
var mapCenter = map.getCenter();
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ ol.renderer.Map.prototype.removeLayerRenderer = function(layer) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean} Animating.
|
* Render.
|
||||||
*/
|
*/
|
||||||
ol.renderer.Map.prototype.render = goog.functions.FALSE;
|
ol.renderer.Map.prototype.render = goog.functions.FALSE;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user