Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert USGS from WMS services to WMTS #36

Closed
emxsys opened this issue Nov 18, 2018 · 2 comments
Closed

Convert USGS from WMS services to WMTS #36

emxsys opened this issue Nov 18, 2018 · 2 comments

Comments

@emxsys
Copy link
Member

emxsys commented Nov 18, 2018

The USGS Topo WMTS map service from the National Map is much faster than the WMS service and also contains Cache-Control headers.

@emxsys
Copy link
Member Author

emxsys commented Nov 20, 2018

Attempted to use WMTS service. Was FAST, but georeferencing alignment was off E/W ~100m.

/* 
 * Copyright (c) 2016 Bruce Schubert.
 * The MIT License
 * http://www.opensource.org/licenses/mit-license
 */

/*global define, WorldWind, $ */

/**
 * The USGS TNM Topo Base Map layer.
 * 
 * @returns {UsgsTopoBaseMapLayer}
 */
define([
    'jquery',
    'worldwind'],
    function () {
    "use strict";
    /**
     * Constructs a USGS Topo map layer.
     * @constructor
     */
    var UsgsTopoBaseMapLayer = function () {
        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);
        };

        // 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);
        };

        $.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);
    };

    /**
     * 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);
    };

    /**
     * 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;
});

@emxsys
Copy link
Member Author

emxsys commented Nov 20, 2018

Resolved the misregistration with the workaournd specified in this issue: NASAWorldWind/WebWorldWind#793

@emxsys emxsys closed this as completed in a2f55ae Nov 20, 2018
@emxsys emxsys added this to the Construction #1 milestone Nov 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant