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

MetadataEnum.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import Check from "../Core/Check.js";
  2. import clone from "../Core/clone.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import MetadataEnumValue from "./MetadataEnumValue.js";
  5. import MetadataComponentType from "./MetadataComponentType.js";
  6. /**
  7. * A metadata enum.
  8. * <p>
  9. * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles
  10. * </p>
  11. *
  12. * @param {object} options Object with the following properties:
  13. * @param {string} options.id The ID of the enum.
  14. * @param {MetadataEnumValue[]} options.values The enum values.
  15. * @param {MetadataComponentType} [options.valueType=MetadataComponentType.UINT16] The enum value type.
  16. * @param {string} [options.name] The name of the enum.
  17. * @param {string} [options.description] The description of the enum.
  18. * @param {*} [options.extras] Extra user-defined properties.
  19. * @param {object} [options.extensions] An object containing extensions.
  20. *
  21. * @alias MetadataEnum
  22. * @constructor
  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 MetadataEnum(options) {
  26. options = options ?? Frozen.EMPTY_OBJECT;
  27. const id = options.id;
  28. const values = options.values;
  29. //>>includeStart('debug', pragmas.debug);
  30. Check.typeOf.string("options.id", id);
  31. Check.defined("options.values", values);
  32. //>>includeEnd('debug');
  33. const namesByValue = {};
  34. const valuesByName = {};
  35. const valuesLength = values.length;
  36. for (let i = 0; i < valuesLength; ++i) {
  37. const value = values[i];
  38. namesByValue[value.value] = value.name;
  39. valuesByName[value.name] = value.value;
  40. }
  41. const valueType = options.valueType ?? MetadataComponentType.UINT16;
  42. this._values = values;
  43. this._namesByValue = namesByValue;
  44. this._valuesByName = valuesByName;
  45. this._valueType = valueType;
  46. this._id = id;
  47. this._name = options.name;
  48. this._description = options.description;
  49. this._extras = clone(options.extras, true);
  50. this._extensions = clone(options.extensions, true);
  51. }
  52. /**
  53. * Creates a {@link MetadataEnum} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.
  54. *
  55. * @param {object} options Object with the following properties:
  56. * @param {string} options.id The ID of the enum.
  57. * @param {object} options.enum The enum JSON object.
  58. *
  59. * @returns {MetadataEnum} The newly created metadata enum.
  60. *
  61. * @private
  62. * @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.
  63. */
  64. MetadataEnum.fromJson = function (options) {
  65. options = options ?? Frozen.EMPTY_OBJECT;
  66. const id = options.id;
  67. const enumDefinition = options.enum;
  68. //>>includeStart('debug', pragmas.debug);
  69. Check.typeOf.string("options.id", id);
  70. Check.typeOf.object("options.enum", enumDefinition);
  71. //>>includeEnd('debug');
  72. const values = enumDefinition.values.map(function (value) {
  73. return MetadataEnumValue.fromJson(value);
  74. });
  75. return new MetadataEnum({
  76. id: id,
  77. values: values,
  78. valueType: MetadataComponentType[enumDefinition.valueType],
  79. name: enumDefinition.name,
  80. description: enumDefinition.description,
  81. extras: enumDefinition.extras,
  82. extensions: enumDefinition.extensions,
  83. });
  84. };
  85. Object.defineProperties(MetadataEnum.prototype, {
  86. /**
  87. * The enum values.
  88. *
  89. * @memberof MetadataEnum.prototype
  90. * @type {MetadataEnumValue[]}
  91. * @readonly
  92. */
  93. values: {
  94. get: function () {
  95. return this._values;
  96. },
  97. },
  98. /**
  99. * A dictionary mapping enum integer values to names.
  100. *
  101. * @memberof MetadataEnum.prototype
  102. * @type {Object<number, string>}
  103. * @readonly
  104. *
  105. * @private
  106. */
  107. namesByValue: {
  108. get: function () {
  109. return this._namesByValue;
  110. },
  111. },
  112. /**
  113. * A dictionary mapping enum names to integer values.
  114. *
  115. * @memberof MetadataEnum.prototype
  116. * @type {Object<string, number>}
  117. * @readonly
  118. *
  119. * @private
  120. */
  121. valuesByName: {
  122. get: function () {
  123. return this._valuesByName;
  124. },
  125. },
  126. /**
  127. * The enum value type.
  128. *
  129. * @memberof MetadataEnum.prototype
  130. * @type {MetadataComponentType}
  131. * @readonly
  132. */
  133. valueType: {
  134. get: function () {
  135. return this._valueType;
  136. },
  137. },
  138. /**
  139. * The ID of the enum.
  140. *
  141. * @memberof MetadataEnum.prototype
  142. * @type {string}
  143. * @readonly
  144. */
  145. id: {
  146. get: function () {
  147. return this._id;
  148. },
  149. },
  150. /**
  151. * The name of the enum.
  152. *
  153. * @memberof MetadataEnum.prototype
  154. * @type {string}
  155. * @readonly
  156. */
  157. name: {
  158. get: function () {
  159. return this._name;
  160. },
  161. },
  162. /**
  163. * The description of the enum.
  164. *
  165. * @memberof MetadataEnum.prototype
  166. * @type {string}
  167. * @readonly
  168. */
  169. description: {
  170. get: function () {
  171. return this._description;
  172. },
  173. },
  174. /**
  175. * Extra user-defined properties.
  176. *
  177. * @memberof MetadataEnum.prototype
  178. * @type {*}
  179. * @readonly
  180. */
  181. extras: {
  182. get: function () {
  183. return this._extras;
  184. },
  185. },
  186. /**
  187. * An object containing extensions.
  188. *
  189. * @memberof MetadataEnum.prototype
  190. * @type {object}
  191. * @readonly
  192. */
  193. extensions: {
  194. get: function () {
  195. return this._extensions;
  196. },
  197. },
  198. });
  199. export default MetadataEnum;