WebWorldWind/apps/util/ProjectionMenu.js
Patrick Hogan 09c81f862e Update
2018-06-21 19:03:59 -07:00

110 lines
4.2 KiB
JavaScript

/*
* Copyright 2003-2006, 2009, 2017, United States Government, as represented by the Administrator of the
* National Aeronautics and Space Administration. All rights reserved.
*
* The NASAWorldWind/WebWorldWind platform is 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.
*/
/**
* @exports ProjectionMenu
*/
define(function () {
"use strict";
/**
* Constructs a projection menu for a specified {@link WorldWindow}.
* @alias ProjectionMenu
* @constructor
* @classdesc Provides a projection menu to select the projection for a WorldWindow.
* @param {WorldWindow} worldWindow The WorldWindow to associate this projection menu with.
*/
var ProjectionMenu = function (worldWindow) {
var thisExplorer = this;
this.wwd = worldWindow;
this.roundGlobe = this.wwd.globe;
this.createProjectionList();
$("#projectionDropdown").find(" li").on("click", function (e) {
thisExplorer.onProjectionClick(e);
});
};
ProjectionMenu.prototype.onProjectionClick = function (event) {
var projectionName = event.target.innerText || event.target.innerHTML;
$("#projectionDropdownTitle").html(projectionName + "<span class='caret'></span>");
if (projectionName === "3D") {
if (!this.roundGlobe) {
this.roundGlobe = new WorldWind.Globe(new WorldWind.EarthElevationModel());
}
if (this.wwd.globe !== this.roundGlobe) {
this.wwd.globe = this.roundGlobe;
}
} else {
if (!this.flatGlobe) {
this.flatGlobe = new WorldWind.Globe2D();
}
if (projectionName === "Equirectangular") {
this.flatGlobe.projection = new WorldWind.ProjectionEquirectangular();
} else if (projectionName === "Mercator") {
this.flatGlobe.projection = new WorldWind.ProjectionMercator();
} else if (projectionName === "North Polar") {
this.flatGlobe.projection = new WorldWind.ProjectionPolarEquidistant("North");
} else if (projectionName === "South Polar") {
this.flatGlobe.projection = new WorldWind.ProjectionPolarEquidistant("South");
} else if (projectionName === "North UPS") {
this.flatGlobe.projection = new WorldWind.ProjectionUPS("North");
} else if (projectionName === "South UPS") {
this.flatGlobe.projection = new WorldWind.ProjectionUPS("South");
} else if (projectionName === "North Gnomonic") {
this.flatGlobe.projection = new WorldWind.ProjectionGnomonic("North");
} else if (projectionName === "South Gnomonic") {
this.flatGlobe.projection = new WorldWind.ProjectionGnomonic("South");
}
if (this.wwd.globe !== this.flatGlobe) {
this.wwd.globe = this.flatGlobe;
}
}
this.wwd.redraw();
};
ProjectionMenu.prototype.createProjectionList = function () {
var projectionNames = [
"3D",
"Equirectangular",
"Mercator",
"North Polar",
"South Polar",
"North UPS",
"South UPS",
"North Gnomonic",
"South Gnomonic"
];
var projectionDropdown = $("#projectionDropdown");
var ulItem = $('<ul class="dropdown-menu"></ul>');
projectionDropdown.append(ulItem);
for (var i = 0; i < projectionNames.length; i++) {
var projectionItem = $('<li><a>' + projectionNames[i] + '</a></li>');
ulItem.append(projectionItem);
}
};
return ProjectionMenu;
});