12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391 |
- define([
- '../../Core/Cartesian3',
- '../../Core/defaultValue',
- '../../Core/defined',
- '../../Core/defineProperties',
- '../../Core/destroyObject',
- '../../Core/DeveloperError',
- '../../Core/EventHelper',
- '../../Core/ScreenSpaceEventType',
- '../../DataSources/ConstantPositionProperty',
- '../../DataSources/DataSourceCollection',
- '../../DataSources/DataSourceDisplay',
- '../../DataSources/Entity',
- '../../DataSources/EntityView',
- '../../Scene/SceneMode',
- '../../ThirdParty/knockout',
- '../../ThirdParty/when',
- '../Animation/Animation',
- '../Animation/AnimationViewModel',
- '../BaseLayerPicker/BaseLayerPicker',
- '../BaseLayerPicker/createDefaultImageryProviderViewModels',
- '../BaseLayerPicker/createDefaultTerrainProviderViewModels',
- '../CesiumWidget/CesiumWidget',
- '../ClockViewModel',
- '../FullscreenButton/FullscreenButton',
- '../Geocoder/Geocoder',
- '../getElement',
- '../HomeButton/HomeButton',
- '../InfoBox/InfoBox',
- '../NavigationHelpButton/NavigationHelpButton',
- '../SceneModePicker/SceneModePicker',
- '../SelectionIndicator/SelectionIndicator',
- '../subscribeAndEvaluate',
- '../Timeline/Timeline'
- ], function(
- Cartesian3,
- defaultValue,
- defined,
- defineProperties,
- destroyObject,
- DeveloperError,
- EventHelper,
- ScreenSpaceEventType,
- ConstantPositionProperty,
- DataSourceCollection,
- DataSourceDisplay,
- Entity,
- EntityView,
- SceneMode,
- knockout,
- when,
- Animation,
- AnimationViewModel,
- BaseLayerPicker,
- createDefaultImageryProviderViewModels,
- createDefaultTerrainProviderViewModels,
- CesiumWidget,
- ClockViewModel,
- FullscreenButton,
- Geocoder,
- getElement,
- HomeButton,
- InfoBox,
- NavigationHelpButton,
- SceneModePicker,
- SelectionIndicator,
- subscribeAndEvaluate,
- Timeline) {
- "use strict";
- function onTimelineScrubfunction(e) {
- var clock = e.clock;
- clock.currentTime = e.timeJulian;
- clock.shouldAnimate = false;
- }
- function pickEntity(viewer, e) {
- var picked = viewer.scene.pick(e.position);
- if (defined(picked)) {
- var id = defaultValue(picked.id, picked.primitive.id);
- if (id instanceof Entity) {
- return id;
- }
- }
-
- return pickImageryLayerFeature(viewer, e.position);
- }
- function trackDataSourceClock(timeline, clock, dataSource) {
- if (defined(dataSource)) {
- var dataSourceClock = dataSource.clock;
- if (defined(dataSourceClock)) {
- dataSourceClock.getValue(clock);
- if (defined(timeline)) {
- timeline.updateFromClock();
- timeline.zoomTo(dataSourceClock.startTime, dataSourceClock.stopTime);
- }
- }
- }
- }
- var cartesian3Scratch = new Cartesian3();
- function pickImageryLayerFeature(viewer, windowPosition) {
- var scene = viewer.scene;
- var pickRay = scene.camera.getPickRay(windowPosition);
- var imageryLayerFeaturePromise = scene.imageryLayers.pickImageryLayerFeatures(pickRay, scene);
- if (!defined(imageryLayerFeaturePromise)) {
- return;
- }
-
- var loadingMessage = new Entity('Loading...');
- loadingMessage.description = {
- getValue : function() {
- return 'Loading feature information...';
- }
- };
- when(imageryLayerFeaturePromise, function(features) {
-
- if (viewer.selectedEntity !== loadingMessage) {
- return;
- }
- if (!defined(features) || features.length === 0) {
- viewer.selectedEntity = createNoFeaturesEntity();
- return;
- }
-
- var feature = features[0];
- var entity = new Entity(feature.name);
- entity.description = {
- getValue : function() {
- return feature.description;
- }
- };
- if (defined(feature.position)) {
- var ecfPosition = viewer.scene.globe.ellipsoid.cartographicToCartesian(feature.position, cartesian3Scratch);
- entity.position = new ConstantPositionProperty(ecfPosition);
- }
- viewer.selectedEntity = entity;
- }, function() {
-
- if (viewer.selectedEntity !== loadingMessage) {
- return;
- }
- var entity = new Entity('None');
- entity.description = {
- getValue : function() {
- return 'No features found.';
- }
- };
- viewer.selectedEntity = createNoFeaturesEntity();
- });
- return loadingMessage;
- }
- function createNoFeaturesEntity() {
- var entity = new Entity('None');
- entity.description = {
- getValue : function() {
- return 'No features found.';
- }
- };
- return entity;
- }
-
- var Viewer = function(container, options) {
-
- if (!defined(container)) {
- throw new DeveloperError('container is required.');
- }
-
- container = getElement(container);
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
- var createBaseLayerPicker = !defined(options.baseLayerPicker) || options.baseLayerPicker !== false;
-
-
- if (createBaseLayerPicker && defined(options.imageryProvider)) {
- throw new DeveloperError('options.imageryProvider is not available when using the BaseLayerPicker widget. \
- Either specify options.selectedImageryProviderViewModel instead or set options.baseLayerPicker to false.');
- }
-
- if (!createBaseLayerPicker && defined(options.selectedImageryProviderViewModel)) {
- throw new DeveloperError('options.selectedImageryProviderViewModel is not available when not using the BaseLayerPicker widget. \
- Either specify options.imageryProvider instead or set options.baseLayerPicker to true.');
- }
-
- if (createBaseLayerPicker && defined(options.terrainProvider)) {
- throw new DeveloperError('options.terrainProvider is not available when using the BaseLayerPicker widget. \
- Either specify options.selectedTerrainProviderViewModel instead or set options.baseLayerPicker to false.');
- }
-
- if (!createBaseLayerPicker && defined(options.selectedTerrainProviderViewModel)) {
- throw new DeveloperError('options.selectedTerrainProviderViewModel is not available when not using the BaseLayerPicker widget. \
- Either specify options.terrainProvider instead or set options.baseLayerPicker to true.');
- }
-
- var viewerContainer = document.createElement('div');
- viewerContainer.className = 'cesium-viewer';
- container.appendChild(viewerContainer);
-
- var cesiumWidgetContainer = document.createElement('div');
- cesiumWidgetContainer.className = 'cesium-viewer-cesiumWidgetContainer';
- viewerContainer.appendChild(cesiumWidgetContainer);
-
- var bottomContainer = document.createElement('div');
- bottomContainer.className = 'cesium-viewer-bottom';
- viewerContainer.appendChild(bottomContainer);
- var scene3DOnly = defaultValue(options.scene3DOnly, false);
-
- var cesiumWidget = new CesiumWidget(cesiumWidgetContainer, {
- terrainProvider : options.terrainProvider,
- imageryProvider : createBaseLayerPicker ? false : options.imageryProvider,
- clock : options.clock,
- skyBox : options.skyBox,
- sceneMode : options.sceneMode,
- mapProjection : options.mapProjection,
- orderIndependentTranslucency : options.orderIndependentTranslucency,
- contextOptions : options.contextOptions,
- useDefaultRenderLoop : options.useDefaultRenderLoop,
- targetFrameRate : options.targetFrameRate,
- showRenderLoopErrors : options.showRenderLoopErrors,
- creditContainer : defined(options.creditContainer) ? options.creditContainer : bottomContainer,
- scene3DOnly : scene3DOnly
- });
- var dataSourceCollection = options.dataSources;
- var destroyDataSourceCollection = false;
- if (!defined(dataSourceCollection)) {
- dataSourceCollection = new DataSourceCollection();
- destroyDataSourceCollection = true;
- }
- var dataSourceDisplay = new DataSourceDisplay({
- scene : cesiumWidget.scene,
- dataSourceCollection : dataSourceCollection
- });
- var clock = cesiumWidget.clock;
- var clockViewModel = new ClockViewModel(clock);
- var eventHelper = new EventHelper();
- eventHelper.add(clock.onTick, Viewer.prototype._onTick, this);
-
- var selectionIndicator;
- if (!defined(options.selectionIndicator) || options.selectionIndicator !== false) {
- var selectionIndicatorContainer = document.createElement('div');
- selectionIndicatorContainer.className = 'cesium-viewer-selectionIndicatorContainer';
- viewerContainer.appendChild(selectionIndicatorContainer);
- selectionIndicator = new SelectionIndicator(selectionIndicatorContainer, cesiumWidget.scene);
- }
-
- var infoBox;
- if (!defined(options.infoBox) || options.infoBox !== false) {
- var infoBoxContainer = document.createElement('div');
- infoBoxContainer.className = 'cesium-viewer-infoBoxContainer';
- viewerContainer.appendChild(infoBoxContainer);
- infoBox = new InfoBox(infoBoxContainer);
- var infoBoxViewModel = infoBox.viewModel;
- eventHelper.add(infoBoxViewModel.cameraClicked, Viewer.prototype._trackSelectedEntity, this);
- eventHelper.add(infoBoxViewModel.closeClicked, Viewer.prototype._clearSelectedEntity, this);
- }
-
- var toolbar = document.createElement('div');
- toolbar.className = 'cesium-viewer-toolbar';
- viewerContainer.appendChild(toolbar);
-
- var geocoder;
- if (!defined(options.geocoder) || options.geocoder !== false) {
- var geocoderContainer = document.createElement('div');
- geocoderContainer.className = 'cesium-viewer-geocoderContainer';
- toolbar.appendChild(geocoderContainer);
- geocoder = new Geocoder({
- container : geocoderContainer,
- scene : cesiumWidget.scene
- });
-
- eventHelper.add(geocoder.viewModel.search.beforeExecute, Viewer.prototype._clearObjects, this);
- }
-
- var homeButton;
- if (!defined(options.homeButton) || options.homeButton !== false) {
- homeButton = new HomeButton(toolbar, cesiumWidget.scene);
- if (defined(geocoder)) {
- eventHelper.add(homeButton.viewModel.command.afterExecute, function() {
- var viewModel = geocoder.viewModel;
- viewModel.searchText = '';
- if (viewModel.isSearchInProgress) {
- viewModel.search();
- }
- });
- }
-
- eventHelper.add(homeButton.viewModel.command.beforeExecute, Viewer.prototype._clearTrackedObject, this);
- }
-
-
-
- if ((options.sceneModePicker === true) && scene3DOnly) {
- throw new DeveloperError('options.sceneModePicker is not available when options.scene3DOnly is set to true.');
- }
- var sceneModePicker;
- if (!scene3DOnly && (!defined(options.sceneModePicker) || options.sceneModePicker !== false)) {
- sceneModePicker = new SceneModePicker(toolbar, cesiumWidget.scene);
- }
-
- var baseLayerPicker;
- var baseLayerPickerDropDown;
- if (createBaseLayerPicker) {
- var imageryProviderViewModels = defaultValue(options.imageryProviderViewModels, createDefaultImageryProviderViewModels());
- var terrainProviderViewModels = defaultValue(options.terrainProviderViewModels, createDefaultTerrainProviderViewModels());
- baseLayerPicker = new BaseLayerPicker(toolbar, {
- globe : cesiumWidget.scene.globe,
- imageryProviderViewModels : imageryProviderViewModels,
- selectedImageryProviderViewModel : options.selectedImageryProviderViewModel,
- terrainProviderViewModels : terrainProviderViewModels,
- selectedTerrainProviderViewModel : options.selectedTerrainProviderViewModel
- });
-
- var elements = toolbar.getElementsByClassName('cesium-baseLayerPicker-dropDown');
- baseLayerPickerDropDown = elements[0];
- }
-
- var navigationHelpButton;
- if (!defined(options.navigationHelpButton) || options.navigationHelpButton !== false) {
- var showNavHelp = true;
- if (defined(window.localStorage)) {
- var hasSeenNavHelp = window.localStorage.getItem('cesium-hasSeenNavHelp');
- if (defined(hasSeenNavHelp) && Boolean(hasSeenNavHelp)) {
- showNavHelp = false;
- } else {
- window.localStorage.setItem('cesium-hasSeenNavHelp', 'true');
- }
- }
- navigationHelpButton = new NavigationHelpButton({
- container : toolbar,
- instructionsInitiallyVisible : defaultValue(options.navigationInstructionsInitiallyVisible, showNavHelp)
- });
- }
-
- var animation;
- if (!defined(options.animation) || options.animation !== false) {
- var animationContainer = document.createElement('div');
- animationContainer.className = 'cesium-viewer-animationContainer';
- viewerContainer.appendChild(animationContainer);
- animation = new Animation(animationContainer, new AnimationViewModel(clockViewModel));
- }
-
- var timeline;
- if (!defined(options.timeline) || options.timeline !== false) {
- var timelineContainer = document.createElement('div');
- timelineContainer.className = 'cesium-viewer-timelineContainer';
- viewerContainer.appendChild(timelineContainer);
- timeline = new Timeline(timelineContainer, clock);
- timeline.addEventListener('settime', onTimelineScrubfunction, false);
- timeline.zoomTo(clock.startTime, clock.stopTime);
- }
-
- var fullscreenButton;
- var fullscreenSubscription;
- if (!defined(options.fullscreenButton) || options.fullscreenButton !== false) {
- var fullscreenContainer = document.createElement('div');
- fullscreenContainer.className = 'cesium-viewer-fullscreenContainer';
- viewerContainer.appendChild(fullscreenContainer);
- fullscreenButton = new FullscreenButton(fullscreenContainer, options.fullscreenElement);
-
-
- fullscreenSubscription = subscribeAndEvaluate(fullscreenButton.viewModel, 'isFullscreenEnabled', function(isFullscreenEnabled) {
- fullscreenContainer.style.display = isFullscreenEnabled ? 'block' : 'none';
- if (defined(timeline)) {
- timeline.container.style.right = fullscreenContainer.clientWidth + 'px';
- timeline.resize();
- }
- });
- } else if (defined(timeline)) {
- timeline.container.style.right = 0;
- }
-
-
- this._baseLayerPickerDropDown = baseLayerPickerDropDown;
- this._fullscreenSubscription = fullscreenSubscription;
- this._dataSourceChangedListeners = {};
- this._automaticallyTrackDataSourceClocks = defaultValue(options.automaticallyTrackDataSourceClocks, true);
- this._container = container;
- this._bottomContainer = bottomContainer;
- this._element = viewerContainer;
- this._cesiumWidget = cesiumWidget;
- this._selectionIndicator = selectionIndicator;
- this._infoBox = infoBox;
- this._dataSourceCollection = dataSourceCollection;
- this._destroyDataSourceCollection = destroyDataSourceCollection;
- this._dataSourceDisplay = dataSourceDisplay;
- this._clockViewModel = clockViewModel;
- this._toolbar = toolbar;
- this._homeButton = homeButton;
- this._sceneModePicker = sceneModePicker;
- this._baseLayerPicker = baseLayerPicker;
- this._animation = animation;
- this._timeline = timeline;
- this._fullscreenButton = fullscreenButton;
- this._geocoder = geocoder;
- this._eventHelper = eventHelper;
- this._lastWidth = 0;
- this._lastHeight = 0;
- this._allowDataSourcesToSuspendAnimation = true;
- this._entityView = undefined;
- this._enableInfoOrSelection = defined(infoBox) || defined(selectionIndicator);
- this._clockTrackedDataSource = undefined;
- this._trackedEntity = undefined;
- this._selectedEntity = undefined;
- this._clockTrackedDataSource = undefined;
- this._forceResize = false;
- knockout.track(this, ['_trackedEntity', '_selectedEntity', '_clockTrackedDataSource']);
-
- eventHelper.add(dataSourceCollection.dataSourceAdded, Viewer.prototype._onDataSourceAdded, this);
- eventHelper.add(dataSourceCollection.dataSourceRemoved, Viewer.prototype._onDataSourceRemoved, this);
-
- eventHelper.add(cesiumWidget.scene.preRender, Viewer.prototype.resize, this);
-
-
-
- var dataSourceLength = dataSourceCollection.length;
- for (var i = 0; i < dataSourceLength; i++) {
- this._dataSourceAdded(dataSourceCollection, dataSourceCollection.get(i));
- }
-
- eventHelper.add(dataSourceCollection.dataSourceAdded, Viewer.prototype._dataSourceAdded, this);
- eventHelper.add(dataSourceCollection.dataSourceRemoved, Viewer.prototype._dataSourceRemoved, this);
- var that = this;
-
- function pickAndTrackObject(e) {
- var entity = pickEntity(that, e);
- if (defined(entity) && defined(entity.position)) {
- that.trackedEntity = entity;
- }
- }
- function pickAndSelectObject(e) {
- that.selectedEntity = pickEntity(that, e);
- }
- cesiumWidget.screenSpaceEventHandler.setInputAction(pickAndSelectObject, ScreenSpaceEventType.LEFT_CLICK);
- cesiumWidget.screenSpaceEventHandler.setInputAction(pickAndTrackObject, ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
- };
- defineProperties(Viewer.prototype, {
-
- container : {
- get : function() {
- return this._container;
- }
- },
-
- bottomContainer : {
- get : function() {
- return this._bottomContainer;
- }
- },
-
- cesiumWidget : {
- get : function() {
- return this._cesiumWidget;
- }
- },
-
- selectionIndicator : {
- get : function() {
- return this._selectionIndicator;
- }
- },
-
- infoBox : {
- get : function() {
- return this._infoBox;
- }
- },
-
- geocoder : {
- get : function() {
- return this._geocoder;
- }
- },
-
- homeButton : {
- get : function() {
- return this._homeButton;
- }
- },
-
- sceneModePicker : {
- get : function() {
- return this._sceneModePicker;
- }
- },
-
- baseLayerPicker : {
- get : function() {
- return this._baseLayerPicker;
- }
- },
-
- animation : {
- get : function() {
- return this._animation;
- }
- },
-
- timeline : {
- get : function() {
- return this._timeline;
- }
- },
-
- fullscreenButton : {
- get : function() {
- return this._fullscreenButton;
- }
- },
-
- dataSourceDisplay : {
- get : function() {
- return this._dataSourceDisplay;
- }
- },
-
- dataSources : {
- get : function() {
- return this._dataSourceCollection;
- }
- },
-
- canvas : {
- get : function() {
- return this._cesiumWidget.canvas;
- }
- },
-
- cesiumLogo : {
- get : function() {
- return this._cesiumWidget.cesiumLogo;
- }
- },
-
- scene : {
- get : function() {
- return this._cesiumWidget.scene;
- }
- },
-
- imageryLayers : {
- get : function() {
- return this.scene.imageryLayers;
- }
- },
-
- terrainProvider : {
- get : function() {
- return this.scene.terrainProvider;
- },
- set : function(terrainProvider) {
- this.scene.terrainProvider = terrainProvider;
- }
- },
-
- camera : {
- get : function() {
- return this.scene.camera;
- }
- },
-
- clock : {
- get : function() {
- return this._cesiumWidget.clock;
- }
- },
-
- screenSpaceEventHandler : {
- get : function() {
- return this._cesiumWidget.screenSpaceEventHandler;
- }
- },
-
- targetFrameRate : {
- get : function() {
- return this._cesiumWidget.targetFrameRate;
- },
- set : function(value) {
- this._cesiumWidget.targetFrameRate = value;
- }
- },
-
- useDefaultRenderLoop : {
- get : function() {
- return this._cesiumWidget.useDefaultRenderLoop;
- },
- set : function(value) {
- this._cesiumWidget.useDefaultRenderLoop = value;
- }
- },
-
- resolutionScale : {
- get : function() {
- return this._cesiumWidget.resolutionScale;
- },
- set : function(value) {
- this._cesiumWidget.resolutionScale = value;
- this._forceResize = true;
- }
- },
-
- allowDataSourcesToSuspendAnimation : {
- get : function() {
- return this._allowDataSourcesToSuspendAnimation;
- },
- set : function(value) {
- this._allowDataSourcesToSuspendAnimation = value;
- }
- },
-
- trackedEntity : {
- get : function() {
- return this._trackedEntity;
- },
- set : function(value) {
- if (this._trackedEntity !== value) {
- this._trackedEntity = value;
- var scene = this.scene;
- var sceneMode = scene.mode;
- var isTracking = defined(value);
- if (sceneMode === SceneMode.COLUMBUS_VIEW || sceneMode === SceneMode.SCENE2D) {
- scene.screenSpaceCameraController.enableTranslate = !isTracking;
- }
- if (sceneMode === SceneMode.COLUMBUS_VIEW || sceneMode === SceneMode.SCENE3D) {
- scene.screenSpaceCameraController.enableTilt = !isTracking;
- }
- if (isTracking && defined(value.position)) {
- this._entityView = new EntityView(value, scene, this.scene.globe.ellipsoid);
- } else {
- this._entityView = undefined;
- }
- }
- }
- },
-
- selectedEntity : {
- get : function() {
- return this._selectedEntity;
- },
- set : function(value) {
- if (this._selectedEntity !== value) {
- this._selectedEntity = value;
- var selectionIndicatorViewModel = defined(this._selectionIndicator) ? this._selectionIndicator.viewModel : undefined;
- if (defined(value)) {
- var infoBoxViewModel = defined(this._infoBox) ? this._infoBox.viewModel : undefined;
- if (defined(infoBoxViewModel)) {
- infoBoxViewModel.titleText = defined(value.name) ? value.name : value.id;
- }
- if (defined(selectionIndicatorViewModel)) {
- selectionIndicatorViewModel.animateAppear();
- }
- } else {
-
- if (defined(selectionIndicatorViewModel)) {
- selectionIndicatorViewModel.animateDepart();
- }
- }
- }
- }
- },
-
- clockTrackedDataSource : {
- get : function() {
- return this._clockTrackedDataSource;
- },
- set : function(value) {
- if (this._clockTrackedDataSource !== value) {
- this._clockTrackedDataSource = value;
- trackDataSourceClock(this._timeline, this.clock, value);
- }
- }
- }
- });
-
- Viewer.prototype.extend = function(mixin, options) {
-
- if (!defined(mixin)) {
- throw new DeveloperError('mixin is required.');
- }
-
- mixin(this, options);
- };
-
- Viewer.prototype.resize = function() {
- var cesiumWidget = this._cesiumWidget;
- var container = this._container;
- var width = container.clientWidth;
- var height = container.clientHeight;
- var animationExists = defined(this._animation);
- var timelineExists = defined(this._timeline);
- if (!this._forceResize && width === this._lastWidth && height === this._lastHeight) {
- return;
- }
- cesiumWidget.resize();
- this._forceResize = false;
- var panelMaxHeight = height - 125;
- var baseLayerPickerDropDown = this._baseLayerPickerDropDown;
- if (defined(baseLayerPickerDropDown)) {
- baseLayerPickerDropDown.style.maxHeight = panelMaxHeight + 'px';
- }
- if (defined(this._infoBox)) {
- this._infoBox.viewModel.maxHeight = panelMaxHeight;
- }
- var timeline = this._timeline;
- var animationContainer;
- var animationWidth = 0;
- var creditLeft = 0;
- var creditBottom = 0;
- if (animationExists && window.getComputedStyle(this._animation.container).visibility !== 'hidden') {
- var lastWidth = this._lastWidth;
- animationContainer = this._animation.container;
- if (width > 900) {
- animationWidth = 169;
- if (lastWidth <= 900) {
- animationContainer.style.width = '169px';
- animationContainer.style.height = '112px';
- this._animation.resize();
- }
- } else if (width >= 600) {
- animationWidth = 136;
- if (lastWidth < 600 || lastWidth > 900) {
- animationContainer.style.width = '136px';
- animationContainer.style.height = '90px';
- this._animation.resize();
- }
- } else {
- animationWidth = 106;
- if (lastWidth > 600 || lastWidth === 0) {
- animationContainer.style.width = '106px';
- animationContainer.style.height = '70px';
- this._animation.resize();
- }
- }
- creditLeft = animationWidth + 5;
- }
- if (timelineExists && window.getComputedStyle(this._timeline.container).visibility !== 'hidden') {
- var fullscreenButton = this._fullscreenButton;
- var timelineContainer = timeline.container;
- var timelineStyle = timelineContainer.style;
- creditBottom = timelineContainer.clientHeight + 3;
- timelineStyle.left = animationWidth + 'px';
- if (defined(fullscreenButton)) {
- timelineStyle.right = fullscreenButton.container.clientWidth + 'px';
- }
- timeline.resize();
- }
- this._bottomContainer.style.left = creditLeft + 'px';
- this._bottomContainer.style.bottom = creditBottom + 'px';
- this._lastWidth = width;
- this._lastHeight = height;
- };
-
- Viewer.prototype.forceResize = function() {
- this._lastWidth = 0;
- this.resize();
- };
-
- Viewer.prototype.render = function() {
- this._cesiumWidget.render();
- };
-
- Viewer.prototype.isDestroyed = function() {
- return false;
- };
-
- Viewer.prototype.destroy = function() {
- var i;
- this.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_CLICK);
- this.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
-
- var dataSources = this.dataSources;
- var dataSourceLength = dataSources.length;
- for (i = 0; i < dataSourceLength; i++) {
- this._dataSourceRemoved(dataSources, dataSources.get(i));
- }
- this._container.removeChild(this._element);
- this._element.removeChild(this._toolbar);
- this._eventHelper.removeAll();
- if (defined(this._geocoder)) {
- this._geocoder = this._geocoder.destroy();
- }
- if (defined(this._homeButton)) {
- this._homeButton = this._homeButton.destroy();
- }
- if (defined(this._sceneModePicker)) {
- this._sceneModePicker = this._sceneModePicker.destroy();
- }
- if (defined(this._baseLayerPicker)) {
- this._baseLayerPicker = this._baseLayerPicker.destroy();
- }
- if (defined(this._animation)) {
- this._element.removeChild(this._animation.container);
- this._animation = this._animation.destroy();
- }
- if (defined(this._timeline)) {
- this._timeline.removeEventListener('settime', onTimelineScrubfunction, false);
- this._element.removeChild(this._timeline.container);
- this._timeline = this._timeline.destroy();
- }
- if (defined(this._fullscreenButton)) {
- this._fullscreenSubscription.dispose();
- this._element.removeChild(this._fullscreenButton.container);
- this._fullscreenButton = this._fullscreenButton.destroy();
- }
- if (defined(this._infoBox)) {
- this._element.removeChild(this._infoBox.container);
- this._infoBox = this._infoBox.destroy();
- }
- if (defined(this._selectionIndicator)) {
- this._element.removeChild(this._selectionIndicator.container);
- this._selectionIndicator = this._selectionIndicator.destroy();
- }
- this._clockViewModel = this._clockViewModel.destroy();
- this._dataSourceDisplay = this._dataSourceDisplay.destroy();
- this._cesiumWidget = this._cesiumWidget.destroy();
- if (this._destroyDataSourceCollection) {
- this._dataSourceCollection = this._dataSourceCollection.destroy();
- }
- return destroyObject(this);
- };
-
- Viewer.prototype._dataSourceAdded = function(dataSourceCollection, dataSource) {
- var entityCollection = dataSource.entities;
- entityCollection.collectionChanged.addEventListener(Viewer.prototype._onEntityCollectionChanged, this);
- };
-
- Viewer.prototype._dataSourceRemoved = function(dataSourceCollection, dataSource) {
- var entityCollection = dataSource.entities;
- entityCollection.collectionChanged.removeEventListener(Viewer.prototype._onEntityCollectionChanged, this);
- if (defined(this.trackedEntity)) {
- if (entityCollection.getById(this.trackedEntity.id) === this.trackedEntity) {
- this.homeButton.viewModel.command();
- }
- }
- if (defined(this.selectedEntity)) {
- if (entityCollection.getById(this.selectedEntity.id) === this.selectedEntity) {
- this.selectedEntity = undefined;
- }
- }
- };
-
- Viewer.prototype._onTick = function(clock) {
- var time = clock.currentTime;
- var entityView = this._entityView;
- var infoBoxViewModel = defined(this._infoBox) ? this._infoBox.viewModel : undefined;
- var selectionIndicatorViewModel = this._selectionIndicator.viewModel;
- var isUpdated = this._dataSourceDisplay.update(time);
- if (this._allowDataSourcesToSuspendAnimation) {
- this._clockViewModel.canAnimate = isUpdated;
- }
- if (defined(entityView)) {
- entityView.update(time);
- }
- var selectedEntity = this.selectedEntity;
- var showSelection = defined(selectedEntity) && this._enableInfoOrSelection;
- if (showSelection) {
- var oldPosition = defined(selectionIndicatorViewModel) ? selectionIndicatorViewModel.position : undefined;
- var position;
- var enableCamera = false;
- if (selectedEntity.isAvailable(time)) {
- if (defined(selectedEntity.position)) {
- position = selectedEntity.position.getValue(time, oldPosition);
- enableCamera = defined(position) && (this.trackedEntity !== this.selectedEntity);
- }
-
- }
-
- if (defined(selectionIndicatorViewModel)) {
- selectionIndicatorViewModel.position = position;
- }
- if (defined(infoBoxViewModel)) {
- infoBoxViewModel.enableCamera = enableCamera;
- infoBoxViewModel.isCameraTracking = (this.trackedEntity === this.selectedEntity);
- if (defined(selectedEntity.description)) {
- infoBoxViewModel.descriptionRawHtml = defaultValue(selectedEntity.description.getValue(time), '');
- } else {
- infoBoxViewModel.descriptionRawHtml = '';
- }
- }
- }
- if (defined(selectionIndicatorViewModel)) {
- selectionIndicatorViewModel.showSelection = showSelection;
- selectionIndicatorViewModel.update();
- }
- if (defined(infoBoxViewModel)) {
- infoBoxViewModel.showInfo = showSelection;
- }
- };
-
- Viewer.prototype._onEntityCollectionChanged = function(collection, added, removed) {
- var length = removed.length;
- for (var i = 0; i < length; i++) {
- var removedObject = removed[i];
- if (this.trackedEntity === removedObject) {
- this.homeButton.viewModel.command();
- }
- if (this.selectedEntity === removedObject) {
- this.selectedEntity = undefined;
- }
- }
- };
-
- Viewer.prototype._trackSelectedEntity = function() {
- this.trackedEntity = this.selectedEntity;
- };
-
- Viewer.prototype._clearTrackedObject = function() {
- this.trackedEntity = undefined;
- };
-
- Viewer.prototype._clearSelectedEntity = function() {
- this.selectedEntity = undefined;
- };
-
- Viewer.prototype._clearObjects = function() {
- this.trackedEntity = undefined;
- this.selectedEntity = undefined;
- };
-
- Viewer.prototype._onDataSourceChanged = function(dataSource) {
- if (this.clockTrackedDataSource === dataSource) {
- trackDataSourceClock(this.timeline, this.clock, dataSource);
- }
- };
-
- Viewer.prototype._onDataSourceAdded = function(dataSourceCollection, dataSource) {
- if (this._automaticallyTrackDataSourceClocks) {
- this.clockTrackedDataSource = dataSource;
- }
- var id = dataSource.entities.id;
- var removalFunc = this._eventHelper.add(dataSource.changedEvent, Viewer.prototype._onDataSourceChanged, this);
- this._dataSourceChangedListeners[id] = removalFunc;
- };
-
- Viewer.prototype._onDataSourceRemoved = function(dataSourceCollection, dataSource) {
- var resetClock = (this.clockTrackedDataSource === dataSource);
- var id = dataSource.entities.id;
- this._dataSourceChangedListeners[id]();
- this._dataSourceChangedListeners[id] = undefined;
- if (resetClock) {
- var numDataSources = dataSourceCollection.length;
- if (this._automaticallyTrackDataSourceClocks && numDataSources > 0) {
- this.clockTrackedDataSource = dataSourceCollection.get(numDataSources - 1);
- } else {
- this.clockTrackedDataSource = undefined;
- }
- }
- };
-
- return Viewer;
- });
|