MetadataClass.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import MetadataClassProperty from "./MetadataClassProperty.js";
  5. /**
  6. * A metadata class.
  7. *
  8. * <p>
  9. * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles
  10. * </p>
  11. *
  12. * @param {Object} options Object with the following properties:
  13. * @param {String} options.id The ID of the class.
  14. * @param {Object} options.class The class JSON object.
  15. * @param {Object.<String, MetadataEnum>} [options.enums] A dictionary of enums.
  16. *
  17. * @alias MetadataClass
  18. * @constructor
  19. * @private
  20. * @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.
  21. */
  22. function MetadataClass(options) {
  23. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  24. const id = options.id;
  25. const classDefinition = options.class;
  26. //>>includeStart('debug', pragmas.debug);
  27. Check.typeOf.string("options.id", id);
  28. Check.typeOf.object("options.class", classDefinition);
  29. //>>includeEnd('debug');
  30. const properties = {};
  31. const propertiesBySemantic = {};
  32. for (const propertyId in classDefinition.properties) {
  33. if (classDefinition.properties.hasOwnProperty(propertyId)) {
  34. const property = new MetadataClassProperty({
  35. id: propertyId,
  36. property: classDefinition.properties[propertyId],
  37. enums: options.enums,
  38. });
  39. properties[propertyId] = property;
  40. if (defined(property.semantic)) {
  41. propertiesBySemantic[property.semantic] = property;
  42. }
  43. }
  44. }
  45. this._properties = properties;
  46. this._propertiesBySemantic = propertiesBySemantic;
  47. this._id = id;
  48. this._name = classDefinition.name;
  49. this._description = classDefinition.description;
  50. this._extras = classDefinition.extras;
  51. this._extensions = classDefinition.extensions;
  52. }
  53. Object.defineProperties(MetadataClass.prototype, {
  54. /**
  55. * The class properties.
  56. *
  57. * @memberof MetadataClass.prototype
  58. * @type {Object.<String, MetadataClassProperty>}
  59. * @readonly
  60. * @private
  61. */
  62. properties: {
  63. get: function () {
  64. return this._properties;
  65. },
  66. },
  67. /**
  68. * A dictionary mapping semantics to class properties.
  69. *
  70. * @memberof MetadataClass.prototype
  71. * @type {Object.<String, MetadataClassProperty>}
  72. * @readonly
  73. *
  74. * @private
  75. */
  76. propertiesBySemantic: {
  77. get: function () {
  78. return this._propertiesBySemantic;
  79. },
  80. },
  81. /**
  82. * The ID of the class.
  83. *
  84. * @memberof MetadataClass.prototype
  85. * @type {String}
  86. * @readonly
  87. * @private
  88. */
  89. id: {
  90. get: function () {
  91. return this._id;
  92. },
  93. },
  94. /**
  95. * The name of the class.
  96. *
  97. * @memberof MetadataClass.prototype
  98. * @type {String}
  99. * @readonly
  100. * @private
  101. */
  102. name: {
  103. get: function () {
  104. return this._name;
  105. },
  106. },
  107. /**
  108. * The description of the class.
  109. *
  110. * @memberof MetadataClass.prototype
  111. * @type {String}
  112. * @readonly
  113. * @private
  114. */
  115. description: {
  116. get: function () {
  117. return this._description;
  118. },
  119. },
  120. /**
  121. * Extras in the JSON object.
  122. *
  123. * @memberof MetadataClass.prototype
  124. * @type {*}
  125. * @readonly
  126. * @private
  127. */
  128. extras: {
  129. get: function () {
  130. return this._extras;
  131. },
  132. },
  133. /**
  134. * Extensions in the JSON object.
  135. *
  136. * @memberof MetadataClass.prototype
  137. * @type {Object}
  138. * @readonly
  139. * @private
  140. */
  141. extensions: {
  142. get: function () {
  143. return this._extensions;
  144. },
  145. },
  146. });
  147. /**
  148. * The class name given to the metadata class when a batch
  149. * table is loaded from 3D Tiles 1.0 formats.
  150. *
  151. * @private
  152. */
  153. MetadataClass.BATCH_TABLE_CLASS_NAME = "_batchTable";
  154. export default MetadataClass;