Source: formats/kml/util/KmlPair.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. define([
  29. './../KmlElements',
  30. '../KmlObject',
  31. '../styles/KmlStyleSelector',
  32. './KmlNodeTransformers'
  33. ], function (
  34. KmlElements,
  35. KmlObject,
  36. KmlStyleSelector,
  37. NodeTransformers
  38. ) {
  39. "use strict";
  40. /**
  41. * Constructs a KmlPair. Application usually don't call this constructor. It is called by {@link KmlFile} as
  42. * Objects from KmlFile are read. It is concrete implementation.
  43. * @alias KmlPair
  44. * @constructor
  45. * @classdesc Contains the data associated with Kml KmlPair
  46. * @param options {Object}
  47. * @param options.objectNode {Node} Node representing the Kml KmlPair.
  48. * @throws {ArgumentError} If either the node is null or undefined.
  49. * @see https://developers.google.com/kml/documentation/kmlreference#pair
  50. * @augments KmlObject
  51. */
  52. var KmlPair = function (options) {
  53. KmlObject.call(this, options);
  54. };
  55. KmlPair.prototype = Object.create(KmlObject.prototype);
  56. Object.defineProperties(KmlPair.prototype, {
  57. /**
  58. * Identifies the key
  59. * @memberof KmlPair.prototype
  60. * @readonly
  61. * @type {String}
  62. */
  63. kmlKey: {
  64. get: function() {
  65. return this._factory.specific(this, {name: 'key', transformer: NodeTransformers.string});
  66. }
  67. },
  68. /**
  69. * References the style using Url. If part of the same document start with the prefix #
  70. * @memberof KmlPair.prototype
  71. * @readonly
  72. * @type {String}
  73. */
  74. kmlStyleUrl: {
  75. get: function() {
  76. return this._factory.specific(this, {name: 'styleUrl', transformer: NodeTransformers.string});
  77. }
  78. },
  79. /**
  80. * Definition of styles applied to this KmlPair.
  81. * @memberof KmlPair.prototype
  82. * @readonly
  83. * @type {KmlStyle}
  84. */
  85. kmlStyleSelector: {
  86. get: function() {
  87. return this._factory.any(this, {
  88. name: KmlStyleSelector.prototype.getTagNames()
  89. });
  90. }
  91. }
  92. });
  93. /**
  94. * @inheritDoc
  95. */
  96. KmlPair.prototype.getTagNames = function () {
  97. return ['Pair'];
  98. };
  99. /**
  100. * @inheritDoc
  101. */
  102. KmlPair.prototype.getStyle = function(styleResolver) {
  103. return styleResolver.handleRemoteStyle(this.kmlStyleUrl, this.kmlStyleSelector);
  104. };
  105. KmlElements.addKey(KmlPair.prototype.getTagNames()[0], KmlPair);
  106. return KmlPair;
  107. });