From a2f55ae4418e777d2d6be768b5cc5b3cfed39e23 Mon Sep 17 00:00:00 2001 From: Bruce Schubert Date: Tue, 20 Nov 2018 06:47:58 -0800 Subject: [PATCH] Converted USGS Topo and Imagery Topo base maps to WMTS service endpoints. - Quality is better! - Performance is better! - Cache-Control headers are included! - Closes #36 --- .../layers/UsgsImageryTopoBaseMapLayer.js | 111 +++++++++++------- .../globe/layers/UsgsTopoBaseMapLayer.js | 85 +++++++++----- 2 files changed, 128 insertions(+), 68 deletions(-) diff --git a/root/js/model/globe/layers/UsgsImageryTopoBaseMapLayer.js b/root/js/model/globe/layers/UsgsImageryTopoBaseMapLayer.js index 1737828..b3fa456 100644 --- a/root/js/model/globe/layers/UsgsImageryTopoBaseMapLayer.js +++ b/root/js/model/globe/layers/UsgsImageryTopoBaseMapLayer.js @@ -4,55 +4,84 @@ * http://www.opensource.org/licenses/mit-license */ -/*global define, WorldWind */ +/*global define, WorldWind, $ */ /** - * The USGS Imagery Topo Base Map layer. + * The USGS TNM Topo Base Map layer. * - * See: https://basemap.nationalmap.gov/arcgis/services/USGSImageryTopo/MapServer/WMSServer?request=GetCapabilities&service=WMS + * See: https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryTopo/MapServer/WMTS/1.0.0/WMTSCapabilities.xml * * @returns {UsgsImageryTopoBaseMapLayer} */ - define([ - 'model/globe/layers/EnhancedWmsLayer', + 'jquery', 'worldwind'], - function (EnhancedWmsLayer) { - "use strict"; - - /** - * Constructs a USGS Imagery Topo map layer. - * @constructor - * @augments WmsLayer - */ - var UsgsImageryTopoBaseMapLayer = function () { - var cfg = { - title: "USGS Imagery Topo Basemap", - version: "1.3.0", -// service: "https://basemap.nationalmap.gov:443/arcgis/services/USGSImageryTopo/MapServer/WmsServer?", - service: "https://emxsys.net/USGSImageryTopo/MapServer/WmsServer?", - layerNames: "0", - sector: new WorldWind.Sector(-90.0, 90.0, -180, 180), - levelZeroDelta: new WorldWind.Location(180, 180), - numLevels: 15, - format: "image/png", - size: 256, - coordinateSystem: "EPSG:4326", // optional - styleNames: "" // (optional): {String} A comma separated list of the styles to include in this layer. - }; - - EnhancedWmsLayer.call(this, cfg); - - // Make this layer opaque - this.opacity = 1.0; - - // Requesting tiles with transparency (the nominal case) causes the layer's labels to bleed - // the underlying background layer which makes for a rather ugly map. - this.urlBuilder.transparent = false; + function () { + "use strict"; + /** + * Constructs a USGS Topo map layer. + * @constructor + * @augments Layer + */ + var UsgsImageryTopoBaseMapLayer = function () { + WorldWind.Layer.call(this, "USGS Imagery Topo Basemap"); + + // Web Map Tiling Service information from + var serviceAddress = "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryTopo/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"; + var layerIdentifier = "USGSImageryTopo"; + var self = this; + + // Called asynchronously to parse and create the WMTS layer + var createLayer = function (xmlDom) { + // Create a WmtsCapabilities object from the XML DOM + var wmtsCapabilities = new WorldWind.WmtsCapabilities(xmlDom); + // Retrieve a WmtsLayerCapabilities object by the desired layer name + var wmtsLayerCapabilities = wmtsCapabilities.getLayer(layerIdentifier); + // Form a configuration object from the WmtsLayerCapabilities object + var wmtsConfig = WorldWind.WmtsLayer.formLayerConfiguration(wmtsLayerCapabilities); + // Create the WMTS Layer from the configuration object + self.wmtsLayer = new WorldWind.WmtsLayer(wmtsConfig); + }; + + // Called if an error occurs during WMTS Capabilities document retrieval + var logError = function (jqXhr, text, exception) { + console.log("There was a failure retrieving the capabilities document: " + text + " exception: " + exception); }; - UsgsImageryTopoBaseMapLayer.prototype = Object.create(EnhancedWmsLayer.prototype); + $.get(serviceAddress).done(createLayer).fail(logError); + }; + UsgsImageryTopoBaseMapLayer.prototype = Object.create(WorldWind.Layer.prototype); + + /** + * Refreshes the data associated with this layer. The behavior of this function varies with the layer + * type. For image layers, it causes the images to be re-retrieved from their origin. + */ + UsgsImageryTopoBaseMapLayer.prototype.refresh = function () { + return this.wmtsLayer.refresh(dc); + }; + + /** + * Subclass method called to display this layer. Subclasses should implement this method rather than the + * [render]{@link Layer#render} method, which determines enable, pick and active altitude status and does not + * call this doRender method if the layer should not be displayed. + * @param {DrawContext} dc The current draw context. + * @protected + */ + UsgsImageryTopoBaseMapLayer.prototype.doRender = function (dc) { + return this.wmtsLayer.doRender(dc); + }; + + /** + * Indicates whether this layer is within the current view. Subclasses may override this method and + * when called determine whether the layer contents are visible in the current view frustum. The default + * implementation always returns true. + * @param {DrawContext} dc The current draw context. + * @returns {boolean} true If this layer is within the current view, otherwise false. + * @protected + */ + UsgsImageryTopoBaseMapLayer.prototype.isLayerInView = function (dc) { + return this.wmtsLayer.isLayerInView(dc); + }; - return UsgsImageryTopoBaseMapLayer; - } -); \ No newline at end of file + return UsgsImageryTopoBaseMapLayer; +}); \ No newline at end of file diff --git a/root/js/model/globe/layers/UsgsTopoBaseMapLayer.js b/root/js/model/globe/layers/UsgsTopoBaseMapLayer.js index eb55f9b..bef5689 100644 --- a/root/js/model/globe/layers/UsgsTopoBaseMapLayer.js +++ b/root/js/model/globe/layers/UsgsTopoBaseMapLayer.js @@ -4,53 +4,84 @@ * http://www.opensource.org/licenses/mit-license */ -/*global define, WorldWind */ +/*global define, WorldWind, $ */ /** * The USGS TNM Topo Base Map layer. * - * See: https://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer?request=GetCapabilities&service=WMS + * See: https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/WMTS/1.0.0/WMTSCapabilities.xml * * @returns {UsgsTopoBaseMapLayer} */ define([ - 'model/globe/layers/EnhancedWmsLayer', + 'jquery', 'worldwind'], - function (EnhancedWmsLayer) { + function () { "use strict"; /** * Constructs a USGS Topo map layer. * @constructor - * @augments WmsLayer + * @augments Layer */ var UsgsTopoBaseMapLayer = function () { - var cfg = { - title: "USGS Topo Basemap", - version: "1.3.0", -// service: "https://basemap.nationalmap.gov:443/arcgis/services/USGSTopo/MapServer/WmsServer?", - service: "https://emxsys.net/USGSTopo/MapServer/WmsServer?", - layerNames: "0", - sector: new WorldWind.Sector(-90.0, 90.0, -180, 180), - levelZeroDelta: new WorldWind.Location(180, 180), - numLevels: 15, - format: "image/png", - size: 256, - coordinateSystem: "EPSG:4326", // optional - styleNames: "" // (optional): {String} A comma separated list of the styles to include in this layer. + WorldWind.Layer.call(this, "USGS Topo Basemap"); + + // Web Map Tiling Service information from + var serviceAddress = "https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"; + var layerIdentifier = "USGSTopo"; + var self = this; + + // Called asynchronously to parse and create the WMTS layer + var createLayer = function (xmlDom) { + // Create a WmtsCapabilities object from the XML DOM + var wmtsCapabilities = new WorldWind.WmtsCapabilities(xmlDom); + // Retrieve a WmtsLayerCapabilities object by the desired layer name + var wmtsLayerCapabilities = wmtsCapabilities.getLayer(layerIdentifier); + // Form a configuration object from the WmtsLayerCapabilities object + var wmtsConfig = WorldWind.WmtsLayer.formLayerConfiguration(wmtsLayerCapabilities); + // Create the WMTS Layer from the configuration object + self.wmtsLayer = new WorldWind.WmtsLayer(wmtsConfig); }; - EnhancedWmsLayer.call(this, cfg); + // Called if an error occurs during WMTS Capabilities document retrieval + var logError = function (jqXhr, text, exception) { + console.log("There was a failure retrieving the capabilities document: " + text + " exception: " + exception); + }; - // Make this layer opaque - this.opacity = 1.0; + $.get(serviceAddress).done(createLayer).fail(logError); + }; + UsgsTopoBaseMapLayer.prototype = Object.create(WorldWind.Layer.prototype); + + /** + * Refreshes the data associated with this layer. The behavior of this function varies with the layer + * type. For image layers, it causes the images to be re-retrieved from their origin. + */ + UsgsTopoBaseMapLayer.prototype.refresh = function () { + return this.wmtsLayer.refresh(dc); + }; - // Requesting tiles with transparency (the nominal case) causes the layer's labels to bleed - // the underlying background layer which makes for a rather ugly map. - this.urlBuilder.transparent = false; + /** + * Subclass method called to display this layer. Subclasses should implement this method rather than the + * [render]{@link Layer#render} method, which determines enable, pick and active altitude status and does not + * call this doRender method if the layer should not be displayed. + * @param {DrawContext} dc The current draw context. + * @protected + */ + UsgsTopoBaseMapLayer.prototype.doRender = function (dc) { + return this.wmtsLayer.doRender(dc); }; - UsgsTopoBaseMapLayer.prototype = Object.create(EnhancedWmsLayer.prototype); + /** + * Indicates whether this layer is within the current view. Subclasses may override this method and + * when called determine whether the layer contents are visible in the current view frustum. The default + * implementation always returns true. + * @param {DrawContext} dc The current draw context. + * @returns {boolean} true If this layer is within the current view, otherwise false. + * @protected + */ + UsgsTopoBaseMapLayer.prototype.isLayerInView = function (dc) { + return this.wmtsLayer.isLayerInView(dc); + }; return UsgsTopoBaseMapLayer; -} -); \ No newline at end of file +}); \ No newline at end of file