TilesetMetadata.js 5.2 KB

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