PropertyAttribute.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import PropertyAttributeProperty from "./PropertyAttributeProperty.js";
  5. /**
  6. * A property attribute; a collection of per-point properties stored as custom
  7. * vertex attributes.
  8. * <p>
  9. * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension}
  10. * </p>
  11. *
  12. * @param {object} options Object with the following properties:
  13. * @param {string} [options.name] Optional human-readable name to describe the attribute
  14. * @param {number} [options.id] A unique id to identify the property attribute, useful for debugging. This is the array index in the property attributes array
  15. * @param {object} options.propertyAttribute The property attribute JSON, following the EXT_structural_metadata schema.
  16. * @param {MetadataClass} options.class The class that properties conform to.
  17. *
  18. * @alias PropertyAttribute
  19. * @constructor
  20. *
  21. * @private
  22. * @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.
  23. */
  24. function PropertyAttribute(options) {
  25. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  26. const propertyAttribute = options.propertyAttribute;
  27. const classDefinition = options.class;
  28. //>>includeStart('debug', pragmas.debug);
  29. Check.typeOf.object("options.propertyAttribute", propertyAttribute);
  30. Check.typeOf.object("options.class", classDefinition);
  31. //>>includeEnd('debug');
  32. const properties = {};
  33. if (defined(propertyAttribute.properties)) {
  34. for (const propertyId in propertyAttribute.properties) {
  35. if (propertyAttribute.properties.hasOwnProperty(propertyId)) {
  36. properties[propertyId] = new PropertyAttributeProperty({
  37. property: propertyAttribute.properties[propertyId],
  38. classProperty: classDefinition.properties[propertyId],
  39. });
  40. }
  41. }
  42. }
  43. this._name = options.name;
  44. this._id = options.id;
  45. this._class = classDefinition;
  46. this._properties = properties;
  47. this._extras = propertyAttribute.extras;
  48. this._extensions = propertyAttribute.extensions;
  49. }
  50. Object.defineProperties(PropertyAttribute.prototype, {
  51. /**
  52. * A human-readable name for this attribute
  53. *
  54. * @memberof PropertyAttribute.prototype
  55. *
  56. * @type {string}
  57. * @readonly
  58. * @private
  59. */
  60. name: {
  61. get: function () {
  62. return this._name;
  63. },
  64. },
  65. /**
  66. * An identifier for this attribute. Useful for debugging.
  67. *
  68. * @memberof PropertyAttribute.prototype
  69. *
  70. * @type {string|number}
  71. * @readonly
  72. * @private
  73. */
  74. id: {
  75. get: function () {
  76. return this._id;
  77. },
  78. },
  79. /**
  80. * The class that properties conform to.
  81. *
  82. * @memberof PropertyAttribute.prototype
  83. *
  84. * @type {MetadataClass}
  85. * @readonly
  86. * @private
  87. */
  88. class: {
  89. get: function () {
  90. return this._class;
  91. },
  92. },
  93. /**
  94. * The properties in this property attribute.
  95. *
  96. * @memberof PropertyAttribute.prototype
  97. *
  98. * @type {Object<string, PropertyAttributeProperty>}
  99. * @readonly
  100. * @private
  101. */
  102. properties: {
  103. get: function () {
  104. return this._properties;
  105. },
  106. },
  107. /**
  108. * Extra user-defined properties.
  109. *
  110. * @memberof PropertyAttribute.prototype
  111. *
  112. * @type {*}
  113. * @readonly
  114. * @private
  115. */
  116. extras: {
  117. get: function () {
  118. return this._extras;
  119. },
  120. },
  121. /**
  122. * An object containing extensions.
  123. *
  124. * @memberof PropertyAttribute.prototype
  125. *
  126. * @type {object}
  127. * @readonly
  128. * @private
  129. */
  130. extensions: {
  131. get: function () {
  132. return this._extensions;
  133. },
  134. },
  135. });
  136. /**
  137. * Gets the property with the given property ID.
  138. *
  139. * @param {string} propertyId The case-sensitive ID of the property.
  140. * @returns {PropertyAttributeProperty|undefined} The property, or <code>undefined</code> if the property does not exist.
  141. * @private
  142. */
  143. PropertyAttribute.prototype.getProperty = function (propertyId) {
  144. //>>includeStart('debug', pragmas.debug);
  145. Check.typeOf.string("propertyId", propertyId);
  146. //>>includeEnd('debug');
  147. return this._properties[propertyId];
  148. };
  149. export default PropertyAttribute;