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

75 lines
2.7 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";
var parseArgs = function () {
var result = {};
var queryString = window.location.href.split("?");
if (queryString && queryString.length > 1) {
var args = queryString[1].split("&");
for (var a = 0; a < args.length; a++) {
var arg = args[a].split("=");
if (arg[0] === "pos") {
// arg format is "pos=lat,lon,alt"
var position = arg[1].split(","),
lat = parseFloat(position[0]),
lon = parseFloat(position[1]),
alt = parseFloat(position[2]);
result.position = new WorldWind.Position(lat, lon, alt);
}
}
}
return result;
};
var args = parseArgs();
WorldWind.Logger.setLoggingLevel(WorldWind.Logger.LEVEL_WARNING);
var wwd = new WorldWind.WorldWindow("canvasOne");
var layers = [
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BMNGLandsatLayer(), enabled: false},
{layer: new WorldWind.BingAerialLayer(null), enabled: false},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
{layer: new WorldWind.BingRoadsLayer(null), enabled: false},
{layer: new WorldWind.CompassLayer(), enabled: true},
{layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true},
{layer: new WorldWind.ViewControlsLayer(wwd), enabled: true}
];
for (var l = 0; l < layers.length; l++) {
layers[l].layer.enabled = layers[l].enabled;
wwd.addLayer(layers[l].layer);
}
// Create a layer manager for controlling layer visibility.
var layerManger = new LayerManager(wwd);
// Now move the view to the requested position.
if (args.position) {
wwd.goTo(args.position);
}
});