Source: util/LevelRowColumnUrlBuilder.js

  1. /*
  2. * Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
  3. * by the Administrator of the National Aeronautics and Space Administration.
  4. * All rights reserved.
  5. *
  6. * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
  7. * Version 2.0 (the "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License
  9. * at http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. *
  16. * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
  17. * software:
  18. *
  19. * ES6-Promise – under MIT License
  20. * libtess.js – SGI Free Software License B
  21. * Proj4 – under MIT License
  22. * JSZip – under MIT License
  23. *
  24. * A complete listing of 3rd Party software notices and licenses included in
  25. * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
  26. * PDF found in code directory.
  27. */
  28. /**
  29. * @exports LevelRowColumnUrlBuilder
  30. */
  31. define([
  32. '../error/ArgumentError',
  33. '../util/Logger',
  34. '../util/WWUtil'
  35. ],
  36. function (ArgumentError,
  37. Logger,
  38. WWUtil) {
  39. "use strict";
  40. /**
  41. * Constructs a URL builder for level/row/column tiles.
  42. * @alias LevelRowColumnUrlBuilder
  43. * @constructor
  44. * @classdesc Provides a factory to create URLs for level/row/column tile REST requests.
  45. * <p>
  46. * URLs are formed by appending the specified server address with the specified path and appending
  47. * a path of the form <em>/level/row/row_column.image-format</em>, where image-format is the corresponding
  48. * suffix to the image mime type specified when a URL is requested. For example, if the specified server
  49. * address is <em>https://worldwind32.arc.nasa.gov</em> and the specified path-to-data is
  50. * <em>../standalonedata/Earth/BlueMarble256</em>, and the requested tile's level, row and column are 0, 5 and 9
  51. * respectively, and the image format is <em>image/jpeg</em>, the composed URL is
  52. * <em>https://worldwind32.arc.nasa.gov/standalonedata/Earth/BlueMarble256/0/5/5_9.jpg</em>.
  53. *
  54. * @param {String} serverAddress The server address. May be null, in which case the address is assumed to be
  55. * the current location (see <code>window.location</code>) minus the last path component.
  56. * @param {String} pathToData The path to the dataset on the server. May be null or empty to indicate that
  57. * the data is directly relative to the specified server address.
  58. *
  59. */
  60. var LevelRowColumnUrlBuilder = function (serverAddress, pathToData) {
  61. /**
  62. * The server address.
  63. * @type {String}
  64. */
  65. this.serverAddress = serverAddress;
  66. if (!serverAddress || serverAddress.length === 0) {
  67. this.serverAddress = WWUtil.currentUrlSansFilePart();
  68. }
  69. /**
  70. * The server-side path to the dataset.
  71. * @type {String}
  72. */
  73. this.pathToData = pathToData;
  74. };
  75. /**
  76. * Creates the URL string for a WMS Get Map request.
  77. * @param {Tile} tile The tile for which to create the URL.
  78. * @param {String} imageFormat The image format to request.
  79. * @throws {ArgumentError} If the specified tile or image format are null or undefined.
  80. */
  81. LevelRowColumnUrlBuilder.prototype.urlForTile = function (tile, imageFormat) {
  82. if (!tile) {
  83. throw new ArgumentError(
  84. Logger.logMessage(Logger.LEVEL_SEVERE, "WmsUrlBuilder", "urlForTile", "missingTile"));
  85. }
  86. if (!imageFormat) {
  87. throw new ArgumentError(
  88. Logger.logMessage(Logger.LEVEL_SEVERE, "WmsUrlBuilder", "urlForTile",
  89. "The image format is null or undefined."));
  90. }
  91. var sb = this.serverAddress;
  92. if (this.pathToData) {
  93. sb = sb + "/" + this.pathToData;
  94. }
  95. sb = sb + "/" + tile.level.levelNumber.toString();
  96. sb = sb + "/" + tile.row.toString();
  97. sb = sb + "/" + tile.row.toString() + "_" + tile.column.toString();
  98. sb = sb + "." + WWUtil.suffixForMimeType(imageFormat);
  99. sb = sb.replace(" ", "%20");
  100. return sb;
  101. };
  102. return LevelRowColumnUrlBuilder;
  103. });