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

GroundGeometryUpdater.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import GeometryOffsetAttribute from "../Core/GeometryOffsetAttribute.js";
  5. import oneTimeWarning from "../Core/oneTimeWarning.js";
  6. import GroundPrimitive from "../Scene/GroundPrimitive.js";
  7. import HeightReference, {
  8. isHeightReferenceClamp,
  9. } from "../Scene/HeightReference.js";
  10. import CallbackProperty from "./CallbackProperty.js";
  11. import ConstantProperty from "./ConstantProperty.js";
  12. import GeometryUpdater from "./GeometryUpdater.js";
  13. import TerrainOffsetProperty from "./TerrainOffsetProperty.js";
  14. const defaultZIndex = new ConstantProperty(0);
  15. /**
  16. * An abstract class for updating ground geometry entities.
  17. * @constructor
  18. * @alias GroundGeometryUpdater
  19. * @param {object} options An object with the following properties:
  20. * @param {Entity} options.entity The entity containing the geometry to be visualized.
  21. * @param {Scene} options.scene The scene where visualization is taking place.
  22. * @param {object} options.geometryOptions Options for the geometry
  23. * @param {string} options.geometryPropertyName The geometry property name
  24. * @param {string[]} options.observedPropertyNames The entity properties this geometry cares about
  25. */
  26. function GroundGeometryUpdater(options) {
  27. GeometryUpdater.call(this, options);
  28. this._zIndex = 0;
  29. this._terrainOffsetProperty = undefined;
  30. }
  31. if (defined(Object.create)) {
  32. GroundGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
  33. GroundGeometryUpdater.prototype.constructor = GroundGeometryUpdater;
  34. }
  35. Object.defineProperties(GroundGeometryUpdater.prototype, {
  36. /**
  37. * Gets the zindex
  38. * @type {number}
  39. * @memberof GroundGeometryUpdater.prototype
  40. * @readonly
  41. */
  42. zIndex: {
  43. get: function () {
  44. return this._zIndex;
  45. },
  46. },
  47. /**
  48. * Gets the terrain offset property
  49. * @type {TerrainOffsetProperty}
  50. * @memberof GroundGeometryUpdater.prototype
  51. * @readonly
  52. * @private
  53. */
  54. terrainOffsetProperty: {
  55. get: function () {
  56. return this._terrainOffsetProperty;
  57. },
  58. },
  59. });
  60. GroundGeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {
  61. return (
  62. this._fillEnabled &&
  63. !defined(geometry.height) &&
  64. !defined(geometry.extrudedHeight) &&
  65. GroundPrimitive.isSupported(this._scene)
  66. );
  67. };
  68. GroundGeometryUpdater.prototype._getIsClosed = function (options) {
  69. const height = options.height;
  70. const extrudedHeight = options.extrudedHeight;
  71. return height === 0 || (defined(extrudedHeight) && extrudedHeight !== height);
  72. };
  73. GroundGeometryUpdater.prototype._computeCenter =
  74. DeveloperError.throwInstantiationError;
  75. GroundGeometryUpdater.prototype._onEntityPropertyChanged = function (
  76. entity,
  77. propertyName,
  78. newValue,
  79. oldValue,
  80. ) {
  81. GeometryUpdater.prototype._onEntityPropertyChanged.call(
  82. this,
  83. entity,
  84. propertyName,
  85. newValue,
  86. oldValue,
  87. );
  88. if (this._observedPropertyNames.indexOf(propertyName) === -1) {
  89. return;
  90. }
  91. const geometry = this._entity[this._geometryPropertyName];
  92. if (!defined(geometry)) {
  93. return;
  94. }
  95. if (
  96. defined(geometry.zIndex) &&
  97. (defined(geometry.height) || defined(geometry.extrudedHeight))
  98. ) {
  99. oneTimeWarning(oneTimeWarning.geometryZIndex);
  100. }
  101. this._zIndex = geometry.zIndex ?? defaultZIndex;
  102. if (defined(this._terrainOffsetProperty)) {
  103. this._terrainOffsetProperty.destroy();
  104. this._terrainOffsetProperty = undefined;
  105. }
  106. const heightReferenceProperty = geometry.heightReference;
  107. const extrudedHeightReferenceProperty = geometry.extrudedHeightReference;
  108. if (
  109. defined(heightReferenceProperty) ||
  110. defined(extrudedHeightReferenceProperty)
  111. ) {
  112. const centerPosition = new CallbackProperty(
  113. this._computeCenter.bind(this),
  114. !this._dynamic,
  115. );
  116. this._terrainOffsetProperty = new TerrainOffsetProperty(
  117. this._scene,
  118. centerPosition,
  119. heightReferenceProperty,
  120. extrudedHeightReferenceProperty,
  121. );
  122. }
  123. };
  124. /**
  125. * Destroys and resources used by the object. Once an object is destroyed, it should not be used.
  126. *
  127. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  128. */
  129. GroundGeometryUpdater.prototype.destroy = function () {
  130. if (defined(this._terrainOffsetProperty)) {
  131. this._terrainOffsetProperty.destroy();
  132. this._terrainOffsetProperty = undefined;
  133. }
  134. GeometryUpdater.prototype.destroy.call(this);
  135. };
  136. /**
  137. * @private
  138. */
  139. GroundGeometryUpdater.getGeometryHeight = function (height, heightReference) {
  140. //>>includeStart('debug', pragmas.debug);
  141. Check.defined("heightReference", heightReference);
  142. //>>includeEnd('debug');
  143. if (!defined(height)) {
  144. if (heightReference !== HeightReference.NONE) {
  145. oneTimeWarning(oneTimeWarning.geometryHeightReference);
  146. }
  147. return;
  148. }
  149. if (!isHeightReferenceClamp(heightReference)) {
  150. return height;
  151. }
  152. return 0.0;
  153. };
  154. /**
  155. * @private
  156. */
  157. GroundGeometryUpdater.getGeometryExtrudedHeight = function (
  158. extrudedHeight,
  159. extrudedHeightReference,
  160. ) {
  161. //>>includeStart('debug', pragmas.debug);
  162. Check.defined("extrudedHeightReference", extrudedHeightReference);
  163. //>>includeEnd('debug');
  164. if (!defined(extrudedHeight)) {
  165. if (extrudedHeightReference !== HeightReference.NONE) {
  166. oneTimeWarning(oneTimeWarning.geometryExtrudedHeightReference);
  167. }
  168. return;
  169. }
  170. if (!isHeightReferenceClamp(extrudedHeightReference)) {
  171. return extrudedHeight;
  172. }
  173. return GroundGeometryUpdater.CLAMP_TO_GROUND;
  174. };
  175. /**
  176. * @private
  177. */
  178. GroundGeometryUpdater.CLAMP_TO_GROUND = "clamp";
  179. /**
  180. * @private
  181. */
  182. GroundGeometryUpdater.computeGeometryOffsetAttribute = function (
  183. height,
  184. heightReference,
  185. extrudedHeight,
  186. extrudedHeightReference,
  187. ) {
  188. if (!defined(height) || !defined(heightReference)) {
  189. heightReference = HeightReference.NONE;
  190. }
  191. if (!defined(extrudedHeight) || !defined(extrudedHeightReference)) {
  192. extrudedHeightReference = HeightReference.NONE;
  193. }
  194. let n = 0;
  195. if (heightReference !== HeightReference.NONE) {
  196. n++;
  197. }
  198. if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) {
  199. n++;
  200. }
  201. if (n === 2) {
  202. return GeometryOffsetAttribute.ALL;
  203. }
  204. if (n === 1) {
  205. return GeometryOffsetAttribute.TOP;
  206. }
  207. return undefined;
  208. };
  209. export default GroundGeometryUpdater;