Common method for conditionally rendering.

This commit is contained in:
Tim Schaub
2012-06-22 20:37:29 +02:00
parent b986395358
commit 787f2ba979

View File

@@ -293,7 +293,10 @@ ol.Map.prototype.setUserProjection = function(userProjection) {
* @param {number} zoom Zoom.
*/
ol.Map.prototype.setZoom = function(zoom) {
this.zoom_ = zoom;
if (zoom !== this.zoom_) {
this.zoom_ = zoom;
this.conditionallyRender();
}
};
@@ -360,6 +363,13 @@ ol.Map.prototype.setContainer = function(container) {
// controls place on overlays.
this.setControls(ol.Map.DEFAULT_CONTROLS);
// conditionally render
this.conditionallyRender();
};
/**
* Check if everything is ready. Render if so.
*/
ol.Map.prototype.conditionallyRender = function() {
if (!goog.isNull(this.layers_) && goog.isDef(this.zoom_) && !goog.isNull(this.center_)) {
this.renderer_.draw(this.layers_, this.center_, this.getResolutionForZoom(this.zoom_));
}