Skip to content

Commit

Permalink
Converted USGS Topo and Imagery Topo base maps to WMTS service endpoi…
Browse files Browse the repository at this point in the history
…nts.

- Quality is better!
- Performance is better!
- Cache-Control headers are included!
- Closes #36
  • Loading branch information
emxsys committed Nov 20, 2018
1 parent 08d99d3 commit a2f55ae
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 68 deletions.
111 changes: 70 additions & 41 deletions root/js/model/globe/layers/UsgsImageryTopoBaseMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.</li>
};

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;
}
);
return UsgsImageryTopoBaseMapLayer;
});
85 changes: 58 additions & 27 deletions root/js/model/globe/layers/UsgsTopoBaseMapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.</li>
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;
}
);
});

0 comments on commit a2f55ae

Please sign in to comment.