move back rendering freeze/unfreeze and animation from map renderer to map
This commit is contained in:
@@ -105,6 +105,24 @@ ol.Map = function(
|
|||||||
*/
|
*/
|
||||||
this.pixelToCoordinateMatrix_ = goog.vec.Mat4.createNumber();
|
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
|
* @private
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -156,6 +174,12 @@ ol.Map = function(
|
|||||||
this.renderer_ = new rendererConstructor(target, this);
|
this.renderer_ = new rendererConstructor(target, this);
|
||||||
this.registerDisposable(this.renderer_);
|
this.registerDisposable(this.renderer_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.MapAnimation}
|
||||||
|
*/
|
||||||
|
this.animation_ = new ol.MapAnimation(this.renderer_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Element}
|
* @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 {function(this: T)} f Function.
|
||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
ol.Map.prototype.withFrozenRendering = function(f, opt_obj) {
|
||||||
this.renderer_.freezeRendering();
|
this.freezeRendering();
|
||||||
try {
|
try {
|
||||||
f.call(opt_obj);
|
f.call(opt_obj);
|
||||||
} finally {
|
} 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,31 +31,6 @@ ol.MapRenderer = function(target, map) {
|
|||||||
*/
|
*/
|
||||||
this.map = 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
|
* @protected
|
||||||
* @type {Object.<number, ol.LayerRenderer>}
|
* @type {Object.<number, ol.LayerRenderer>}
|
||||||
@@ -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.
|
* @return {boolean} Animating.
|
||||||
*/
|
*/
|
||||||
ol.MapRenderer.prototype.renderInternal = function() {
|
ol.MapRenderer.prototype.render = function() {
|
||||||
this.dirty_ = false;
|
|
||||||
var animate = false;
|
var animate = false;
|
||||||
this.forEachReadyVisibleLayer(function(layer, layerRenderer) {
|
this.forEachReadyVisibleLayer(function(layer, layerRenderer) {
|
||||||
if (layerRenderer.render()) {
|
if (layerRenderer.render()) {
|
||||||
@@ -320,61 +278,3 @@ ol.MapRenderer.prototype.renderInternal = function() {
|
|||||||
});
|
});
|
||||||
return animate;
|
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ ol.webgl.MapRenderer.prototype.isImageTextureLoaded = function(image) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.webgl.MapRenderer.prototype.renderInternal = function() {
|
ol.webgl.MapRenderer.prototype.render = function() {
|
||||||
|
|
||||||
if (!this.getMap().isDef()) {
|
if (!this.getMap().isDef()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -525,7 +525,7 @@ ol.webgl.MapRenderer.prototype.renderInternal = function() {
|
|||||||
|
|
||||||
var size = this.getMap().getSize();
|
var size = this.getMap().getSize();
|
||||||
|
|
||||||
var animate = goog.base(this, 'renderInternal');
|
var animate = goog.base(this, 'render');
|
||||||
|
|
||||||
var gl = this.getGL();
|
var gl = this.getGL();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user