diff --git a/src/ol/base/map.js b/src/ol/base/map.js index 88a17e811d..5789d72685 100644 --- a/src/ol/base/map.js +++ b/src/ol/base/map.js @@ -105,6 +105,24 @@ ol.Map = function( */ this.pixelToCoordinateMatrix_ = goog.vec.Mat4.createNumber(); + /** + * @private + * @type {boolean} + */ + this.animating_ = false; + + /** + * @private + * @type {boolean} + */ + this.dirty_ = false; + + /** + * @private + * @type {number} + */ + this.freezeRenderingCount_ = 0; + /** * @private * @type {boolean} @@ -156,6 +174,12 @@ ol.Map = function( this.renderer_ = new rendererConstructor(target, this); this.registerDisposable(this.renderer_); + /** + * @private + * @type {ol.MapAnimation} + */ + this.animation_ = new ol.MapAnimation(this.renderer_); + /** * @private * @type {Element} @@ -753,16 +777,89 @@ ol.Map.prototype.updateMatrices_ = function() { }; +/** + */ +ol.Map.prototype.render = function() { + if (!this.animating_) { + if (this.freezeRenderingCount_ === 0) { + if (this.renderer_.render()) { + this.animate_(); + } + } else { + this.dirty_ = true; + } + } +}; + + +/** + * @private + */ +ol.Map.prototype.animate_ = function() { + goog.asserts.assert(!this.animating_); + goog.fx.anim.registerAnimation(this.animation_); + this.animating_ = true; +}; + + /** * @param {function(this: T)} f Function. * @param {T=} opt_obj Object. * @template T */ ol.Map.prototype.withFrozenRendering = function(f, opt_obj) { - this.renderer_.freezeRendering(); + this.freezeRendering(); try { f.call(opt_obj); } finally { - this.renderer_.unfreezeRendering(); + this.unfreezeRendering(); + } +}; + + +/** + */ +ol.Map.prototype.freezeRendering = function() { + ++this.freezeRenderingCount_; +}; + + +/** + */ +ol.Map.prototype.unfreezeRendering = function() { + goog.asserts.assert(this.freezeRenderingCount_ > 0); + if (--this.freezeRenderingCount_ === 0) { + if (!this.animating_ && this.dirty_) { + if (this.renderer_.render()) { + this.animate_(); + } + } + } +}; + + + +/** + * @constructor + * @implements {goog.fx.anim.Animated} + * @param {!ol.MapRenderer} renderer Map renderer. + */ +ol.MapAnimation = function(renderer) { + + /** + * @private + * @type {ol.MapRenderer} + */ + this.renderer_ = renderer; + +}; + + +/** + * @inheritDoc + */ +ol.MapAnimation.prototype.onAnimationFrame = function() { + if (!this.renderer_.render()) { + goog.fx.anim.unregisterAnimation(this); } }; diff --git a/src/ol/base/maprenderer.js b/src/ol/base/maprenderer.js index cbb0cca078..a2fa959ec6 100644 --- a/src/ol/base/maprenderer.js +++ b/src/ol/base/maprenderer.js @@ -31,31 +31,6 @@ ol.MapRenderer = function(target, map) { */ this.map = map; - /** - * @private - * @type {ol.MapRendererAnimation} - */ - this.animation_ = new ol.MapRendererAnimation(this); - - /** - * @private - * @type {boolean} - */ - this.animating_ = false; - - /** - * @private - * @type {boolean} - */ - this.dirty_ = false; - - /** - * @private - * @type {number} - */ - this.freezeRenderingCount_ = 0; - - /** * @protected * @type {Object.} @@ -292,26 +267,9 @@ ol.MapRenderer.prototype.handleSizeChanged = goog.nullFunction; /** - */ -ol.MapRenderer.prototype.render = function() { - if (!this.animating_) { - if (this.freezeRenderingCount_ === 0) { - if (this.renderInternal()) { - this.animate_(); - } - } else { - this.dirty_ = true; - } - } -}; - - -/** - * @protected * @return {boolean} Animating. */ -ol.MapRenderer.prototype.renderInternal = function() { - this.dirty_ = false; +ol.MapRenderer.prototype.render = function() { var animate = false; this.forEachReadyVisibleLayer(function(layer, layerRenderer) { if (layerRenderer.render()) { @@ -320,61 +278,3 @@ ol.MapRenderer.prototype.renderInternal = function() { }); return animate; }; - - -/** - * @private - */ -ol.MapRenderer.prototype.animate_ = function() { - goog.asserts.assert(!this.animating_); - goog.fx.anim.registerAnimation(this.animation_); - this.animating_ = true; -}; - - -/** - */ -ol.MapRenderer.prototype.freezeRendering = function() { - ++this.freezeRenderingCount_; -}; - - -/** - */ -ol.MapRenderer.prototype.unfreezeRendering = function() { - goog.asserts.assert(this.freezeRenderingCount_ > 0); - if (--this.freezeRenderingCount_ === 0) { - if (!this.animating_ && this.dirty_) { - if (this.renderInternal()) { - this.animate_(); - } - } - } -}; - - - -/** - * @constructor - * @implements {goog.fx.anim.Animated} - * @param {!ol.MapRenderer} renderer renderer. - */ -ol.MapRendererAnimation = function(renderer) { - - /** - * @private - * @type {ol.MapRenderer} - */ - this.renderer_ = renderer; - -}; - - -/** - * @inheritDoc - */ -ol.MapRendererAnimation.prototype.onAnimationFrame = function() { - if (!this.renderer_.renderInternal()) { - goog.fx.anim.unregisterAnimation(this); - } -}; diff --git a/src/ol/webgl/maprenderer.js b/src/ol/webgl/maprenderer.js index aad37c6427..a923626336 100644 --- a/src/ol/webgl/maprenderer.js +++ b/src/ol/webgl/maprenderer.js @@ -517,7 +517,7 @@ ol.webgl.MapRenderer.prototype.isImageTextureLoaded = function(image) { /** * @inheritDoc */ -ol.webgl.MapRenderer.prototype.renderInternal = function() { +ol.webgl.MapRenderer.prototype.render = function() { if (!this.getMap().isDef()) { return false; @@ -525,7 +525,7 @@ ol.webgl.MapRenderer.prototype.renderInternal = function() { var size = this.getMap().getSize(); - var animate = goog.base(this, 'renderInternal'); + var animate = goog.base(this, 'render'); var gl = this.getGL();