MetadataSchema.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import MetadataClass from "./MetadataClass.js";
  4. import MetadataEnum from "./MetadataEnum.js";
  5. /**
  6. * A schema containing classes and enums.
  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} schema The schema JSON object.
  12. *
  13. * @alias MetadataSchema
  14. * @constructor
  15. * @private
  16. * @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.
  17. */
  18. function MetadataSchema(schema) {
  19. //>>includeStart('debug', pragmas.debug);
  20. Check.typeOf.object("schema", schema);
  21. //>>includeEnd('debug');
  22. const enums = {};
  23. if (defined(schema.enums)) {
  24. for (const enumId in schema.enums) {
  25. if (schema.enums.hasOwnProperty(enumId)) {
  26. enums[enumId] = new MetadataEnum({
  27. id: enumId,
  28. enum: schema.enums[enumId],
  29. });
  30. }
  31. }
  32. }
  33. const classes = {};
  34. if (defined(schema.classes)) {
  35. for (const classId in schema.classes) {
  36. if (schema.classes.hasOwnProperty(classId)) {
  37. classes[classId] = new MetadataClass({
  38. id: classId,
  39. class: schema.classes[classId],
  40. enums: enums,
  41. });
  42. }
  43. }
  44. }
  45. this._classes = classes;
  46. this._enums = enums;
  47. this._id = schema.id;
  48. this._name = schema.name;
  49. this._description = schema.description;
  50. this._version = schema.version;
  51. this._extras = schema.extras;
  52. this._extensions = schema.extensions;
  53. }
  54. Object.defineProperties(MetadataSchema.prototype, {
  55. /**
  56. * Classes defined in the schema.
  57. *
  58. * @memberof MetadataSchema.prototype
  59. * @type {Object.<String, MetadataClass>}
  60. * @readonly
  61. * @private
  62. */
  63. classes: {
  64. get: function () {
  65. return this._classes;
  66. },
  67. },
  68. /**
  69. * Enums defined in the schema.
  70. *
  71. * @memberof MetadataSchema.prototype
  72. * @type {Object.<String, MetadataEnum>}
  73. * @readonly
  74. * @private
  75. */
  76. enums: {
  77. get: function () {
  78. return this._enums;
  79. },
  80. },
  81. /**
  82. * The ID of the schema.
  83. *
  84. * @memberof MetadataSchema.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 schema.
  96. *
  97. * @memberof MetadataSchema.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 schema.
  109. *
  110. * @memberof MetadataSchema.prototype
  111. * @type {String}
  112. * @readonly
  113. * @private
  114. */
  115. description: {
  116. get: function () {
  117. return this._description;
  118. },
  119. },
  120. /**
  121. * The application-specific version of the schema.
  122. *
  123. * @memberof MetadataSchema.prototype
  124. * @type {String}
  125. * @readonly
  126. * @private
  127. */
  128. version: {
  129. get: function () {
  130. return this._version;
  131. },
  132. },
  133. /**
  134. * Extras in the JSON object.
  135. *
  136. * @memberof MetadataSchema.prototype
  137. * @type {*}
  138. * @readonly
  139. * @private
  140. */
  141. extras: {
  142. get: function () {
  143. return this._extras;
  144. },
  145. },
  146. /**
  147. * Extensions in the JSON object.
  148. *
  149. * @memberof MetadataSchema.prototype
  150. * @type {Object}
  151. * @readonly
  152. * @private
  153. */
  154. extensions: {
  155. get: function () {
  156. return this._extensions;
  157. },
  158. },
  159. });
  160. export default MetadataSchema;