TerriaViewer.prototype.selectViewer = function(bCesium) { changeBaseMap(this, undefined); this.terria.beforeViewerChanged.raiseEvent(); var map, viewer, rect, eventHelper; var that = this; if (!bCesium) { //shut down existing cesium if (defined(this.terria.cesium)) { viewer = this.terria.cesium.viewer; //get camera and timeline settings try { rect = this.terria.cesium.getCurrentExtent(); } catch (e) { console.log('Using default screen extent', e.message); rect = this.terria.initialView.rectangle; } this.terria.cesium.destroy(); if (that.cesiumEventHelper) { that.cesiumEventHelper.removeAll(); that.cesiumEventHelper = undefined; } this.dataSourceDisplay.destroy(); this._enableSelectExtent(viewer.scene, false); var inputHandler = viewer.screenSpaceEventHandler; inputHandler.removeInputAction( ScreenSpaceEventType.MOUSE_MOVE ); inputHandler.removeInputAction( ScreenSpaceEventType.LEFT_DOUBLE_CLICK ); inputHandler.removeInputAction( ScreenSpaceEventType.LEFT_DOUBLE_CLICK, KeyboardEventModifier.SHIFT ); if (defined(this.monitor)) { this.monitor.destroy(); this.monitor = undefined; } viewer.destroy(); } else { rect = this.terria.initialView.rectangle; } //create leaflet viewer map = L.map(this._mapContainer, { worldCopyJump: true, zoomControl: false, attributionControl: false, maxZoom: this.maximumLeafletZoomLevel }).setView([-28.5, 135], 5); map.attributionControl = L.control.attribution({ position: 'bottomleft' }); map.addControl(map.attributionControl); map.screenSpaceEventHandler = { setInputAction : function() {}, remoteInputAction : function() {} }; map.destroy = function() {}; var leaflet = new Leaflet( this.terria, map); if (!defined(this.leafletVisualizer)) { this.leafletVisualizer = new LeafletVisualizer(); } var d = this._getDisclaimer(); if (d) { map.attributionControl.setPrefix('<span class="leaflet-disclaimer">' + (d.link ? '<a target="_blank" href="' + d.link + '">' : '') + d.text + (d.link ? '</a>' : '') + '</span>' + (this._developerAttribution && this._developerAttribution.link ? '<a target="_blank" href="' + this._developerAttribution.link + '">' : '') + (this._developerAttribution ? this._developerAttribution.text : '') + (this._developerAttribution && this._developerAttribution.link ? '</a>' : '') + (this._developerAttribution ? ' | ' : '') + '<a target="_blank" href="http://leafletjs.com/">Leaflet</a>' // partially to avoid a dangling leading comma issue ); } map.on("boxzoomend", function(e) { console.log(e.boxZoomBounds); }); this.terria.leaflet = leaflet; this.terria.cesium = undefined; this.terria.currentViewer = this.terria.leaflet; this.dataSourceDisplay = new DataSourceDisplay({ scene : leaflet.scene, dataSourceCollection : this.terria.dataSources, visualizersCallback: this.leafletVisualizer.visualizersCallback }); eventHelper = new EventHelper(); eventHelper.add(that.terria.clock.onTick, function(clock) { that.dataSourceDisplay.update(clock.currentTime); }); this.leafletEventHelper = eventHelper; var ticker = function() { if (defined(that.terria.leaflet)) { that.terria.clock.tick(); cesiumRequestAnimationFrame(ticker); } }; ticker(); this.terria.leaflet.zoomTo(rect, 0.0); } else { if (defined(this.terria.leaflet)) { map = this.terria.leaflet.map; rect = this.terria.leaflet.getCurrentExtent(); this.terria.leaflet.destroy(); if (that.leafletEventHelper) { that.leafletEventHelper.removeAll(); that.leafletEventHelper = undefined; } this.dataSourceDisplay.destroy(); map.remove(); } //create Cesium viewer viewer = this._createCesiumViewer(this._mapContainer); this._enableSelectExtent(viewer.scene, true); this.terria.cesium = new Cesium(this.terria, viewer); this.terria.leaflet = undefined; this.terria.currentViewer = this.terria.cesium; //Simple monitor to start up and switch to 2D if seem to be stuck. if (!defined(this.checkedStartupPerformance)) { this.checkedStartupPerformance = true; var uri = new URI(window.location); var params = uri.search(true); var frameRate = (defined(params.fps)) ? params.fps : 5; this.monitor = new FrameRateMonitor({ scene: viewer.scene, minimumFrameRateDuringWarmup: frameRate, minimumFrameRateAfterWarmup: 0, samplingWindow: 2 }); this.monitor.lowFrameRate.addEventListener( function() { if (! that.terria.cesium.stoppedRendering) { PopupMessageViewModel.open(that._uiContainer, { title : 'Unusually Slow Performance Detected', message : '\ It appears that your system is capable of running '+that.terria.appName+' in 3D mode, but is having significant performance issues. \ We are automatically switching to 2D mode to help resolve this issue. If you want to switch back to 3D mode you can select \ that option from the Maps button at the top of the screen.' }); runLater(function() { that.terria.viewerMode = ViewerMode.Leaflet; }); } }); } eventHelper = new EventHelper(); eventHelper.add(that.terria.clock.onTick, function(clock) { that.dataSourceDisplay.update(clock.currentTime); }); this.cesiumEventHelper = eventHelper; this.dataSourceDisplay = new DataSourceDisplay({ scene : viewer.scene, dataSourceCollection : this.terria.dataSources }); if (defined(rect)) { this.terria.cesium.zoomTo(rect, 0.0); } else { this.terria.cesium.zoomTo( this.terria.initialView, 0.0); } } //redisplay timeline if (this.terria.showTimeline !== 0) { this.terria.showTimeline++; } this.terria.afterViewerChanged.raiseEvent(); changeBaseMap(this, this.terria.baseMap); };
AusGlobeViewer.prototype.selectViewer = function(bCesium) { var previousClock; if (this.viewer) { previousClock = Clock.clone(this.viewer.clock); } else if (this.map) { previousClock = Clock.clone(this.map.clock); } changeBaseMap(this, undefined); this.terria.beforeViewerChanged.raiseEvent(); var rect; var that = this; var timelineVisible = isTimelineVisible(this.viewer || this.map); if (!bCesium) { //shut down existing cesium if (defined(this.viewer)) { //get camera and timeline settings try { rect = this.terria.cesium.getCurrentExtent(); } catch (e) { console.log('Using default screen extent', e.message); rect = this.terria.initialView.rectangle; } this.terria.cesium.destroy(); this._enableSelectExtent(false); var inputHandler = this.viewer.screenSpaceEventHandler; inputHandler.removeInputAction( ScreenSpaceEventType.MOUSE_MOVE ); inputHandler.removeInputAction( ScreenSpaceEventType.LEFT_DOUBLE_CLICK ); inputHandler.removeInputAction( ScreenSpaceEventType.LEFT_DOUBLE_CLICK, KeyboardEventModifier.SHIFT ); if (defined(this.monitor)) { this.monitor.destroy(); this.monitor = undefined; } this.viewer.destroy(); this.viewer = undefined; } else { rect = this.terria.initialView.rectangle; } //create leaflet viewer var map = L.map('cesiumContainer', { worldCopyJump: true, zoomControl: false }).setView([-28.5, 135], 5); this.map = map; map.clock = this.terria.clock; map.dataSources = this.terria.dataSources; map.screenSpaceEventHandler = { setInputAction : function() {}, remoteInputAction : function() {} }; map.destroy = function() {}; map.infoBox = new InfoBox(document.body); var leaflet = new Leaflet( this.terria, map); if (!defined(this.leafletVisualizer)) { this.leafletVisualizer = new LeafletVisualizer(); } this.dataSourceDisplay = new DataSourceDisplay({ scene : leaflet.scene, dataSourceCollection : map.dataSources, visualizersCallback: this.leafletVisualizer.visualizersCallback }); var eventHelper = new EventHelper(); eventHelper.add(map.clock.onTick, function(clock) { that.dataSourceDisplay.update(clock.currentTime); }); that.leafletEventHelper = eventHelper; var ticker = function() { if (that.map === map) { map.clock.tick(); cesiumRequestAnimationFrame(ticker); } else { console.log('done'); } }; ticker(); this.createLeafletTimeline(map.clock); Clock.clone(previousClock, map.clock); map.timeline.zoomTo(map.clock.startTime, map.clock.stopTime); map.on("boxzoomend", function(e) { console.log(e.boxZoomBounds); }); //redisplay data this.map = map; this.terria.leaflet = leaflet; this.terria.cesium = undefined; this.terria.currentViewer = this.terria.leaflet; this.terria.leaflet.zoomTo(rect, 0.0); } else { if (defined(this.map)) { rect = this.terria.leaflet.getCurrentExtent(); this.terria.leaflet.destroy(); if (that.leafletEventHelper) { that.leafletEventHelper.removeAll(); that.leafletEventHelper = undefined; } this.removeLeafletTimeline(); this.dataSourceDisplay.destroy(); this.map.dataSources = undefined; this.map.remove(); this.map = undefined; } //create Cesium viewer this.viewer = this._createCesiumViewer('cesiumContainer'); this.scene = this.viewer.scene; this.terria.cesium = new Cesium( this.terria, this.viewer); this.terria.leaflet = undefined; this.terria.currentViewer = this.terria.cesium; this._enableSelectExtent(true); Clock.clone(previousClock, this.viewer.clock); //Simple monitor to start up and switch to 2D if seem to be stuck. if (!defined(this.checkedStartupPerformance)) { this.checkedStartupPerformance = true; var uri = new URI(window.location); var params = uri.search(true); var frameRate = (defined(params.fps)) ? params.fps : 5; this.monitor = new FrameRateMonitor({ scene: this.scene, minimumFrameRateDuringWarmup: frameRate, minimumFrameRateAfterWarmup: 0, samplingWindow: 2 }); this.monitor.lowFrameRate.addEventListener( function() { if (! that.terria.cesium.stoppedRendering) { PopupMessageViewModel.open('ui', { title : 'Unusually Slow Performance Detected', message : '\ It appears that your system is capable of running National Map in 3D mode, but is having significant performance issues. \ We are automatically switching to 2D mode to help resolve this issue. If you want to switch back to 3D mode you can select \ that option from the Maps button at the top of the screen.' }); runLater(function() { that.selectViewer(false); }); } }); } if (defined(rect)) { this.terria.cesium.zoomTo(rect, 0.0); } else { this.terria.cesium.zoomTo( this.terria.initialView, 0.0); } } this.terria.afterViewerChanged.raiseEvent(); changeBaseMap(this, this.terria.baseMap); if (timelineVisible) { showTimeline(this.viewer || this.map); } else { hideTimeline(this.viewer || this.map); } };