Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't render if width or height is 0. #896

Merged
merged 4 commits into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Beta Releases
* `ImageryProvider.loadImage` now requires that the calling imagery provider instance be passed as its first parameter.
* Removed `CesiumViewerWidget` and replaced it with a new `Viewer` widget with mixin architecture. This new widget does not depend on Dojo and is part of the combined Cesium.js file. It is intended to be a flexible base widget for easily building robust applications. See [#838](https://github.com/AnalyticalGraphicsInc/cesium/pull/838) for the full details.
* Removed the Dojo-based `checkForChromeFrame` function, and replaced it with a new standalone version that returns a promise to signal when the asynchronous check has completed.
* Fix resizing issues in `CesiumWidget` ([#608](https://github.com/AnalyticalGraphicsInc/cesium/issues/608), [#834](https://github.com/AnalyticalGraphicsInc/cesium/issues/834)).
* Added initial support for [GeoJSON](http://www.geojson.org/) see [#890](https://github.com/AnalyticalGraphicsInc/cesium/pull/890) for details.
* Added `Context.getAntialias`.
* Added rotation, aligned axis, width, and height properties to `Billboard`s.
Expand All @@ -29,7 +30,6 @@ Beta Releases
* Added the ability to unsubscribe to `Timeline` update event.
* Added a `screenSpaceEventHandler` property to `CesiumWidget`. Also added a `sceneMode` option to the constructor to set the initial scene mode.
* Added `useDefaultRenderLoop` property to `CesiumWidget` that allows the default render loop to be disabled so that a custom render loop can be used.
* Fix resizing issues in `CesiumWidget` ([#608](https://github.com/AnalyticalGraphicsInc/cesium/issues/608)) by having the default render loop force a resize event every 60 frames.
* Added `CesiumWidget.onRenderLoopError` which is an `Event` that is raised if an exception is generated inside of the default render loop.
* `ImageryProviderViewModel.creationCommand` can now return an array of ImageryProvider instances, which allows adding multiple layers when a single item is selected in the `BaseLayerPicker` widget.
* Changed static `clone` functions in all objects such that if the object being cloned is undefined, the function will return undefined instead of throwing an exception
Expand Down
49 changes: 24 additions & 25 deletions Source/Widgets/CesiumWidget/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ define([
function render() {
try {
if (widget._useDefaultRenderLoop) {
var frameNumber = widget._scene.getFrameState().frameNumber;
if (widget._needResize || (frameNumber % 60) === 0) {
widget.resize();
}
widget.resize();
widget.render();
requestAnimationFrame(render);
} else {
Expand Down Expand Up @@ -182,6 +179,8 @@ define([
this._element = widgetNode;
this._container = container;
this._canvas = canvas;
this._canvasWidth = canvas.width;
this._canvasHeight = canvas.height;
this._cesiumLogo = cesiumLogo;
this._scene = scene;
this._centralBody = centralBody;
Expand All @@ -190,6 +189,7 @@ define([
this._screenSpaceEventHandler = new ScreenSpaceEventHandler(canvas);
this._useDefaultRenderLoop = undefined;
this._renderLoopRunning = false;
this._canRender = false;

if (options.sceneMode) {
if (options.sceneMode === SceneMode.SCENE2D) {
Expand All @@ -200,14 +200,6 @@ define([
}
}

var that = this;
//Subscribe for resize events and set the initial size.
this._needResize = true;
this._resizeCallback = function() {
that._needResize = true;
};
window.addEventListener('resize', this._resizeCallback, false);

this.useDefaultRenderLoop = defaultValue(options.useDefaultRenderLoop, true);
};

Expand Down Expand Up @@ -362,7 +354,6 @@ define([
* @memberof CesiumWidget
*/
CesiumWidget.prototype.destroy = function() {
window.removeEventListener('resize', this._resizeCallback, false);
this._container.removeChild(this._element);
destroyObject(this);
};
Expand All @@ -374,21 +365,27 @@ define([
* @memberof CesiumWidget
*/
CesiumWidget.prototype.resize = function() {
var width = this._canvas.clientWidth;
var height = this._canvas.clientHeight;
if (this._canvas.width === width && this._canvas.height === height) {
var canvas = this._canvas;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (this._canvasWidth === width && this._canvasHeight === height) {
return;
}

this._canvas.width = width;
this._canvas.height = height;
canvas.width = this._canvasWidth = width;
canvas.height = this._canvasHeight = height;

var frustum = this._scene.getCamera().frustum;
if (typeof frustum.aspectRatio !== 'undefined') {
frustum.aspectRatio = width / height;
} else {
frustum.top = frustum.right * (height / width);
frustum.bottom = -frustum.top;
var canRender = width !== 0 && height !== 0;
this._canRender = canRender;

if (canRender) {
var frustum = this._scene.getCamera().frustum;
if (typeof frustum.aspectRatio !== 'undefined') {
frustum.aspectRatio = width / height;
} else {
frustum.top = frustum.right * (height / width);
frustum.bottom = -frustum.top;
}
}
};

Expand All @@ -400,7 +397,9 @@ define([
CesiumWidget.prototype.render = function() {
var currentTime = this._clock.tick();
this._scene.initializeFrame();
this._scene.render(currentTime);
if (this._canRender) {
this._scene.render(currentTime);
}
};

return CesiumWidget;
Expand Down
9 changes: 0 additions & 9 deletions Source/Widgets/Viewer/Viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
height: 100%;
}

.cesium-viewer-canvas {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.cesium-viewer-timelineContainer {
position: absolute;
bottom: 0;
Expand Down
19 changes: 3 additions & 16 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ define([
function render() {
try {
if (viewer._useDefaultRenderLoop) {
var frameNumber = viewer._cesiumWidget._scene.getFrameState().frameNumber;
if (viewer._needResize || (frameNumber % 60) === 0) {
viewer.resize();
}
viewer.resize();
viewer.render();
requestAnimationFrame(render);
} else {
Expand Down Expand Up @@ -192,14 +189,6 @@ Either specify options.imageryProvider instead or set options.baseLayerPicker to
useDefaultRenderLoop : false
});

//Subscribe for resize events and set the initial size.
var that = this;
this._needResize = true;
this._resizeCallback = function() {
that._needResize = true;
};
window.addEventListener('resize', this._resizeCallback, false);

//Data source display
var dataSourceDisplay = new DataSourceDisplay(cesiumWidget.scene);
this._dataSourceDisplay = dataSourceDisplay;
Expand Down Expand Up @@ -573,7 +562,8 @@ Either specify options.imageryProvider instead or set options.baseLayerPicker to
* @memberof Viewer
*/
Viewer.prototype.resize = function() {
this._needResize = false;
var cesiumWidget = this._cesiumWidget;
cesiumWidget.resize();

var container = this._container;
var width = container.clientWidth;
Expand All @@ -582,9 +572,6 @@ Either specify options.imageryProvider instead or set options.baseLayerPicker to
return;
}

var cesiumWidget = this._cesiumWidget;
cesiumWidget.resize();

var baseLayerPickerDropDown = this._baseLayerPickerDropDown;
if (typeof baseLayerPickerDropDown !== 'undefined') {
var baseLayerPickerMaxHeight = height - 125;
Expand Down