智慧水务管理系统 - 精河县供水工程综合管理平台

StructuralMetadata.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import { destroyObject } from "@cesium/engine";
  2. import Check from "../Core/Check.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import defined from "../Core/defined.js";
  5. /**
  6. * An object containing structural metadata.
  7. * <p>
  8. * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the
  9. * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.
  10. * </p>
  11. *
  12. * @param {object} options Object with the following properties:
  13. * @param {MetadataSchema} options.schema The parsed schema.
  14. * @param {PropertyTable[]} [options.propertyTables] An array of property table objects. For the legacy <code>EXT_feature_metadata</code> extension, this is sorted by the key in the propertyTables dictionary
  15. * @param {PropertyTexture[]} [options.propertyTextures] An array of property texture objects. For the legacy <code>EXT_feature_metadata</code> extension, this is sorted by the key in the propertyTextures dictionary
  16. * @param {PropertyAttribute[]} [options.propertyAttributes] An array of property attribute objects. This is new in <code>EXT_structural_metadata</code>
  17. * @param {object} [options.statistics] Statistics about metadata
  18. * @param {object} [options.extras] Extra user-defined properties
  19. * @param {object} [options.extensions] An object containing extensions
  20. *
  21. * @alias StructuralMetadata
  22. * @constructor
  23. *
  24. * @private
  25. * @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.
  26. */
  27. function StructuralMetadata(options) {
  28. options = options ?? Frozen.EMPTY_OBJECT;
  29. //>>includeStart('debug', pragmas.debug);
  30. Check.typeOf.object("options.schema", options.schema);
  31. //>>includeEnd('debug');
  32. this._schema = options.schema;
  33. const propertyTables = options.propertyTables;
  34. this._propertyTableCount = defined(propertyTables)
  35. ? propertyTables.length
  36. : 0;
  37. this._propertyTables = propertyTables ?? [];
  38. this._propertyTextures = options.propertyTextures ?? [];
  39. this._propertyAttributes = options.propertyAttributes ?? [];
  40. this._statistics = options.statistics;
  41. this._extras = options.extras;
  42. this._extensions = options.extensions;
  43. }
  44. Object.defineProperties(StructuralMetadata.prototype, {
  45. /**
  46. * Schema containing classes and enums.
  47. *
  48. * @memberof StructuralMetadata.prototype
  49. * @type {MetadataSchema}
  50. * @readonly
  51. * @private
  52. */
  53. schema: {
  54. get: function () {
  55. return this._schema;
  56. },
  57. },
  58. /**
  59. * Statistics about the metadata.
  60. * <p>
  61. * See the {@link https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.schema.json|statistics schema reference} for the full set of properties.
  62. * </p>
  63. *
  64. * @memberof StructuralMetadata.prototype
  65. * @type {object}
  66. * @readonly
  67. * @private
  68. */
  69. statistics: {
  70. get: function () {
  71. return this._statistics;
  72. },
  73. },
  74. /**
  75. * Extra user-defined properties.
  76. *
  77. * @memberof StructuralMetadata.prototype
  78. * @type {*}
  79. * @readonly
  80. * @private
  81. */
  82. extras: {
  83. get: function () {
  84. return this._extras;
  85. },
  86. },
  87. /**
  88. * An object containing extensions.
  89. *
  90. * @memberof StructuralMetadata.prototype
  91. * @type {object}
  92. * @readonly
  93. * @private
  94. */
  95. extensions: {
  96. get: function () {
  97. return this._extensions;
  98. },
  99. },
  100. /**
  101. * Number of property tables in the metadata.
  102. *
  103. * @memberof StructuralMetadata.prototype
  104. * @type {number}
  105. * @readonly
  106. * @private
  107. */
  108. propertyTableCount: {
  109. get: function () {
  110. return this._propertyTableCount;
  111. },
  112. },
  113. /**
  114. * The property tables in the metadata.
  115. *
  116. * @memberof StructuralMetadata.prototype
  117. * @type {PropertyTable[]}
  118. * @readonly
  119. * @private
  120. */
  121. propertyTables: {
  122. get: function () {
  123. return this._propertyTables;
  124. },
  125. },
  126. /**
  127. * The property textures in the metadata.
  128. *
  129. * @memberof StructuralMetadata.prototype
  130. * @type {PropertyTexture[]}
  131. * @readonly
  132. * @private
  133. */
  134. propertyTextures: {
  135. get: function () {
  136. return this._propertyTextures;
  137. },
  138. },
  139. /**
  140. * The property attributes from the structural metadata extension
  141. *
  142. * @memberof StructuralMetadata.prototype
  143. * @type {PropertyAttribute[]}
  144. * @readonly
  145. * @private
  146. */
  147. propertyAttributes: {
  148. get: function () {
  149. return this._propertyAttributes;
  150. },
  151. },
  152. /**
  153. * Total size in bytes across all property tables
  154. *
  155. * @memberof StructuralMetadata.prototype
  156. * @type {number}
  157. * @readonly
  158. * @private
  159. */
  160. propertyTablesByteLength: {
  161. get: function () {
  162. if (!defined(this._propertyTables)) {
  163. return 0;
  164. }
  165. let totalByteLength = 0;
  166. const length = this._propertyTables.length;
  167. for (let i = 0; i < length; i++) {
  168. totalByteLength += this._propertyTables[i].byteLength;
  169. }
  170. return totalByteLength;
  171. },
  172. },
  173. });
  174. /**
  175. * Gets the property table with the given ID.
  176. * <p>
  177. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  178. * by the key in the propertyTables dictionary.
  179. * </p>
  180. *
  181. * @param {number} propertyTableId The property table ID.
  182. * @returns {PropertyTable} The property table.
  183. * @private
  184. */
  185. StructuralMetadata.prototype.getPropertyTable = function (propertyTableId) {
  186. //>>includeStart('debug', pragmas.debug);
  187. Check.typeOf.number("propertyTableId", propertyTableId);
  188. //>>includeEnd('debug');
  189. return this._propertyTables[propertyTableId];
  190. };
  191. /**
  192. * Gets the property texture with the given ID.
  193. * <p>
  194. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  195. * by the key in the propertyTextures dictionary.
  196. * </p>
  197. *
  198. * @param {number} propertyTextureId The index into the property textures array.
  199. * @returns {PropertyTexture} The property texture
  200. * @private
  201. */
  202. StructuralMetadata.prototype.getPropertyTexture = function (propertyTextureId) {
  203. //>>includeStart('debug', pragmas.debug);
  204. Check.typeOf.number("propertyTextureId", propertyTextureId);
  205. //>>includeEnd('debug');
  206. return this._propertyTextures[propertyTextureId];
  207. };
  208. /**
  209. * Gets the property attribute with the given ID. This concept is new in
  210. * EXT_structural_metadata
  211. *
  212. * @param {number} propertyAttributeId The index into the property attributes array.
  213. * @returns {PropertyAttribute} The property attribute
  214. * @private
  215. */
  216. StructuralMetadata.prototype.getPropertyAttribute = function (
  217. propertyAttributeId,
  218. ) {
  219. //>>includeStart('debug', pragmas.debug);
  220. Check.typeOf.number("propertyAttributeId", propertyAttributeId);
  221. //>>includeEnd('debug');
  222. return this._propertyAttributes[propertyAttributeId];
  223. };
  224. /**
  225. * Destroys any resources that need cleaning up in the structural metadata.
  226. *
  227. * @private
  228. */
  229. StructuralMetadata.prototype.destroy = function () {
  230. const propertyTables = this._propertyTables;
  231. for (let i = 0; i < propertyTables.length; i++) {
  232. propertyTables[i] = propertyTables[i] && propertyTables[i].destroy();
  233. }
  234. return destroyObject(this);
  235. };
  236. export default StructuralMetadata;