Skip to content

Commit 28b641d

Browse files
committed
Merge pull request #129 from gberaudo/olcs_warmup
Olcs warmup
2 parents aae0396 + a08d72d commit 28b641d

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/ol3cesium.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ olcs.OLCesium = function(map, opt_target) {
146146
this.cesiumRenderingDelay_ = new goog.async.AnimationDelay(function(time) {
147147
this.scene_.initializeFrame();
148148
this.scene_.render();
149-
this.camera_.checkCameraChange();
150-
149+
this.enabled_ && this.camera_.checkCameraChange();
151150
this.cesiumRenderingDelay_.start();
152151
}, undefined, this);
153152
};
@@ -244,3 +243,30 @@ olcs.OLCesium.prototype.setEnabled = function(opt_enable) {
244243
this.cesiumRenderingDelay_.stop();
245244
}
246245
};
246+
247+
248+
/**
249+
* Preload Cesium so that it is ready when transitioning from 2D to 3D.
250+
* @param {number} height Target height of the camera
251+
* @param {number} timeout Milliseconds after which the warming will stop
252+
* @api
253+
*/
254+
olcs.OLCesium.prototype.warmUp = function(height, timeout) {
255+
if (this.enabled_) {
256+
// already enabled
257+
return;
258+
}
259+
this.camera_.readFromView();
260+
var ellipsoid = this.globe_.ellipsoid;
261+
var csCamera = this.scene_.camera;
262+
var position = ellipsoid.cartesianToCartographic(csCamera.position);
263+
if (position.height < height) {
264+
position.height = height;
265+
csCamera.position = ellipsoid.cartographicToCartesian(position);
266+
}
267+
this.cesiumRenderingDelay_.start();
268+
var that = this;
269+
setTimeout(
270+
function() { !that.enabled_ && that.cesiumRenderingDelay_.stop(); },
271+
timeout);
272+
};

0 commit comments

Comments
 (0)