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

GeometryUpdater.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import Check from "../Core/Check.js";
  2. import Color from "../Core/Color.js";
  3. import defined from "../Core/defined.js";
  4. import destroyObject from "../Core/destroyObject.js";
  5. import DeveloperError from "../Core/DeveloperError.js";
  6. import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
  7. import Event from "../Core/Event.js";
  8. import Iso8601 from "../Core/Iso8601.js";
  9. import oneTimeWarning from "../Core/oneTimeWarning.js";
  10. import ClassificationType from "../Scene/ClassificationType.js";
  11. import ShadowMode from "../Scene/ShadowMode.js";
  12. import ColorMaterialProperty from "./ColorMaterialProperty.js";
  13. import ConstantProperty from "./ConstantProperty.js";
  14. import Entity from "./Entity.js";
  15. import Property from "./Property.js";
  16. const defaultMaterial = new ColorMaterialProperty(Color.WHITE);
  17. const defaultShow = new ConstantProperty(true);
  18. const defaultFill = new ConstantProperty(true);
  19. const defaultOutline = new ConstantProperty(false);
  20. const defaultOutlineColor = new ConstantProperty(Color.BLACK);
  21. const defaultShadows = new ConstantProperty(ShadowMode.DISABLED);
  22. const defaultDistanceDisplayCondition = new ConstantProperty(
  23. new DistanceDisplayCondition(),
  24. );
  25. const defaultClassificationType = new ConstantProperty(ClassificationType.BOTH);
  26. /**
  27. * An abstract class for updating geometry entities.
  28. * @alias GeometryUpdater
  29. * @constructor
  30. *
  31. * @param {object} options An object with the following properties:
  32. * @param {Entity} options.entity The entity containing the geometry to be visualized.
  33. * @param {Scene} options.scene The scene where visualization is taking place.
  34. * @param {object} options.geometryOptions Options for the geometry
  35. * @param {string} options.geometryPropertyName The geometry property name
  36. * @param {string[]} options.observedPropertyNames The entity properties this geometry cares about
  37. */
  38. function GeometryUpdater(options) {
  39. //>>includeStart('debug', pragmas.debug);
  40. Check.defined("options.entity", options.entity);
  41. Check.defined("options.scene", options.scene);
  42. Check.defined("options.geometryOptions", options.geometryOptions);
  43. Check.defined("options.geometryPropertyName", options.geometryPropertyName);
  44. Check.defined("options.observedPropertyNames", options.observedPropertyNames);
  45. //>>includeEnd('debug');
  46. const entity = options.entity;
  47. const geometryPropertyName = options.geometryPropertyName;
  48. this._entity = entity;
  49. this._scene = options.scene;
  50. this._fillEnabled = false;
  51. this._isClosed = false;
  52. this._onTerrain = false;
  53. this._dynamic = false;
  54. this._outlineEnabled = false;
  55. this._geometryChanged = new Event();
  56. this._showProperty = undefined;
  57. this._materialProperty = undefined;
  58. this._showOutlineProperty = undefined;
  59. this._outlineColorProperty = undefined;
  60. this._outlineWidth = 1.0;
  61. this._shadowsProperty = undefined;
  62. this._distanceDisplayConditionProperty = undefined;
  63. this._classificationTypeProperty = undefined;
  64. this._options = options.geometryOptions;
  65. this._geometryPropertyName = geometryPropertyName;
  66. this._id = `${geometryPropertyName}-${entity.id}`;
  67. this._observedPropertyNames = options.observedPropertyNames;
  68. this._supportsMaterialsforEntitiesOnTerrain =
  69. Entity.supportsMaterialsforEntitiesOnTerrain(options.scene);
  70. }
  71. Object.defineProperties(GeometryUpdater.prototype, {
  72. /**
  73. * Gets the unique ID associated with this updater
  74. * @memberof GeometryUpdater.prototype
  75. * @type {string}
  76. * @readonly
  77. */
  78. id: {
  79. get: function () {
  80. return this._id;
  81. },
  82. },
  83. /**
  84. * Gets the entity associated with this geometry.
  85. * @memberof GeometryUpdater.prototype
  86. *
  87. * @type {Entity}
  88. * @readonly
  89. */
  90. entity: {
  91. get: function () {
  92. return this._entity;
  93. },
  94. },
  95. /**
  96. * Gets a value indicating if the geometry has a fill component.
  97. * @memberof GeometryUpdater.prototype
  98. *
  99. * @type {boolean}
  100. * @readonly
  101. */
  102. fillEnabled: {
  103. get: function () {
  104. return this._fillEnabled;
  105. },
  106. },
  107. /**
  108. * Gets a value indicating if fill visibility varies with simulation time.
  109. * @memberof GeometryUpdater.prototype
  110. *
  111. * @type {boolean}
  112. * @readonly
  113. */
  114. hasConstantFill: {
  115. get: function () {
  116. return (
  117. !this._fillEnabled ||
  118. (!defined(this._entity.availability) &&
  119. Property.isConstant(this._showProperty) &&
  120. Property.isConstant(this._fillProperty))
  121. );
  122. },
  123. },
  124. /**
  125. * Gets the material property used to fill the geometry.
  126. * @memberof GeometryUpdater.prototype
  127. *
  128. * @type {MaterialProperty}
  129. * @readonly
  130. */
  131. fillMaterialProperty: {
  132. get: function () {
  133. return this._materialProperty;
  134. },
  135. },
  136. /**
  137. * Gets a value indicating if the geometry has an outline component.
  138. * @memberof GeometryUpdater.prototype
  139. *
  140. * @type {boolean}
  141. * @readonly
  142. */
  143. outlineEnabled: {
  144. get: function () {
  145. return this._outlineEnabled;
  146. },
  147. },
  148. /**
  149. * Gets a value indicating if the geometry has an outline component.
  150. * @memberof GeometryUpdater.prototype
  151. *
  152. * @type {boolean}
  153. * @readonly
  154. */
  155. hasConstantOutline: {
  156. get: function () {
  157. return (
  158. !this._outlineEnabled ||
  159. (!defined(this._entity.availability) &&
  160. Property.isConstant(this._showProperty) &&
  161. Property.isConstant(this._showOutlineProperty))
  162. );
  163. },
  164. },
  165. /**
  166. * Gets the {@link Color} property for the geometry outline.
  167. * @memberof GeometryUpdater.prototype
  168. *
  169. * @type {Property}
  170. * @readonly
  171. */
  172. outlineColorProperty: {
  173. get: function () {
  174. return this._outlineColorProperty;
  175. },
  176. },
  177. /**
  178. * Gets the constant with of the geometry outline, in pixels.
  179. * This value is only valid if isDynamic is false.
  180. * @memberof GeometryUpdater.prototype
  181. *
  182. * @type {number}
  183. * @readonly
  184. */
  185. outlineWidth: {
  186. get: function () {
  187. return this._outlineWidth;
  188. },
  189. },
  190. /**
  191. * Gets the property specifying whether the geometry
  192. * casts or receives shadows from light sources.
  193. * @memberof GeometryUpdater.prototype
  194. *
  195. * @type {Property}
  196. * @readonly
  197. */
  198. shadowsProperty: {
  199. get: function () {
  200. return this._shadowsProperty;
  201. },
  202. },
  203. /**
  204. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this geometry will be displayed.
  205. * @memberof GeometryUpdater.prototype
  206. *
  207. * @type {Property}
  208. * @readonly
  209. */
  210. distanceDisplayConditionProperty: {
  211. get: function () {
  212. return this._distanceDisplayConditionProperty;
  213. },
  214. },
  215. /**
  216. * Gets or sets the {@link ClassificationType} Property specifying if this geometry will classify terrain, 3D Tiles, or both when on the ground.
  217. * @memberof GeometryUpdater.prototype
  218. *
  219. * @type {Property}
  220. * @readonly
  221. */
  222. classificationTypeProperty: {
  223. get: function () {
  224. return this._classificationTypeProperty;
  225. },
  226. },
  227. /**
  228. * Gets a value indicating if the geometry is time-varying.
  229. *
  230. * @memberof GeometryUpdater.prototype
  231. *
  232. * @type {boolean}
  233. * @readonly
  234. */
  235. isDynamic: {
  236. get: function () {
  237. return this._dynamic;
  238. },
  239. },
  240. /**
  241. * Gets a value indicating if the geometry is closed.
  242. * This property is only valid for static geometry.
  243. * @memberof GeometryUpdater.prototype
  244. *
  245. * @type {boolean}
  246. * @readonly
  247. */
  248. isClosed: {
  249. get: function () {
  250. return this._isClosed;
  251. },
  252. },
  253. /**
  254. * Gets a value indicating if the geometry should be drawn on terrain.
  255. * @memberof EllipseGeometryUpdater.prototype
  256. *
  257. * @type {boolean}
  258. * @readonly
  259. */
  260. onTerrain: {
  261. get: function () {
  262. return this._onTerrain;
  263. },
  264. },
  265. /**
  266. * Gets an event that is raised whenever the public properties
  267. * of this updater change.
  268. * @memberof GeometryUpdater.prototype
  269. *
  270. * @type {boolean}
  271. * @readonly
  272. */
  273. geometryChanged: {
  274. get: function () {
  275. return this._geometryChanged;
  276. },
  277. },
  278. });
  279. /**
  280. * Checks if the geometry is outlined at the provided time.
  281. *
  282. * @param {JulianDate} time The time for which to retrieve visibility.
  283. * @returns {boolean} true if geometry is outlined at the provided time, false otherwise.
  284. */
  285. GeometryUpdater.prototype.isOutlineVisible = function (time) {
  286. const entity = this._entity;
  287. const visible =
  288. this._outlineEnabled &&
  289. entity.isAvailable(time) &&
  290. this._showProperty.getValue(time) &&
  291. this._showOutlineProperty.getValue(time);
  292. return visible ?? false;
  293. };
  294. /**
  295. * Checks if the geometry is filled at the provided time.
  296. *
  297. * @param {JulianDate} time The time for which to retrieve visibility.
  298. * @returns {boolean} true if geometry is filled at the provided time, false otherwise.
  299. */
  300. GeometryUpdater.prototype.isFilled = function (time) {
  301. const entity = this._entity;
  302. const visible =
  303. this._fillEnabled &&
  304. entity.isAvailable(time) &&
  305. this._showProperty.getValue(time) &&
  306. this._fillProperty.getValue(time);
  307. return visible ?? false;
  308. };
  309. /**
  310. * Creates the geometry instance which represents the fill of the geometry.
  311. *
  312. * @function
  313. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  314. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  315. *
  316. * @exception {DeveloperError} This instance does not represent a filled geometry.
  317. */
  318. GeometryUpdater.prototype.createFillGeometryInstance =
  319. DeveloperError.throwInstantiationError;
  320. /**
  321. * Creates the geometry instance which represents the outline of the geometry.
  322. *
  323. * @function
  324. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  325. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  326. *
  327. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  328. */
  329. GeometryUpdater.prototype.createOutlineGeometryInstance =
  330. DeveloperError.throwInstantiationError;
  331. /**
  332. * Returns true if this object was destroyed; otherwise, false.
  333. *
  334. * @returns {boolean} True if this object was destroyed; otherwise, false.
  335. */
  336. GeometryUpdater.prototype.isDestroyed = function () {
  337. return false;
  338. };
  339. /**
  340. * Destroys and resources used by the object. Once an object is destroyed, it should not be used.
  341. *
  342. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  343. */
  344. GeometryUpdater.prototype.destroy = function () {
  345. destroyObject(this);
  346. };
  347. /**
  348. * @param {Entity} entity
  349. * @param {object} geometry
  350. * @private
  351. */
  352. GeometryUpdater.prototype._isHidden = function (entity, geometry) {
  353. const show = geometry.show;
  354. return (
  355. defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)
  356. );
  357. };
  358. /**
  359. * @param {Entity} entity
  360. * @param {object} geometry
  361. * @private
  362. */
  363. GeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {
  364. return false;
  365. };
  366. /**
  367. * @param {GeometryOptions} options
  368. * @private
  369. */
  370. GeometryUpdater.prototype._getIsClosed = function (options) {
  371. return true;
  372. };
  373. /**
  374. * @param {Entity} entity
  375. * @param {object} geometry
  376. * @private
  377. */
  378. GeometryUpdater.prototype._isDynamic = DeveloperError.throwInstantiationError;
  379. /**
  380. * @param {Entity} entity
  381. * @param {object} geometry
  382. * @private
  383. */
  384. GeometryUpdater.prototype._setStaticOptions =
  385. DeveloperError.throwInstantiationError;
  386. /**
  387. * @param {Entity} entity
  388. * @param {string} propertyName
  389. * @param {*} newValue
  390. * @param {*} oldValue
  391. * @private
  392. */
  393. GeometryUpdater.prototype._onEntityPropertyChanged = function (
  394. entity,
  395. propertyName,
  396. newValue,
  397. oldValue,
  398. ) {
  399. if (this._observedPropertyNames.indexOf(propertyName) === -1) {
  400. return;
  401. }
  402. const geometry = this._entity[this._geometryPropertyName];
  403. if (!defined(geometry)) {
  404. if (this._fillEnabled || this._outlineEnabled) {
  405. this._fillEnabled = false;
  406. this._outlineEnabled = false;
  407. this._geometryChanged.raiseEvent(this);
  408. }
  409. return;
  410. }
  411. const fillProperty = geometry.fill;
  412. const fillEnabled =
  413. defined(fillProperty) && fillProperty.isConstant
  414. ? fillProperty.getValue(Iso8601.MINIMUM_VALUE)
  415. : true;
  416. const outlineProperty = geometry.outline;
  417. let outlineEnabled = defined(outlineProperty);
  418. if (outlineEnabled && outlineProperty.isConstant) {
  419. outlineEnabled = outlineProperty.getValue(Iso8601.MINIMUM_VALUE);
  420. }
  421. if (!fillEnabled && !outlineEnabled) {
  422. if (this._fillEnabled || this._outlineEnabled) {
  423. this._fillEnabled = false;
  424. this._outlineEnabled = false;
  425. this._geometryChanged.raiseEvent(this);
  426. }
  427. return;
  428. }
  429. const show = geometry.show;
  430. if (this._isHidden(entity, geometry)) {
  431. if (this._fillEnabled || this._outlineEnabled) {
  432. this._fillEnabled = false;
  433. this._outlineEnabled = false;
  434. this._geometryChanged.raiseEvent(this);
  435. }
  436. return;
  437. }
  438. this._materialProperty = geometry.material ?? defaultMaterial;
  439. this._fillProperty = fillProperty ?? defaultFill;
  440. this._showProperty = show ?? defaultShow;
  441. this._showOutlineProperty = geometry.outline ?? defaultOutline;
  442. this._outlineColorProperty = outlineEnabled
  443. ? (geometry.outlineColor ?? defaultOutlineColor)
  444. : undefined;
  445. this._shadowsProperty = geometry.shadows ?? defaultShadows;
  446. this._distanceDisplayConditionProperty =
  447. geometry.distanceDisplayCondition ?? defaultDistanceDisplayCondition;
  448. this._classificationTypeProperty =
  449. geometry.classificationType ?? defaultClassificationType;
  450. this._fillEnabled = fillEnabled;
  451. const onTerrain =
  452. this._isOnTerrain(entity, geometry) &&
  453. (this._supportsMaterialsforEntitiesOnTerrain ||
  454. this._materialProperty instanceof ColorMaterialProperty);
  455. if (outlineEnabled && onTerrain) {
  456. oneTimeWarning(oneTimeWarning.geometryOutlines);
  457. outlineEnabled = false;
  458. }
  459. this._onTerrain = onTerrain;
  460. this._outlineEnabled = outlineEnabled;
  461. if (this._isDynamic(entity, geometry)) {
  462. if (!this._dynamic) {
  463. this._dynamic = true;
  464. this._geometryChanged.raiseEvent(this);
  465. }
  466. } else {
  467. this._setStaticOptions(entity, geometry);
  468. this._isClosed = this._getIsClosed(this._options);
  469. const outlineWidth = geometry.outlineWidth;
  470. this._outlineWidth = defined(outlineWidth)
  471. ? outlineWidth.getValue(Iso8601.MINIMUM_VALUE)
  472. : 1.0;
  473. this._dynamic = false;
  474. this._geometryChanged.raiseEvent(this);
  475. }
  476. };
  477. /**
  478. * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true.
  479. *
  480. * @param {PrimitiveCollection} primitives The primitive collection to use.
  481. * @param {PrimitiveCollection} [groundPrimitives] The primitive collection to use for ground primitives.
  482. *
  483. * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame.
  484. *
  485. * @exception {DeveloperError} This instance does not represent dynamic geometry.
  486. * @private
  487. */
  488. GeometryUpdater.prototype.createDynamicUpdater = function (
  489. primitives,
  490. groundPrimitives,
  491. ) {
  492. //>>includeStart('debug', pragmas.debug);
  493. Check.defined("primitives", primitives);
  494. Check.defined("groundPrimitives", groundPrimitives);
  495. if (!this._dynamic) {
  496. throw new DeveloperError(
  497. "This instance does not represent dynamic geometry.",
  498. );
  499. }
  500. //>>includeEnd('debug');
  501. return new this.constructor.DynamicGeometryUpdater(
  502. this,
  503. primitives,
  504. groundPrimitives,
  505. );
  506. };
  507. export default GeometryUpdater;