MetadataEnum.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import MetadataEnumValue from "./MetadataEnumValue.js";
  4. import MetadataComponentType from "./MetadataComponentType.js";
  5. /**
  6. * A metadata enum.
  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} options Object with the following properties:
  12. * @param {String} options.id The ID of the enum.
  13. * @param {Object} options.enum The enum JSON object.
  14. *
  15. * @alias MetadataEnum
  16. * @constructor
  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 MetadataEnum(options) {
  21. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22. const id = options.id;
  23. const enumDefinition = options.enum;
  24. //>>includeStart('debug', pragmas.debug);
  25. Check.typeOf.string("options.id", id);
  26. Check.typeOf.object("options.enum", enumDefinition);
  27. //>>includeEnd('debug');
  28. const namesByValue = {};
  29. const valuesByName = {};
  30. const values = enumDefinition.values.map(function (value) {
  31. namesByValue[value.value] = value.name;
  32. valuesByName[value.name] = value.value;
  33. return new MetadataEnumValue(value);
  34. });
  35. const valueType = defaultValue(
  36. MetadataComponentType[enumDefinition.valueType],
  37. MetadataComponentType.UINT16
  38. );
  39. this._values = values;
  40. this._namesByValue = namesByValue;
  41. this._valuesByName = valuesByName;
  42. this._valueType = valueType;
  43. this._id = id;
  44. this._name = enumDefinition.name;
  45. this._description = enumDefinition.description;
  46. this._extras = enumDefinition.extras;
  47. this._extensions = enumDefinition.extensions;
  48. }
  49. Object.defineProperties(MetadataEnum.prototype, {
  50. /**
  51. * The enum values.
  52. *
  53. * @memberof MetadataEnum.prototype
  54. * @type {MetadataEnumValue[]}
  55. * @readonly
  56. * @private
  57. */
  58. values: {
  59. get: function () {
  60. return this._values;
  61. },
  62. },
  63. /**
  64. * A dictionary mapping enum integer values to names.
  65. *
  66. * @memberof MetadataEnum.prototype
  67. * @type {Object.<Number, String>}
  68. * @readonly
  69. *
  70. * @private
  71. */
  72. namesByValue: {
  73. get: function () {
  74. return this._namesByValue;
  75. },
  76. },
  77. /**
  78. * A dictionary mapping enum names to integer values.
  79. *
  80. * @memberof MetadataEnum.prototype
  81. * @type {Object.<String, Number>}
  82. * @readonly
  83. *
  84. * @private
  85. */
  86. valuesByName: {
  87. get: function () {
  88. return this._valuesByName;
  89. },
  90. },
  91. /**
  92. * The enum value type.
  93. *
  94. * @memberof MetadataEnum.prototype
  95. * @type {MetadataComponentType}
  96. * @readonly
  97. *
  98. * @private
  99. */
  100. valueType: {
  101. get: function () {
  102. return this._valueType;
  103. },
  104. },
  105. /**
  106. * The ID of the enum.
  107. *
  108. * @memberof MetadataEnum.prototype
  109. * @type {String}
  110. * @readonly
  111. * @private
  112. */
  113. id: {
  114. get: function () {
  115. return this._id;
  116. },
  117. },
  118. /**
  119. * The name of the enum.
  120. *
  121. * @memberof MetadataEnum.prototype
  122. * @type {String}
  123. * @readonly
  124. * @private
  125. */
  126. name: {
  127. get: function () {
  128. return this._name;
  129. },
  130. },
  131. /**
  132. * The description of the enum.
  133. *
  134. * @memberof MetadataEnum.prototype
  135. * @type {String}
  136. * @readonly
  137. * @private
  138. */
  139. description: {
  140. get: function () {
  141. return this._description;
  142. },
  143. },
  144. /**
  145. * Extras in the JSON object.
  146. *
  147. * @memberof MetadataEnum.prototype
  148. * @type {*}
  149. * @readonly
  150. * @private
  151. */
  152. extras: {
  153. get: function () {
  154. return this._extras;
  155. },
  156. },
  157. /**
  158. * Extensions in the JSON object.
  159. *
  160. * @memberof MetadataEnum.prototype
  161. * @type {Object}
  162. * @readonly
  163. * @private
  164. */
  165. extensions: {
  166. get: function () {
  167. return this._extensions;
  168. },
  169. },
  170. });
  171. export default MetadataEnum;