ImplicitMetadataView.js 5.5 KB

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