ShowGeometryInstanceAttribute.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import ComponentDatatype from './ComponentDatatype.js';
  2. import defaultValue from './defaultValue.js';
  3. import defined from './defined.js';
  4. import defineProperties from './defineProperties.js';
  5. import DeveloperError from './DeveloperError.js';
  6. /**
  7. * Value and type information for per-instance geometry attribute that determines if the geometry instance will be shown.
  8. *
  9. * @alias ShowGeometryInstanceAttribute
  10. * @constructor
  11. *
  12. * @param {Boolean} [show=true] Determines if the geometry instance will be shown.
  13. *
  14. *
  15. * @example
  16. * var instance = new Cesium.GeometryInstance({
  17. * geometry : new Cesium.BoxGeometry({
  18. * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
  19. * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),
  20. * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)
  21. * }),
  22. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  23. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  24. * id : 'box',
  25. * attributes : {
  26. * show : new Cesium.ShowGeometryInstanceAttribute(false)
  27. * }
  28. * });
  29. *
  30. * @see GeometryInstance
  31. * @see GeometryInstanceAttribute
  32. */
  33. function ShowGeometryInstanceAttribute(show) {
  34. show = defaultValue(show, true);
  35. /**
  36. * The values for the attributes stored in a typed array.
  37. *
  38. * @type Uint8Array
  39. *
  40. * @default [1.0]
  41. */
  42. this.value = ShowGeometryInstanceAttribute.toValue(show);
  43. }
  44. defineProperties(ShowGeometryInstanceAttribute.prototype, {
  45. /**
  46. * The datatype of each component in the attribute, e.g., individual elements in
  47. * {@link ColorGeometryInstanceAttribute#value}.
  48. *
  49. * @memberof ShowGeometryInstanceAttribute.prototype
  50. *
  51. * @type {ComponentDatatype}
  52. * @readonly
  53. *
  54. * @default {@link ComponentDatatype.UNSIGNED_BYTE}
  55. */
  56. componentDatatype : {
  57. get : function() {
  58. return ComponentDatatype.UNSIGNED_BYTE;
  59. }
  60. },
  61. /**
  62. * The number of components in the attributes, i.e., {@link ColorGeometryInstanceAttribute#value}.
  63. *
  64. * @memberof ShowGeometryInstanceAttribute.prototype
  65. *
  66. * @type {Number}
  67. * @readonly
  68. *
  69. * @default 1
  70. */
  71. componentsPerAttribute : {
  72. get : function() {
  73. return 1;
  74. }
  75. },
  76. /**
  77. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  78. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  79. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  80. *
  81. * @memberof ShowGeometryInstanceAttribute.prototype
  82. *
  83. * @type {Boolean}
  84. * @readonly
  85. *
  86. * @default true
  87. */
  88. normalize : {
  89. get : function() {
  90. return false;
  91. }
  92. }
  93. });
  94. /**
  95. * Converts a boolean show to a typed array that can be used to assign a show attribute.
  96. *
  97. * @param {Boolean} show The show value.
  98. * @param {Uint8Array} [result] The array to store the result in, if undefined a new instance will be created.
  99. * @returns {Uint8Array} The modified result parameter or a new instance if result was undefined.
  100. *
  101. * @example
  102. * var attributes = primitive.getGeometryInstanceAttributes('an id');
  103. * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true, attributes.show);
  104. */
  105. ShowGeometryInstanceAttribute.toValue = function(show, result) {
  106. //>>includeStart('debug', pragmas.debug);
  107. if (!defined(show)) {
  108. throw new DeveloperError('show is required.');
  109. }
  110. //>>includeEnd('debug');
  111. if (!defined(result)) {
  112. return new Uint8Array([show]);
  113. }
  114. result[0] = show;
  115. return result;
  116. };
  117. export default ShowGeometryInstanceAttribute;