/
CesiumWidget.js
693 lines (623 loc) · 33.5 KB
/
CesiumWidget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*global define*/
define([
'../../Core/buildModuleUrl',
'../../Core/Cartesian3',
'../../Core/Clock',
'../../Core/Credit',
'../../Core/defaultValue',
'../../Core/defined',
'../../Core/defineProperties',
'../../Core/destroyObject',
'../../Core/DeveloperError',
'../../Core/Ellipsoid',
'../../Core/FeatureDetection',
'../../Core/formatError',
'../../Core/requestAnimationFrame',
'../../Core/ScreenSpaceEventHandler',
'../../Scene/BingMapsImageryProvider',
'../../Scene/Globe',
'../../Scene/Moon',
'../../Scene/Scene',
'../../Scene/SceneMode',
'../../Scene/ShadowMode',
'../../Scene/SkyAtmosphere',
'../../Scene/SkyBox',
'../../Scene/Sun',
'../getElement'
], function(
buildModuleUrl,
Cartesian3,
Clock,
Credit,
defaultValue,
defined,
defineProperties,
destroyObject,
DeveloperError,
Ellipsoid,
FeatureDetection,
formatError,
requestAnimationFrame,
ScreenSpaceEventHandler,
BingMapsImageryProvider,
Globe,
Moon,
Scene,
SceneMode,
ShadowMode,
SkyAtmosphere,
SkyBox,
Sun,
getElement) {
'use strict';
function getDefaultSkyBoxUrl(suffix) {
return buildModuleUrl('Assets/Textures/SkyBox/tycho2t3_80_' + suffix + '.jpg');
}
function startRenderLoop(widget) {
widget._renderLoopRunning = true;
var lastFrameTime = 0;
function render(frameTime) {
if (widget.isDestroyed()) {
return;
}
if (widget._useDefaultRenderLoop) {
try {
var targetFrameRate = widget._targetFrameRate;
if (!defined(targetFrameRate)) {
widget.resize();
widget.render();
requestAnimationFrame(render);
} else {
var interval = 1000.0 / targetFrameRate;
var delta = frameTime - lastFrameTime;
if (delta > interval) {
widget.resize();
widget.render();
lastFrameTime = frameTime - (delta % interval);
}
requestAnimationFrame(render);
}
} catch (error) {
widget._useDefaultRenderLoop = false;
widget._renderLoopRunning = false;
if (widget._showRenderLoopErrors) {
var title = 'An error occurred while rendering. Rendering has stopped.';
widget.showErrorPanel(title, undefined, error);
}
}
} else {
widget._renderLoopRunning = false;
}
}
requestAnimationFrame(render);
}
function configureCanvasSize(widget) {
var canvas = widget._canvas;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
var resolutionScale = widget._resolutionScale;
if (!widget._supportsImageRenderingPixelated) {
resolutionScale *= defaultValue(window.devicePixelRatio, 1.0);
}
widget._canvasWidth = width;
widget._canvasHeight = height;
width *= resolutionScale;
height *= resolutionScale;
canvas.width = width;
canvas.height = height;
widget._canRender = width !== 0 && height !== 0;
}
function configureCameraFrustum(widget) {
var canvas = widget._canvas;
var width = canvas.width;
var height = canvas.height;
if (width !== 0 && height !== 0) {
var frustum = widget._scene.camera.frustum;
if (defined(frustum.aspectRatio)) {
frustum.aspectRatio = width / height;
} else {
frustum.top = frustum.right * (height / width);
frustum.bottom = -frustum.top;
}
}
}
var cesiumLogoData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHYAAAAaCAYAAABikagwAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAN1wAADdcBQiibeAAAAAd0SU1FB9wGGRQyF371QVsAABOHSURBVGje7Vp5cFTHmf91v2Nm3owGnYMuEEJCOBiEjDlsDMYQjGMOOwmXcWxiLywpJ9iuTXZd612corJssFOxi8LerXizxEGUvWsivNxxHHCQ8WYBYSFzmUMCCXQjaUajOd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containing a Cesium scene.
*
* @alias CesiumWidget
* @constructor
*
* @param {Element|String} container The DOM element or ID that will contain the widget.
* @param {Object} [options] Object with the following properties:
* @param {Clock} [options.clock=new Clock()] The clock to use to control current time.
* @param {ImageryProvider} [options.imageryProvider=new BingMapsImageryProvider()] The imagery provider to serve as the base layer. If set to <code>false</code>, no imagery provider will be added.
* @param {TerrainProvider} [options.terrainProvider=new EllipsoidTerrainProvider] The terrain provider.
* @param {SkyBox} [options.skyBox] The skybox used to render the stars. When <code>undefined</code>, the default stars are used. If set to <code>false</code>, no skyBox, Sun, or Moon will be added.
* @param {SkyAtmosphere} [options.skyAtmosphere] Blue sky, and the glow around the Earth's limb. Set to <code>false</code> to turn it off.
* @param {SceneMode} [options.sceneMode=SceneMode.SCENE3D] The initial scene mode.
* @param {Boolean} [options.scene3DOnly=false] When <code>true</code>, each geometry instance will only be rendered in 3D to save GPU memory.
* @param {Boolean} [options.orderIndependentTranslucency=true] If true and the configuration supports it, use order independent translucency.
* @param {MapProjection} [options.mapProjection=new GeographicProjection()] The map projection to use in 2D and Columbus View modes.
* @param {Globe} [options.globe=new Globe(mapProjection.ellipsoid)] The globe to use in the scene. If set to <code>false</code>, no globe will be added.
* @param {Boolean} [options.useDefaultRenderLoop=true] True if this widget should control the render loop, false otherwise.
* @param {Number} [options.targetFrameRate] The target frame rate when using the default render loop.
* @param {Boolean} [options.showRenderLoopErrors=true] If true, this widget will automatically display an HTML panel to the user containing the error, if a render loop error occurs.
* @param {Object} [options.contextOptions] Context and WebGL creation properties corresponding to <code>options</code> passed to {@link Scene}.
* @param {Element|String} [options.creditContainer] The DOM element or ID that will contain the {@link CreditDisplay}. If not specified, the credits are added
* to the bottom of the widget itself.
* @param {Number} [options.terrainExaggeration=1.0] A scalar used to exaggerate the terrain. Note that terrain exaggeration will not modify any other primitive as they are positioned relative to the ellipsoid.
* @param {Boolean} [options.shadows=false] Determines if shadows are cast by the sun.
* @param {ShadowMode} [options.terrainShadows=ShadowMode.RECEIVE_ONLY] Determines if the terrain casts or receives shadows from the sun.
* @param {MapMode2D} [options.mapMode2D=MapMode2D.INFINITE_SCROLL] Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
*
* @exception {DeveloperError} Element with id "container" does not exist in the document.
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Cesium%20Widget.html|Cesium Sandcastle Cesium Widget Demo}
*
* @example
* // For each example, include a link to CesiumWidget.css stylesheet in HTML head,
* // and in the body, include: <div id="cesiumContainer"></div>
*
* //Widget with no terrain and default Bing Maps imagery provider.
* var widget = new Cesium.CesiumWidget('cesiumContainer');
*
* //Widget with OpenStreetMaps imagery provider and Cesium terrain provider hosted by AGI.
* var widget = new Cesium.CesiumWidget('cesiumContainer', {
* imageryProvider : Cesium.createOpenStreetMapImageryProvider(),
* terrainProvider : new Cesium.CesiumTerrainProvider({
* url : 'https://assets.agi.com/stk-terrain/world'
* }),
* // Use high-res stars downloaded from https://github.com/AnalyticalGraphicsInc/cesium-assets
* skyBox : new Cesium.SkyBox({
* sources : {
* positiveX : 'stars/TychoSkymapII.t3_08192x04096_80_px.jpg',
* negativeX : 'stars/TychoSkymapII.t3_08192x04096_80_mx.jpg',
* positiveY : 'stars/TychoSkymapII.t3_08192x04096_80_py.jpg',
* negativeY : 'stars/TychoSkymapII.t3_08192x04096_80_my.jpg',
* positiveZ : 'stars/TychoSkymapII.t3_08192x04096_80_pz.jpg',
* negativeZ : 'stars/TychoSkymapII.t3_08192x04096_80_mz.jpg'
* }
* }),
* // Show Columbus View map with Web Mercator projection
* sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
* mapProjection : new Cesium.WebMercatorProjection()
* });
*/
function CesiumWidget(container, options) {
//>>includeStart('debug', pragmas.debug);
if (!defined(container)) {
throw new DeveloperError('container is required.');
}
//>>includeEnd('debug');
container = getElement(container);
options = defaultValue(options, {});
//Configure the widget DOM elements
var element = document.createElement('div');
element.className = 'cesium-widget';
container.appendChild(element);
var canvas = document.createElement('canvas');
var supportsImageRenderingPixelated = FeatureDetection.supportsImageRenderingPixelated();
this._supportsImageRenderingPixelated = supportsImageRenderingPixelated;
if (supportsImageRenderingPixelated) {
canvas.style.imageRendering = FeatureDetection.imageRenderingValue();
}
canvas.oncontextmenu = function() {
return false;
};
canvas.onselectstart = function() {
return false;
};
element.appendChild(canvas);
var creditContainer = document.createElement('div');
creditContainer.className = 'cesium-widget-credits';
var creditContainerContainer = defined(options.creditContainer) ? getElement(options.creditContainer) : element;
creditContainerContainer.appendChild(creditContainer);
var showRenderLoopErrors = defaultValue(options.showRenderLoopErrors, true);
this._element = element;
this._container = container;
this._canvas = canvas;
this._canvasWidth = 0;
this._canvasHeight = 0;
this._creditContainer = creditContainer;
this._canRender = false;
this._renderLoopRunning = false;
this._showRenderLoopErrors = showRenderLoopErrors;
this._resolutionScale = 1.0;
this._forceResize = false;
this._clock = defined(options.clock) ? options.clock : new Clock();
configureCanvasSize(this);
try {
var scene = new Scene({
canvas : canvas,
contextOptions : options.contextOptions,
creditContainer : creditContainer,
mapProjection : options.mapProjection,
orderIndependentTranslucency : options.orderIndependentTranslucency,
scene3DOnly : defaultValue(options.scene3DOnly, false),
terrainExaggeration : options.terrainExaggeration,
shadows : options.shadows,
mapMode2D : options.mapMode2D
});
this._scene = scene;
scene.camera.constrainedAxis = Cartesian3.UNIT_Z;
configureCameraFrustum(this);
var ellipsoid = defaultValue(scene.mapProjection.ellipsoid, Ellipsoid.WGS84);
var creditDisplay = scene.frameState.creditDisplay;
var cesiumCredit = new Credit('Cesium', cesiumLogoData, 'http://cesiumjs.org/');
creditDisplay.addDefaultCredit(cesiumCredit);
var globe = options.globe;
if (!defined(globe)) {
globe = new Globe(ellipsoid);
}
if (globe !== false) {
scene.globe = globe;
// If the passed in value is a boolean, convert to the ShadowMode enum.
var terrainShadows = options.terrainShadows;
if (terrainShadows === true) {
scene.globe.shadows = ShadowMode.ENABLED;
} else if (terrainShadows === false) {
scene.globe.shadows = ShadowMode.RECEIVE_ONLY;
} else {
scene.globe.shadows = defaultValue(terrainShadows, ShadowMode.RECEIVE_ONLY);
}
}
var skyBox = options.skyBox;
if (!defined(skyBox)) {
skyBox = new SkyBox({
sources : {
positiveX : getDefaultSkyBoxUrl('px'),
negativeX : getDefaultSkyBoxUrl('mx'),
positiveY : getDefaultSkyBoxUrl('py'),
negativeY : getDefaultSkyBoxUrl('my'),
positiveZ : getDefaultSkyBoxUrl('pz'),
negativeZ : getDefaultSkyBoxUrl('mz')
}
});
}
if (skyBox !== false) {
scene.skyBox = skyBox;
scene.sun = new Sun();
scene.moon = new Moon();
}
// Blue sky, and the glow around the Earth's limb.
var skyAtmosphere = options.skyAtmosphere;
if (!defined(skyAtmosphere)) {
skyAtmosphere = new SkyAtmosphere(ellipsoid);
}
if (skyAtmosphere !== false) {
scene.skyAtmosphere = skyAtmosphere;
}
//Set the base imagery layer
var imageryProvider = (options.globe === false) ? false : options.imageryProvider;
if (!defined(imageryProvider)) {
imageryProvider = new BingMapsImageryProvider({
url : 'https://dev.virtualearth.net'
});
}
if (imageryProvider !== false) {
scene.imageryLayers.addImageryProvider(imageryProvider);
}
//Set the terrain provider if one is provided.
if (defined(options.terrainProvider) && options.globe !== false) {
scene.terrainProvider = options.terrainProvider;
}
this._screenSpaceEventHandler = new ScreenSpaceEventHandler(canvas, false);
if (defined(options.sceneMode)) {
if (options.sceneMode === SceneMode.SCENE2D) {
this._scene.morphTo2D(0);
}
if (options.sceneMode === SceneMode.COLUMBUS_VIEW) {
this._scene.morphToColumbusView(0);
}
}
this._useDefaultRenderLoop = undefined;
this.useDefaultRenderLoop = defaultValue(options.useDefaultRenderLoop, true);
this._targetFrameRate = undefined;
this.targetFrameRate = options.targetFrameRate;
var that = this;
scene.renderError.addEventListener(function(scene, error) {
that._useDefaultRenderLoop = false;
that._renderLoopRunning = false;
if (that._showRenderLoopErrors) {
var title = 'An error occurred while rendering. Rendering has stopped.';
that.showErrorPanel(title, undefined, error);
}
});
} catch (error) {
if (showRenderLoopErrors) {
var title = 'Error constructing CesiumWidget.';
var message = 'Visit <a href="http://get.webgl.org">http://get.webgl.org</a> to verify that your web browser and hardware support WebGL. Consider trying a different web browser or updating your video drivers. Detailed error information is below:';
this.showErrorPanel(title, message, error);
}
throw error;
}
}
defineProperties(CesiumWidget.prototype, {
/**
* Gets the parent container.
* @memberof CesiumWidget.prototype
*
* @type {Element}
*/
container : {
get : function() {
return this._container;
}
},
/**
* Gets the canvas.
* @memberof CesiumWidget.prototype
*
* @type {Canvas}
*/
canvas : {
get : function() {
return this._canvas;
}
},
/**
* Gets the credit container.
* @memberof CesiumWidget.prototype
*
* @type {Element}
*/
creditContainer: {
get : function() {
return this._creditContainer;
}
},
/**
* Gets the scene.
* @memberof CesiumWidget.prototype
*
* @type {Scene}
*/
scene : {
get : function() {
return this._scene;
}
},
/**
* Gets the collection of image layers that will be rendered on the globe.
* @memberof CesiumWidget.prototype
*
* @type {ImageryLayerCollection}
* @readonly
*/
imageryLayers : {
get : function() {
return this._scene.imageryLayers;
}
},
/**
* The terrain provider providing surface geometry for the globe.
* @memberof CesiumWidget.prototype
*
* @type {TerrainProvider}
*/
terrainProvider : {
get : function() {
return this._scene.terrainProvider;
},
set : function(terrainProvider) {
this._scene.terrainProvider = terrainProvider;
}
},
/**
* Gets the camera.
* @memberof CesiumWidget.prototype
*
* @type {Camera}
* @readonly
*/
camera : {
get : function() {
return this._scene.camera;
}
},
/**
* Gets the clock.
* @memberof CesiumWidget.prototype
*
* @type {Clock}
*/
clock : {
get : function() {
return this._clock;
}
},
/**
* Gets the screen space event handler.
* @memberof CesiumWidget.prototype
*
* @type {ScreenSpaceEventHandler}
*/
screenSpaceEventHandler : {
get : function() {
return this._screenSpaceEventHandler;
}
},
/**
* Gets or sets the target frame rate of the widget when <code>useDefaultRenderLoop</code>
* is true. If undefined, the browser's {@link requestAnimationFrame} implementation
* determines the frame rate. If defined, this value must be greater than 0. A value higher
* than the underlying requestAnimationFrame implementation will have no effect.
* @memberof CesiumWidget.prototype
*
* @type {Number}
*/
targetFrameRate : {
get : function() {
return this._targetFrameRate;
},
set : function(value) {
if (value <= 0) {
throw new DeveloperError('targetFrameRate must be greater than 0, or undefined.');
}
this._targetFrameRate = value;
}
},
/**
* Gets or sets whether or not this widget should control the render loop.
* If set to true the widget will use {@link requestAnimationFrame} to
* perform rendering and resizing of the widget, as well as drive the
* simulation clock. If set to false, you must manually call the
* <code>resize</code>, <code>render</code> methods as part of a custom
* render loop. If an error occurs during rendering, {@link Scene}'s
* <code>renderError</code> event will be raised and this property
* will be set to false. It must be set back to true to continue rendering
* after the error.
* @memberof CesiumWidget.prototype
*
* @type {Boolean}
*/
useDefaultRenderLoop : {
get : function() {
return this._useDefaultRenderLoop;
},
set : function(value) {
if (this._useDefaultRenderLoop !== value) {
this._useDefaultRenderLoop = value;
if (value && !this._renderLoopRunning) {
startRenderLoop(this);
}
}
}
},
/**
* Gets or sets a scaling factor for rendering resolution. Values less than 1.0 can improve
* performance on less powerful devices while values greater than 1.0 will render at a higher
* resolution and then scale down, resulting in improved visual fidelity.
* For example, if the widget is laid out at a size of 640x480, setting this value to 0.5
* will cause the scene to be rendered at 320x240 and then scaled up while setting
* it to 2.0 will cause the scene to be rendered at 1280x960 and then scaled down.
* @memberof CesiumWidget.prototype
*
* @type {Number}
* @default 1.0
*/
resolutionScale : {
get : function() {
return this._resolutionScale;
},
set : function(value) {
if (value <= 0) {
throw new DeveloperError('resolutionScale must be greater than 0.');
}
this._resolutionScale = value;
this._forceResize = true;
}
}
});
/**
* Show an error panel to the user containing a title and a longer error message,
* which can be dismissed using an OK button. This panel is displayed automatically
* when a render loop error occurs, if showRenderLoopErrors was not false when the
* widget was constructed.
*
* @param {String} title The title to be displayed on the error panel. This string is interpreted as text.
* @param {String} message A helpful, user-facing message to display prior to the detailed error information. This string is interpreted as HTML.
* @param {String} [error] The error to be displayed on the error panel. This string is formatted using {@link formatError} and then displayed as text.
*/
CesiumWidget.prototype.showErrorPanel = function(title, message, error) {
var element = this._element;
var overlay = document.createElement('div');
overlay.className = 'cesium-widget-errorPanel';
var content = document.createElement('div');
content.className = 'cesium-widget-errorPanel-content';
overlay.appendChild(content);
var errorHeader = document.createElement('div');
errorHeader.className = 'cesium-widget-errorPanel-header';
errorHeader.appendChild(document.createTextNode(title));
content.appendChild(errorHeader);
var errorPanelScroller = document.createElement('div');
errorPanelScroller.className = 'cesium-widget-errorPanel-scroll';
content.appendChild(errorPanelScroller);
function resizeCallback() {
errorPanelScroller.style.maxHeight = Math.max(Math.round(element.clientHeight * 0.9 - 100), 30) + 'px';
}
resizeCallback();
if (defined(window.addEventListener)) {
window.addEventListener('resize', resizeCallback, false);
}
if (defined(message)) {
var errorMessage = document.createElement('div');
errorMessage.className = 'cesium-widget-errorPanel-message';
errorMessage.innerHTML = '<p>' + message + '</p>';
errorPanelScroller.appendChild(errorMessage);
}
var errorDetails = '(no error details available)';
if (defined(error)) {
errorDetails = formatError(error);
}
var errorMessageDetails = document.createElement('div');
errorMessageDetails.className = 'cesium-widget-errorPanel-message';
errorMessageDetails.appendChild(document.createTextNode(errorDetails));
errorPanelScroller.appendChild(errorMessageDetails);
var buttonPanel = document.createElement('div');
buttonPanel.className = 'cesium-widget-errorPanel-buttonPanel';
content.appendChild(buttonPanel);
var okButton = document.createElement('button');
okButton.setAttribute('type', 'button');
okButton.className = 'cesium-button';
okButton.appendChild(document.createTextNode('OK'));
okButton.onclick = function() {
if (defined(resizeCallback) && defined(window.removeEventListener)) {
window.removeEventListener('resize', resizeCallback, false);
}
element.removeChild(overlay);
};
buttonPanel.appendChild(okButton);
element.appendChild(overlay);
//IE8 does not have a console object unless the dev tools are open.
if (typeof console !== 'undefined') {
console.error(title + '\n' + message + '\n' + errorDetails);
}
};
/**
* @returns {Boolean} true if the object has been destroyed, false otherwise.
*/
CesiumWidget.prototype.isDestroyed = function() {
return false;
};
/**
* Destroys the widget. Should be called if permanently
* removing the widget from layout.
*/
CesiumWidget.prototype.destroy = function() {
this._scene = this._scene && this._scene.destroy();
this._container.removeChild(this._element);
destroyObject(this);
};
/**
* Updates the canvas size, camera aspect ratio, and viewport size.
* This function is called automatically as needed unless
* <code>useDefaultRenderLoop</code> is set to false.
*/
CesiumWidget.prototype.resize = function() {
var canvas = this._canvas;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (!this._forceResize && this._canvasWidth === width && this._canvasHeight === height) {
return;
}
this._forceResize = false;
configureCanvasSize(this);
configureCameraFrustum(this);
};
/**
* Renders the scene. This function is called automatically
* unless <code>useDefaultRenderLoop</code> is set to false;
*/
CesiumWidget.prototype.render = function() {
if (this._canRender) {
this._scene.initializeFrame();
var currentTime = this._clock.tick();
this._scene.render(currentTime);
} else {
this._clock.tick();
}
};
return CesiumWidget;
});