GroupMetadata.js 5.4 KB

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