From b5944e173546c5e39a33a6361c6a9fa99eb635fa Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 8 Apr 2016 18:41:02 +0200 Subject: [PATCH 1/3] Assert fovy is a number before computing distance resolution --- src/camera.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/camera.js b/src/camera.js index 5f11c3016..eadb936f9 100644 --- a/src/camera.js +++ b/src/camera.js @@ -496,6 +496,7 @@ olcs.Camera.prototype.calcDistanceForResolution_ = function(resolution, latitude) { var canvas = this.scene_.canvas; var fovy = this.cam_.frustum.fovy; // vertical field of view + goog.asserts.assert(!isNaN(fovy)); var metersPerUnit = this.view_.getProjection().getMetersPerUnit(); // number of "map units" visible in 2D (vertically) From 3eb63e13ac7df72f05b311fc9ce00e0a335ce48d Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 8 Apr 2016 18:43:42 +0200 Subject: [PATCH 2/3] Throw early if OL3 map is not initialised OL3-Cesium needs the center and resolution. --- src/ol3cesium.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ol3cesium.js b/src/ol3cesium.js index aa3ff5f08..82092ad2e 100644 --- a/src/ol3cesium.js +++ b/src/ol3cesium.js @@ -306,7 +306,7 @@ olcs.OLCesium.prototype.getEnabled = function() { * @api */ olcs.OLCesium.prototype.setEnabled = function(enable) { - if (this.enabled_ == enable) { + if (this.enabled_ === enable) { return; } this.enabled_ = enable; @@ -315,6 +315,7 @@ olcs.OLCesium.prototype.setEnabled = function(enable) { // so we can't remove it from DOM or even make display:none; this.container_.style.visibility = this.enabled_ ? 'visible' : 'hidden'; if (this.enabled_) { + this.throwOnUnitializedMap_(); if (this.isOverMap_) { var interactions = this.map_.getInteractions(); interactions.forEach(function(el, i, arr) { @@ -361,6 +362,7 @@ olcs.OLCesium.prototype.warmUp = function(height, timeout) { // already enabled return; } + this.throwOnUnitializedMap_(); this.camera_.readFromView(); var ellipsoid = this.globe_.ellipsoid; var csCamera = this.scene_.camera; @@ -436,3 +438,18 @@ olcs.OLCesium.prototype.setResolutionScale = function(value) { } } }; + + +/** + * Check if OL3 map is not properly initialized. + * @private + */ +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) { + throw new Error('The OL3 map is not properly initialized: ' + + center + ' / ' + resolution); + } +}; From e5e1d964efffe11c4f28f67c0a4c16a7b0f83fe9 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 8 Apr 2016 18:45:32 +0200 Subject: [PATCH 3/3] 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()); } };