Cesium3DTilesetMetadata.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import GroupMetadata from "./GroupMetadata.js";
  5. import TilesetMetadata from "./TilesetMetadata.js";
  6. /**
  7. * An object containing metadata about a 3D Tileset.
  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. * <p>
  12. * This object represents the tileset JSON (3D Tiles 1.1) or the <code>3DTILES_metadata</code> object that contains
  13. * the schema ({@link MetadataSchema}), tileset metadata ({@link TilesetMetadata}), group metadata (dictionary of {@link GroupMetadata}), and metadata statistics (dictionary)
  14. * </p>
  15. *
  16. * @param {Object} options Object with the following properties:
  17. * @param {Object} options.metadataJson Either the tileset JSON (3D Tiles 1.1) or the <code>3DTILES_metadata</code> extension object that contains the tileset metadata.
  18. * @param {MetadataSchema} options.schema The parsed schema.
  19. *
  20. * @alias Cesium3DTilesetMetadata
  21. * @constructor
  22. * @private
  23. * @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.
  24. */
  25. function Cesium3DTilesetMetadata(options) {
  26. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  27. const metadataJson = options.metadataJson;
  28. // The calling code is responsible for loading the schema.
  29. // This keeps metadata parsing synchronous.
  30. const schema = options.schema;
  31. //>>includeStart('debug', pragmas.debug);
  32. Check.typeOf.object("options.metadataJson", metadataJson);
  33. Check.typeOf.object("options.schema", schema);
  34. //>>includeEnd('debug');
  35. // An older schema stored the tileset metadata in the "tileset" property.
  36. const metadata = defaultValue(metadataJson.metadata, metadataJson.tileset);
  37. let tileset;
  38. if (defined(metadata)) {
  39. tileset = new TilesetMetadata({
  40. tileset: metadata,
  41. class: schema.classes[metadata.class],
  42. });
  43. }
  44. let groupIds = [];
  45. const groups = [];
  46. const groupsJson = metadataJson.groups;
  47. if (Array.isArray(groupsJson)) {
  48. const length = groupsJson.length;
  49. for (let i = 0; i < length; i++) {
  50. const group = groupsJson[i];
  51. groups.push(
  52. new GroupMetadata({
  53. group: group,
  54. class: schema.classes[group.class],
  55. })
  56. );
  57. }
  58. } else if (defined(groupsJson)) {
  59. // An older version of group metadata stored groups in a dictionary
  60. // instead of an array.
  61. groupIds = Object.keys(groupsJson).sort();
  62. const length = groupIds.length;
  63. for (let i = 0; i < length; i++) {
  64. const groupId = groupIds[i];
  65. if (groupsJson.hasOwnProperty(groupId)) {
  66. const group = groupsJson[groupId];
  67. groups.push(
  68. new GroupMetadata({
  69. id: groupId,
  70. group: groupsJson[groupId],
  71. class: schema.classes[group.class],
  72. })
  73. );
  74. }
  75. }
  76. }
  77. this._schema = schema;
  78. this._groups = groups;
  79. this._groupIds = groupIds;
  80. this._tileset = tileset;
  81. this._statistics = metadataJson.statistics;
  82. this._extras = metadataJson.extras;
  83. this._extensions = metadataJson.extensions;
  84. }
  85. Object.defineProperties(Cesium3DTilesetMetadata.prototype, {
  86. /**
  87. * Schema containing classes and enums.
  88. *
  89. * @memberof Cesium3DTilesetMetadata.prototype
  90. * @type {MetadataSchema}
  91. * @readonly
  92. * @private
  93. */
  94. schema: {
  95. get: function () {
  96. return this._schema;
  97. },
  98. },
  99. /**
  100. * Metadata about groups of content.
  101. *
  102. * @memberof Cesium3DTilesetMetadata.prototype
  103. * @type {GroupMetadata[]}
  104. * @readonly
  105. * @private
  106. */
  107. groups: {
  108. get: function () {
  109. return this._groups;
  110. },
  111. },
  112. /**
  113. * The IDs of the group metadata in the corresponding groups dictionary.
  114. * Only populated if using the legacy schema.
  115. *
  116. * @memberof Cesium3DTilesetMetadata.prototype
  117. * @type {String[]}
  118. * @readonly
  119. * @private
  120. */
  121. groupIds: {
  122. get: function () {
  123. return this._groupIds;
  124. },
  125. },
  126. /**
  127. * Metadata about the tileset as a whole.
  128. *
  129. * @memberof Cesium3DTilesetMetadata.prototype
  130. * @type {TilesetMetadata}
  131. * @readonly
  132. * @private
  133. */
  134. tileset: {
  135. get: function () {
  136. return this._tileset;
  137. },
  138. },
  139. /**
  140. * Statistics about the metadata.
  141. * <p>
  142. * See the {@link https://github.com/CesiumGS/3d-tiles/blob/main/extensions/3DTILES_metadata/schema/statistics.schema.json|statistics schema reference}
  143. * in the 3D Tiles spec for the full set of properties.
  144. * </p>
  145. *
  146. * @memberof Cesium3DTilesetMetadata.prototype
  147. * @type {Object}
  148. * @readonly
  149. * @private
  150. */
  151. statistics: {
  152. get: function () {
  153. return this._statistics;
  154. },
  155. },
  156. /**
  157. * Extras in the JSON object.
  158. *
  159. * @memberof Cesium3DTilesetMetadata.prototype
  160. * @type {*}
  161. * @readonly
  162. * @private
  163. */
  164. extras: {
  165. get: function () {
  166. return this._extras;
  167. },
  168. },
  169. /**
  170. * Extensions in the JSON object.
  171. *
  172. * @memberof Cesium3DTilesetMetadata.prototype
  173. * @type {Object}
  174. * @readonly
  175. * @private
  176. */
  177. extensions: {
  178. get: function () {
  179. return this._extensions;
  180. },
  181. },
  182. });
  183. export default Cesium3DTilesetMetadata;