/* * Copyright 2003-2006, 2009, 2017, 2020 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. * * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source * software: * * ES6-Promise – under MIT License * libtess.js – SGI Free Software License B * Proj4 – under MIT License * JSZip – under MIT License * * A complete listing of 3rd Party software notices and licenses included in * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses * PDF found in code directory. */ /** * @exports ServersPanel */ define(function () { "use strict"; /** * Constructs a servers panel. * @alias ServersPanel * @constructor * @classdesc Provides a list of collapsible panels that indicate the layers associated with a WMS or other * image server. Currently only WMS is supported. The user can select a server's layers and they will be added to * the WorldWindow's layer list. * @param {WorldWindow} worldWindow The WorldWindow to associate this layers panel with. * @param {LayersPanel} layersPanel The layers panel managing the specified WorldWindows layer list. */ var ServersPanel = function (worldWindow, layersPanel, timeSeriesPlayer) { var thisServersPanel = this; this.wwd = worldWindow; this.layersPanel = layersPanel; this.timeSeriesPlayer = timeSeriesPlayer; this.idCounter = 1; this.legends = {}; $("#addServerBox").find("button").on("click", function (e) { thisServersPanel.onAddServerButton(e); }); $("#addServerText").on("keypress", function (e) { thisServersPanel.onAddServerTextKeyPress($(this), e); }); }; ServersPanel.prototype.onAddServerButton = function (event) { this.attachServer($("#addServerText")[0].value); $("#addServerText").val(""); }; ServersPanel.prototype.onAddServerTextKeyPress = function (searchInput, event) { if (event.keyCode === 13) { searchInput.blur(); this.attachServer($("#addServerText")[0].value); $("#addServerText").val(""); } }; ServersPanel.prototype.attachServer = function (serverAddress) { if (!serverAddress) { return; } serverAddress = serverAddress.trim(); // Search for 'https' or 'http' (case insensitive) and substitute it for lowercase 'https' serverAddress = serverAddress.replace(/https|http/i, "https"); if (serverAddress.lastIndexOf("https", 0) != 0) { serverAddress = "https://" + serverAddress; } var thisExplorer = this, request = new XMLHttpRequest(), url = WorldWind.WmsUrlBuilder.fixGetMapString(serverAddress); url += "service=WMS&request=GetCapabilities&vers"; request.open("GET", url, true); request.onreadystatechange = function () { if (request.readyState === 4 && request.status === 200) { var xmlDom = request.responseXML; if (!xmlDom && request.responseText.indexOf(" 0 ? wmsService.title : serverAddress; // //var html = '
'; //html += ''; //html += '
'; //html += '
'; //html += 'This is some text to display in the collapse panel.'; //html += '
'; var topDiv = $('
'), heading = $(''), title = $('

'), anchor = $('' + panelTitle + ''), remove = $(''), bodyParent = $('
'), body = $('
'), treeDiv = this.makeTree(serverAddress, treeId); remove.on("click", function () { topDiv.remove(); }); title.append(anchor); title.append(remove); heading.append(title); topDiv.append(heading); body.append(treeDiv); bodyParent.append(body); topDiv.append(bodyParent); var serversItem = $("#servers"); serversItem.append(topDiv); var treeRoot = treeDiv.fancytree("getRootNode"); // Don't show the top-level layer if it's a grouping layer with the same title as the server title. // The NEO server is set up this way, for example. var layers = wmsCapsDoc.capability.layers; if ((layers.length === 1) && (layers[0].layers) && (layers[0].title === wmsCapsDoc.service.title) && !(layers[0].name && layers[0].name.length > 0)) { layers = layers[0].layers; } treeRoot.addChildren(this.assembleLayers(layers, [])); // Collapse grouping nodes if there are many of them. var numNodes = 0; treeRoot.visit(function (node) { ++numNodes; }); if (numNodes > 10) { treeRoot.visit(function (node) { node.setExpanded(false); }); } }; ServersPanel.prototype.makeTree = function (serverAddress, treeId) { var thisServersPanel = this, treeDivId = "treeDiv" + treeId, treeDataId = "treeData" + treeId, treeDiv = $('
'), treeUl = $('