From e5e1d964efffe11c4f28f67c0a4c16a7b0f83fe9 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 8 Apr 2016 18:45:32 +0200 Subject: [PATCH] Fix bad computation of aspect ratio In some cases, the frustum aspect ratio was set to NaN, which was breaking Cesium. --- src/ol3cesium.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ol3cesium.js b/src/ol3cesium.js index 82092ad2e..3adfc3763 100644 --- a/src/ol3cesium.js +++ b/src/ol3cesium.js @@ -221,6 +221,11 @@ olcs.OLCesium.prototype.handleResize_ = function() { var width = this.canvas_.clientWidth; var height = this.canvas_.clientHeight; + if (width === 0 | height === 0) { + // The canvas DOM element is not ready yet. + return; + } + if (width === this.canvasClientWidth_ && height === this.canvasClientHeight_ && !this.resolutionScaleChanged_) { @@ -446,10 +451,10 @@ olcs.OLCesium.prototype.setResolutionScale = function(value) { */ olcs.OLCesium.prototype.throwOnUnitializedMap_ = function() { var map = this.map_; - var center = map.getView().getCenter(); - var resolution = map.getView().getResolution(); - if (!center || isNaN(center[0]) || isNaN(center[1]) || !resolution) { + var view = map.getView(); + var center = view.getCenter(); + if (!view.isDef() || isNaN(center[0]) || isNaN(center[1])) { throw new Error('The OL3 map is not properly initialized: ' + - center + ' / ' + resolution); + center + ' / ' + view.getResolution()); } };