Skip to content

Commit

Permalink
Merge pull request #340 from gberaudo/fix_frustum_aspect_ratio_and_ch…
Browse files Browse the repository at this point in the history
…eck_earlier

Fix frustum aspect ratio and check earlier
  • Loading branch information
gberaudo committed Apr 13, 2016
2 parents ee9231b + e5e1d96 commit e02ab3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion src/ol3cesium.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -306,7 +311,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;
Expand All @@ -315,6 +320,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) {
Expand Down Expand Up @@ -361,6 +367,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;
Expand Down Expand Up @@ -436,3 +443,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 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 + ' / ' + view.getResolution());
}
};

0 comments on commit e02ab3b

Please sign in to comment.