Models/UrlTemplateCatalogItem.js

  1. "use strict";
  2. /*global require*/
  3. var i18next = require("i18next").default;
  4. var UrlTemplateImageryProvider = require("terriajs-cesium/Source/Scene/UrlTemplateImageryProvider")
  5. .default;
  6. var knockout = require("terriajs-cesium/Source/ThirdParty/knockout").default;
  7. var ImageryLayerCatalogItem = require("./ImageryLayerCatalogItem");
  8. var inherit = require("../Core/inherit");
  9. var proxyCatalogItemUrl = require("./proxyCatalogItemUrl");
  10. /**
  11. * A {@link ImageryLayerCatalogItem} representing a layer from a mapping server that can be reached
  12. * via a URL template.
  13. *
  14. * @alias UrlTemplateCatalogItem
  15. * @constructor
  16. * @extends ImageryLayerCatalogItem
  17. *
  18. * @param {Terria} terria The Terria instance.
  19. */
  20. var UrlTemplateCatalogItem = function(terria) {
  21. ImageryLayerCatalogItem.call(this, terria);
  22. /**
  23. * Gets or sets the minimum tile level to retrieve from the map data
  24. * This property is observable.
  25. * @type {String}
  26. */
  27. this.minimumLevel = 0;
  28. /**
  29. * Gets or sets the maximum tile level to retrieve from the map data
  30. * This property is observable.
  31. * @type {String}
  32. */
  33. this.maximumLevel = 25;
  34. /**
  35. * Gets or sets the attribution to display with the data
  36. * This property is observable.
  37. * @type {String}
  38. */
  39. this.attribution = undefined;
  40. /**
  41. * Gets or sets the array of subdomains, one of which will be prepended to each tile URL.
  42. * This property is observable.
  43. * @type {Array}
  44. */
  45. this.subdomains = undefined;
  46. /**
  47. * Gets or sets the tile discard policy.
  48. * @type {TileDiscardPolicy}
  49. */
  50. this.tileDiscardPolicy = undefined;
  51. knockout.track(this, [
  52. "minimumLevel",
  53. "maximumLevel",
  54. "attribution",
  55. "subdomains",
  56. "tileDiscardPolicy"
  57. ]);
  58. };
  59. inherit(ImageryLayerCatalogItem, UrlTemplateCatalogItem);
  60. Object.defineProperties(UrlTemplateCatalogItem.prototype, {
  61. /**
  62. * Gets the type of data item represented by this instance.
  63. * @memberOf UrlTemplateCatalogItem.prototype
  64. * @type {String}
  65. */
  66. type: {
  67. get: function() {
  68. return "url-template";
  69. }
  70. },
  71. /**
  72. * Gets a human-readable name for this type of data source, 'URL Template Map Server'.
  73. * @memberOf UrlTemplateCatalogItem.prototype
  74. * @type {String}
  75. */
  76. typeName: {
  77. get: function() {
  78. return i18next.t("models.urlTemplateMapServer.name");
  79. }
  80. }
  81. });
  82. UrlTemplateCatalogItem.prototype._createImageryProvider = function() {
  83. return new UrlTemplateImageryProvider({
  84. url: proxyCatalogItemUrl(this, this.url),
  85. maximumLevel: this.maximumLevel,
  86. minimumLevel: this.minimumLevel,
  87. credit: this.attribution,
  88. subdomains: this.subdomains,
  89. tileDiscardPolicy: this.tileDiscardPolicy,
  90. rectangle: this.rectangle
  91. });
  92. };
  93. module.exports = UrlTemplateCatalogItem;