WebWorldWind/examples/StarField.js
Patrick Hogan 6ebc542db8 Updated.
2017-11-20 14:06:30 -08:00

74 lines
2.4 KiB
JavaScript

/*
* Copyright 2015-2017 WorldWind Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
requirejs([
'./WorldWindShim',
'./LayerManager'
],
function (WorldWind,
LayerManager) {
'use strict';
WorldWind.Logger.setLoggingLevel(WorldWind.Logger.LEVEL_WARNING);
var wwd = new WorldWind.WorldWindow('canvasOne');
var BMNGLayer = new WorldWind.BMNGLayer();
var starFieldLayer = new WorldWind.StarFieldLayer();
var atmosphereLayer = new WorldWind.AtmosphereLayer();
wwd.addLayer(BMNGLayer);
//IMPORTANT: add the starFieldLayer before the atmosphereLayer
wwd.addLayer(starFieldLayer);
wwd.addLayer(atmosphereLayer);
var date = new Date();
starFieldLayer.time = date;
atmosphereLayer.time = date;
var layerManger = new LayerManager(wwd);
wwd.redraw();
wwd.redrawCallbacks.push(runSunSimulation);
var sunSimulationCheckBox = document.getElementById('stars-simulation');
var doRunSimulation = false;
var timeStamp = Date.now();
var factor = 1;
sunSimulationCheckBox.addEventListener('change', onSunCheckBoxClick, false);
function onSunCheckBoxClick() {
doRunSimulation = this.checked;
if (!doRunSimulation) {
var date = new Date();
starFieldLayer.time = date;
atmosphereLayer.time = date;
}
wwd.redraw();
}
function runSunSimulation(wwd, stage) {
if (stage === WorldWind.AFTER_REDRAW && doRunSimulation) {
timeStamp += (factor * 60 * 1000);
var date = new Date(timeStamp);
starFieldLayer.time = date;
atmosphereLayer.time = date;
wwd.redraw();
}
}
});