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

PolylineVolumeGeometryUpdater.js 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import Check from "../Core/Check.js";
  2. import Color from "../Core/Color.js";
  3. import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
  4. import defined from "../Core/defined.js";
  5. import DeveloperError from "../Core/DeveloperError.js";
  6. import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js";
  7. import GeometryInstance from "../Core/GeometryInstance.js";
  8. import Iso8601 from "../Core/Iso8601.js";
  9. import PolylineVolumeGeometry from "../Core/PolylineVolumeGeometry.js";
  10. import PolylineVolumeOutlineGeometry from "../Core/PolylineVolumeOutlineGeometry.js";
  11. import ShowGeometryInstanceAttribute from "../Core/ShowGeometryInstanceAttribute.js";
  12. import MaterialAppearance from "../Scene/MaterialAppearance.js";
  13. import PerInstanceColorAppearance from "../Scene/PerInstanceColorAppearance.js";
  14. import ColorMaterialProperty from "./ColorMaterialProperty.js";
  15. import DynamicGeometryUpdater from "./DynamicGeometryUpdater.js";
  16. import GeometryUpdater from "./GeometryUpdater.js";
  17. import Property from "./Property.js";
  18. const scratchColor = new Color();
  19. function PolylineVolumeGeometryOptions(entity) {
  20. this.id = entity;
  21. this.vertexFormat = undefined;
  22. this.polylinePositions = undefined;
  23. this.shapePositions = undefined;
  24. this.cornerType = undefined;
  25. this.granularity = undefined;
  26. }
  27. /**
  28. * A {@link GeometryUpdater} for polyline volumes.
  29. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  30. * @alias PolylineVolumeGeometryUpdater
  31. * @constructor
  32. *
  33. * @param {Entity} entity The entity containing the geometry to be visualized.
  34. * @param {Scene} scene The scene where visualization is taking place.
  35. */
  36. function PolylineVolumeGeometryUpdater(entity, scene) {
  37. GeometryUpdater.call(this, {
  38. entity: entity,
  39. scene: scene,
  40. geometryOptions: new PolylineVolumeGeometryOptions(entity),
  41. geometryPropertyName: "polylineVolume",
  42. observedPropertyNames: ["availability", "polylineVolume"],
  43. });
  44. this._onEntityPropertyChanged(
  45. entity,
  46. "polylineVolume",
  47. entity.polylineVolume,
  48. undefined,
  49. );
  50. }
  51. if (defined(Object.create)) {
  52. PolylineVolumeGeometryUpdater.prototype = Object.create(
  53. GeometryUpdater.prototype,
  54. );
  55. PolylineVolumeGeometryUpdater.prototype.constructor =
  56. PolylineVolumeGeometryUpdater;
  57. }
  58. /**
  59. * Creates the geometry instance which represents the fill of the geometry.
  60. *
  61. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  62. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  63. *
  64. * @exception {DeveloperError} This instance does not represent a filled geometry.
  65. */
  66. PolylineVolumeGeometryUpdater.prototype.createFillGeometryInstance = function (
  67. time,
  68. ) {
  69. //>>includeStart('debug', pragmas.debug);
  70. Check.defined("time", time);
  71. if (!this._fillEnabled) {
  72. throw new DeveloperError(
  73. "This instance does not represent a filled geometry.",
  74. );
  75. }
  76. //>>includeEnd('debug');
  77. const entity = this._entity;
  78. const isAvailable = entity.isAvailable(time);
  79. let attributes;
  80. let color;
  81. const show = new ShowGeometryInstanceAttribute(
  82. isAvailable &&
  83. entity.isShowing &&
  84. this._showProperty.getValue(time) &&
  85. this._fillProperty.getValue(time),
  86. );
  87. const distanceDisplayCondition =
  88. this._distanceDisplayConditionProperty.getValue(time);
  89. const distanceDisplayConditionAttribute =
  90. DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  91. distanceDisplayCondition,
  92. );
  93. if (this._materialProperty instanceof ColorMaterialProperty) {
  94. let currentColor;
  95. if (
  96. defined(this._materialProperty.color) &&
  97. (this._materialProperty.color.isConstant || isAvailable)
  98. ) {
  99. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  100. }
  101. if (!defined(currentColor)) {
  102. currentColor = Color.WHITE;
  103. }
  104. color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  105. attributes = {
  106. show: show,
  107. distanceDisplayCondition: distanceDisplayConditionAttribute,
  108. color: color,
  109. };
  110. } else {
  111. attributes = {
  112. show: show,
  113. distanceDisplayCondition: distanceDisplayConditionAttribute,
  114. };
  115. }
  116. return new GeometryInstance({
  117. id: entity,
  118. geometry: new PolylineVolumeGeometry(this._options),
  119. attributes: attributes,
  120. });
  121. };
  122. /**
  123. * Creates the geometry instance which represents the outline of the geometry.
  124. *
  125. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  126. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  127. *
  128. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  129. */
  130. PolylineVolumeGeometryUpdater.prototype.createOutlineGeometryInstance =
  131. function (time) {
  132. //>>includeStart('debug', pragmas.debug);
  133. Check.defined("time", time);
  134. if (!this._outlineEnabled) {
  135. throw new DeveloperError(
  136. "This instance does not represent an outlined geometry.",
  137. );
  138. }
  139. //>>includeEnd('debug');
  140. const entity = this._entity;
  141. const isAvailable = entity.isAvailable(time);
  142. const outlineColor = Property.getValueOrDefault(
  143. this._outlineColorProperty,
  144. time,
  145. Color.BLACK,
  146. scratchColor,
  147. );
  148. const distanceDisplayCondition =
  149. this._distanceDisplayConditionProperty.getValue(time);
  150. return new GeometryInstance({
  151. id: entity,
  152. geometry: new PolylineVolumeOutlineGeometry(this._options),
  153. attributes: {
  154. show: new ShowGeometryInstanceAttribute(
  155. isAvailable &&
  156. entity.isShowing &&
  157. this._showProperty.getValue(time) &&
  158. this._showOutlineProperty.getValue(time),
  159. ),
  160. color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
  161. distanceDisplayCondition:
  162. DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  163. distanceDisplayCondition,
  164. ),
  165. },
  166. });
  167. };
  168. PolylineVolumeGeometryUpdater.prototype._isHidden = function (
  169. entity,
  170. polylineVolume,
  171. ) {
  172. return (
  173. !defined(polylineVolume.positions) ||
  174. !defined(polylineVolume.shape) ||
  175. GeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume)
  176. );
  177. };
  178. PolylineVolumeGeometryUpdater.prototype._isDynamic = function (
  179. entity,
  180. polylineVolume,
  181. ) {
  182. return (
  183. !polylineVolume.positions.isConstant || //
  184. !polylineVolume.shape.isConstant || //
  185. !Property.isConstant(polylineVolume.granularity) || //
  186. !Property.isConstant(polylineVolume.outlineWidth) || //
  187. !Property.isConstant(polylineVolume.cornerType)
  188. );
  189. };
  190. PolylineVolumeGeometryUpdater.prototype._setStaticOptions = function (
  191. entity,
  192. polylineVolume,
  193. ) {
  194. const granularity = polylineVolume.granularity;
  195. const cornerType = polylineVolume.cornerType;
  196. const options = this._options;
  197. const isColorMaterial =
  198. this._materialProperty instanceof ColorMaterialProperty;
  199. options.vertexFormat = isColorMaterial
  200. ? PerInstanceColorAppearance.VERTEX_FORMAT
  201. : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  202. options.polylinePositions = polylineVolume.positions.getValue(
  203. Iso8601.MINIMUM_VALUE,
  204. options.polylinePositions,
  205. );
  206. options.shapePositions = polylineVolume.shape.getValue(
  207. Iso8601.MINIMUM_VALUE,
  208. options.shape,
  209. );
  210. options.granularity = defined(granularity)
  211. ? granularity.getValue(Iso8601.MINIMUM_VALUE)
  212. : undefined;
  213. options.cornerType = defined(cornerType)
  214. ? cornerType.getValue(Iso8601.MINIMUM_VALUE)
  215. : undefined;
  216. };
  217. PolylineVolumeGeometryUpdater.DynamicGeometryUpdater =
  218. DynamicPolylineVolumeGeometryUpdater;
  219. /**
  220. * @private
  221. */
  222. function DynamicPolylineVolumeGeometryUpdater(
  223. geometryUpdater,
  224. primitives,
  225. groundPrimitives,
  226. ) {
  227. DynamicGeometryUpdater.call(
  228. this,
  229. geometryUpdater,
  230. primitives,
  231. groundPrimitives,
  232. );
  233. }
  234. if (defined(Object.create)) {
  235. DynamicPolylineVolumeGeometryUpdater.prototype = Object.create(
  236. DynamicGeometryUpdater.prototype,
  237. );
  238. DynamicPolylineVolumeGeometryUpdater.prototype.constructor =
  239. DynamicPolylineVolumeGeometryUpdater;
  240. }
  241. DynamicPolylineVolumeGeometryUpdater.prototype._isHidden = function (
  242. entity,
  243. polylineVolume,
  244. time,
  245. ) {
  246. const options = this._options;
  247. return (
  248. !defined(options.polylinePositions) ||
  249. !defined(options.shapePositions) ||
  250. DynamicGeometryUpdater.prototype._isHidden.call(
  251. this,
  252. entity,
  253. polylineVolume,
  254. time,
  255. )
  256. );
  257. };
  258. DynamicPolylineVolumeGeometryUpdater.prototype._setOptions = function (
  259. entity,
  260. polylineVolume,
  261. time,
  262. ) {
  263. const options = this._options;
  264. options.polylinePositions = Property.getValueOrUndefined(
  265. polylineVolume.positions,
  266. time,
  267. options.polylinePositions,
  268. );
  269. options.shapePositions = Property.getValueOrUndefined(
  270. polylineVolume.shape,
  271. time,
  272. );
  273. options.granularity = Property.getValueOrUndefined(
  274. polylineVolume.granularity,
  275. time,
  276. );
  277. options.cornerType = Property.getValueOrUndefined(
  278. polylineVolume.cornerType,
  279. time,
  280. );
  281. };
  282. export default PolylineVolumeGeometryUpdater;