ImplicitSubtreeMetadata.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import MetadataEntity from "./MetadataEntity.js";
  5. /**
  6. * Metadata about an implicit subtree.
  7. * <p>
  8. * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles
  9. * </p>
  10. *
  11. * @param {Object} options Object with the following properties:
  12. * @param {Object} options.subtreeMetadata The subtree metadata JSON object.
  13. * @param {MetadataClass} options.class The class that subtree metadata conforms to.
  14. *
  15. * @alias ImplicitSubtreeMetadata
  16. * @constructor
  17. * @private
  18. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  19. */
  20. function ImplicitSubtreeMetadata(options) {
  21. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22. const subtreeMetadata = options.subtreeMetadata;
  23. const metadataClass = options.class;
  24. //>>includeStart('debug', pragmas.debug);
  25. Check.typeOf.object("options.subtreeMetadata", subtreeMetadata);
  26. Check.typeOf.object("options.class", metadataClass);
  27. //>>includeEnd('debug');
  28. const properties = defined(subtreeMetadata.properties)
  29. ? subtreeMetadata.properties
  30. : {};
  31. this._class = metadataClass;
  32. this._properties = properties;
  33. this._extras = subtreeMetadata.extras;
  34. this._extensions = subtreeMetadata.extensions;
  35. }
  36. Object.defineProperties(ImplicitSubtreeMetadata.prototype, {
  37. /**
  38. * The class that properties conform to.
  39. *
  40. * @memberof ImplicitSubtreeMetadata.prototype
  41. * @type {MetadataClass}
  42. * @readonly
  43. * @private
  44. */
  45. class: {
  46. get: function () {
  47. return this._class;
  48. },
  49. },
  50. /**
  51. * Extras in the JSON object.
  52. *
  53. * @memberof ImplicitSubtreeMetadata.prototype
  54. * @type {Object}
  55. * @readonly
  56. * @private
  57. */
  58. extras: {
  59. get: function () {
  60. return this._extras;
  61. },
  62. },
  63. /**
  64. * Extensions in the JSON object.
  65. *
  66. * @memberof ImplicitSubtreeMetadata.prototype
  67. * @type {Object}
  68. * @readonly
  69. * @private
  70. */
  71. extensions: {
  72. get: function () {
  73. return this._extensions;
  74. },
  75. },
  76. });
  77. /**
  78. * Returns whether the subtree has this property.
  79. *
  80. * @param {String} propertyId The case-sensitive ID of the property.
  81. * @returns {Boolean} Whether the subtree has this property.
  82. * @private
  83. */
  84. ImplicitSubtreeMetadata.prototype.hasProperty = function (propertyId) {
  85. return MetadataEntity.hasProperty(propertyId, this._properties, this._class);
  86. };
  87. /**
  88. * Returns whether the subtree has a property with the given semantic.
  89. *
  90. * @param {String} semantic The case-sensitive semantic of the property.
  91. * @returns {Boolean} Whether the subtree has a property with the given semantic.
  92. * @private
  93. */
  94. ImplicitSubtreeMetadata.prototype.hasPropertyBySemantic = function (semantic) {
  95. return MetadataEntity.hasPropertyBySemantic(
  96. semantic,
  97. this._properties,
  98. this._class
  99. );
  100. };
  101. /**
  102. * Returns an array of property IDs.
  103. *
  104. * @param {String[]} [results] An array into which to store the results.
  105. * @returns {String[]} The property IDs.
  106. * @private
  107. */
  108. ImplicitSubtreeMetadata.prototype.getPropertyIds = function (results) {
  109. return MetadataEntity.getPropertyIds(this._properties, this._class, results);
  110. };
  111. /**
  112. * Returns a copy of the value of the property with the given ID.
  113. * <p>
  114. * If the property is normalized the normalized value is returned.
  115. * </p>
  116. *
  117. * @param {String} propertyId The case-sensitive ID of the property.
  118. * @returns {*} The value of the property or <code>undefined</code> if the subtree does not have this property.
  119. * @private
  120. */
  121. ImplicitSubtreeMetadata.prototype.getProperty = function (propertyId) {
  122. return MetadataEntity.getProperty(propertyId, this._properties, this._class);
  123. };
  124. /**
  125. * Sets the value of the property with the given ID.
  126. * <p>
  127. * If the property is normalized a normalized value must be provided to this function.
  128. * </p>
  129. *
  130. * @param {String} propertyId The case-sensitive ID of the property.
  131. * @param {*} value The value of the property that will be copied.
  132. * @returns {Boolean} <code>true</code> if the property was set, <code>false</code> otherwise.
  133. * @private
  134. */
  135. ImplicitSubtreeMetadata.prototype.setProperty = function (propertyId, value) {
  136. return MetadataEntity.setProperty(
  137. propertyId,
  138. value,
  139. this._properties,
  140. this._class
  141. );
  142. };
  143. /**
  144. * Returns a copy of the value of the property with the given semantic.
  145. *
  146. * @param {String} semantic The case-sensitive semantic of the property.
  147. * @returns {*} The value of the property or <code>undefined</code> if the subtree does not have this semantic.
  148. * @private
  149. */
  150. ImplicitSubtreeMetadata.prototype.getPropertyBySemantic = function (semantic) {
  151. return MetadataEntity.getPropertyBySemantic(
  152. semantic,
  153. this._properties,
  154. this._class
  155. );
  156. };
  157. /**
  158. * Sets the value of the property with the given semantic.
  159. *
  160. * @param {String} semantic The case-sensitive semantic of the property.
  161. * @param {*} value The value of the property that will be copied.
  162. * @returns {Boolean} <code>true</code> if the property was set, <code>false</code> otherwise.
  163. * @private
  164. */
  165. ImplicitSubtreeMetadata.prototype.setPropertyBySemantic = function (
  166. semantic,
  167. value
  168. ) {
  169. return MetadataEntity.setPropertyBySemantic(
  170. semantic,
  171. value,
  172. this._properties,
  173. this._class
  174. );
  175. };
  176. export default ImplicitSubtreeMetadata;