ContentMetadata.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import MetadataEntity from "./MetadataEntity.js";
  4. /**
  5. * Metadata about the content of a 3D Tile. This represents the content metadata JSON (3D Tiles 1.1)
  6. * or the <code>3DTILES_metadata</code> extension on a single {@link Cesium3DTileContent}
  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.content Either the content metadata JSON (3D Tiles 1.1) or the extension JSON attached to the content.
  13. * @param {MetadataClass} options.class The class that the content metadata conforms to.
  14. *
  15. * @alias ContentMetadata
  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 ContentMetadata(options) {
  21. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22. const content = options.content;
  23. const metadataClass = options.class;
  24. //>>includeStart('debug', pragmas.debug);
  25. Check.typeOf.object("options.content", content);
  26. Check.typeOf.object("options.class", metadataClass);
  27. //>>includeEnd('debug');
  28. this._class = metadataClass;
  29. this._properties = content.properties;
  30. this._extensions = content.extensions;
  31. this._extras = content.extras;
  32. }
  33. Object.defineProperties(ContentMetadata.prototype, {
  34. /**
  35. * The class that properties conform to.
  36. *
  37. * @memberof ContentMetadata.prototype
  38. * @type {MetadataClass}
  39. * @readonly
  40. * @private
  41. */
  42. class: {
  43. get: function () {
  44. return this._class;
  45. },
  46. },
  47. /**
  48. * Extra user-defined properties.
  49. *
  50. * @memberof ContentMetadata.prototype
  51. * @type {object}
  52. * @readonly
  53. * @private
  54. */
  55. extras: {
  56. get: function () {
  57. return this._extras;
  58. },
  59. },
  60. /**
  61. * An object containing extensions.
  62. *
  63. * @memberof ContentMetadata.prototype
  64. * @type {object}
  65. * @readonly
  66. * @private
  67. */
  68. extensions: {
  69. get: function () {
  70. return this._extensions;
  71. },
  72. },
  73. });
  74. /**
  75. * Returns whether the content has this property.
  76. *
  77. * @param {string} propertyId The case-sensitive ID of the property.
  78. * @returns {boolean} Whether the content has this property.
  79. * @private
  80. */
  81. ContentMetadata.prototype.hasProperty = function (propertyId) {
  82. return MetadataEntity.hasProperty(propertyId, this._properties, this._class);
  83. };
  84. /**
  85. * Returns whether the content has a property with the given semantic.
  86. *
  87. * @param {string} semantic The case-sensitive semantic of the property.
  88. * @returns {boolean} Whether the content has a property with the given semantic.
  89. * @private
  90. */
  91. ContentMetadata.prototype.hasPropertyBySemantic = function (semantic) {
  92. return MetadataEntity.hasPropertyBySemantic(
  93. semantic,
  94. this._properties,
  95. this._class
  96. );
  97. };
  98. /**
  99. * Returns an array of property IDs.
  100. *
  101. * @param {string[]} [results] An array into which to store the results.
  102. * @returns {string[]} The property IDs.
  103. * @private
  104. */
  105. ContentMetadata.prototype.getPropertyIds = function (results) {
  106. return MetadataEntity.getPropertyIds(this._properties, this._class, results);
  107. };
  108. /**
  109. * Returns a copy of the value of the property with the given ID.
  110. * <p>
  111. * If the property is normalized the normalized value is returned.
  112. * </p>
  113. *
  114. * @param {string} propertyId The case-sensitive ID of the property.
  115. * @returns {*} The value of the property or <code>undefined</code> if the content does not have this property.
  116. * @private
  117. */
  118. ContentMetadata.prototype.getProperty = function (propertyId) {
  119. return MetadataEntity.getProperty(propertyId, this._properties, this._class);
  120. };
  121. /**
  122. * Sets the value of the property with the given ID.
  123. * <p>
  124. * If the property is normalized a normalized value must be provided to this function.
  125. * </p>
  126. *
  127. * @param {string} propertyId The case-sensitive ID of the property.
  128. * @param {*} value The value of the property that will be copied.
  129. * @returns {boolean} <code>true</code> if the property was set, <code>false</code> otherwise.
  130. * @private
  131. */
  132. ContentMetadata.prototype.setProperty = function (propertyId, value) {
  133. return MetadataEntity.setProperty(
  134. propertyId,
  135. value,
  136. this._properties,
  137. this._class
  138. );
  139. };
  140. /**
  141. * Returns a copy of the value of the property with the given semantic.
  142. *
  143. * @param {string} semantic The case-sensitive semantic of the property.
  144. * @returns {*} The value of the property or <code>undefined</code> if the content does not have this semantic.
  145. * @private
  146. */
  147. ContentMetadata.prototype.getPropertyBySemantic = function (semantic) {
  148. return MetadataEntity.getPropertyBySemantic(
  149. semantic,
  150. this._properties,
  151. this._class
  152. );
  153. };
  154. /**
  155. * Sets the value of the property with the given semantic.
  156. *
  157. * @param {string} semantic The case-sensitive semantic of the property.
  158. * @param {*} value The value of the property that will be copied.
  159. * @returns {boolean} <code>true</code> if the property was set, <code>false</code> otherwise.
  160. * @private
  161. */
  162. ContentMetadata.prototype.setPropertyBySemantic = function (semantic, value) {
  163. return MetadataEntity.setPropertyBySemantic(
  164. semantic,
  165. value,
  166. this._properties,
  167. this._class
  168. );
  169. };
  170. export default ContentMetadata;