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

EllipseGeometryUpdater.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. import ApproximateTerrainHeights from "../Core/ApproximateTerrainHeights.js";
  2. import Cartesian3 from "../Core/Cartesian3.js";
  3. import Check from "../Core/Check.js";
  4. import Color from "../Core/Color.js";
  5. import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
  6. import defined from "../Core/defined.js";
  7. import DeveloperError from "../Core/DeveloperError.js";
  8. import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js";
  9. import EllipseGeometry from "../Core/EllipseGeometry.js";
  10. import EllipseOutlineGeometry from "../Core/EllipseOutlineGeometry.js";
  11. import GeometryInstance from "../Core/GeometryInstance.js";
  12. import Iso8601 from "../Core/Iso8601.js";
  13. import OffsetGeometryInstanceAttribute from "../Core/OffsetGeometryInstanceAttribute.js";
  14. import Rectangle from "../Core/Rectangle.js";
  15. import ShowGeometryInstanceAttribute from "../Core/ShowGeometryInstanceAttribute.js";
  16. import HeightReference from "../Scene/HeightReference.js";
  17. import MaterialAppearance from "../Scene/MaterialAppearance.js";
  18. import PerInstanceColorAppearance from "../Scene/PerInstanceColorAppearance.js";
  19. import ColorMaterialProperty from "./ColorMaterialProperty.js";
  20. import DynamicGeometryUpdater from "./DynamicGeometryUpdater.js";
  21. import GeometryUpdater from "./GeometryUpdater.js";
  22. import GroundGeometryUpdater from "./GroundGeometryUpdater.js";
  23. import Property from "./Property.js";
  24. const scratchColor = new Color();
  25. const defaultOffset = Cartesian3.ZERO;
  26. const offsetScratch = new Cartesian3();
  27. const scratchRectangle = new Rectangle();
  28. function EllipseGeometryOptions(entity) {
  29. this.id = entity;
  30. this.vertexFormat = undefined;
  31. this.center = undefined;
  32. this.semiMajorAxis = undefined;
  33. this.semiMinorAxis = undefined;
  34. this.rotation = undefined;
  35. this.height = undefined;
  36. this.extrudedHeight = undefined;
  37. this.granularity = undefined;
  38. this.stRotation = undefined;
  39. this.numberOfVerticalLines = undefined;
  40. this.offsetAttribute = undefined;
  41. }
  42. /**
  43. * A {@link GeometryUpdater} for ellipses.
  44. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  45. * @alias EllipseGeometryUpdater
  46. * @constructor
  47. *
  48. * @param {Entity} entity The entity containing the geometry to be visualized.
  49. * @param {Scene} scene The scene where visualization is taking place.
  50. */
  51. function EllipseGeometryUpdater(entity, scene) {
  52. GroundGeometryUpdater.call(this, {
  53. entity: entity,
  54. scene: scene,
  55. geometryOptions: new EllipseGeometryOptions(entity),
  56. geometryPropertyName: "ellipse",
  57. observedPropertyNames: ["availability", "position", "ellipse"],
  58. });
  59. this._onEntityPropertyChanged(entity, "ellipse", entity.ellipse, undefined);
  60. }
  61. if (defined(Object.create)) {
  62. EllipseGeometryUpdater.prototype = Object.create(
  63. GroundGeometryUpdater.prototype,
  64. );
  65. EllipseGeometryUpdater.prototype.constructor = EllipseGeometryUpdater;
  66. }
  67. /**
  68. * Creates the geometry instance which represents the fill of the geometry.
  69. *
  70. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  71. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  72. *
  73. * @exception {DeveloperError} This instance does not represent a filled geometry.
  74. */
  75. EllipseGeometryUpdater.prototype.createFillGeometryInstance = function (time) {
  76. //>>includeStart('debug', pragmas.debug);
  77. Check.defined("time", time);
  78. if (!this._fillEnabled) {
  79. throw new DeveloperError(
  80. "This instance does not represent a filled geometry.",
  81. );
  82. }
  83. //>>includeEnd('debug');
  84. const entity = this._entity;
  85. const isAvailable = entity.isAvailable(time);
  86. const attributes = {
  87. show: new ShowGeometryInstanceAttribute(
  88. isAvailable &&
  89. entity.isShowing &&
  90. this._showProperty.getValue(time) &&
  91. this._fillProperty.getValue(time),
  92. ),
  93. distanceDisplayCondition:
  94. DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  95. this._distanceDisplayConditionProperty.getValue(time),
  96. ),
  97. offset: undefined,
  98. color: undefined,
  99. };
  100. if (this._materialProperty instanceof ColorMaterialProperty) {
  101. let currentColor;
  102. if (
  103. defined(this._materialProperty.color) &&
  104. (this._materialProperty.color.isConstant || isAvailable)
  105. ) {
  106. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  107. }
  108. if (!defined(currentColor)) {
  109. currentColor = Color.WHITE;
  110. }
  111. attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  112. }
  113. if (defined(this._options.offsetAttribute)) {
  114. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
  115. Property.getValueOrDefault(
  116. this._terrainOffsetProperty,
  117. time,
  118. defaultOffset,
  119. offsetScratch,
  120. ),
  121. );
  122. }
  123. return new GeometryInstance({
  124. id: entity,
  125. geometry: new EllipseGeometry(this._options),
  126. attributes: attributes,
  127. });
  128. };
  129. /**
  130. * Creates the geometry instance which represents the outline of the geometry.
  131. *
  132. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  133. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  134. *
  135. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  136. */
  137. EllipseGeometryUpdater.prototype.createOutlineGeometryInstance = function (
  138. time,
  139. ) {
  140. //>>includeStart('debug', pragmas.debug);
  141. Check.defined("time", time);
  142. if (!this._outlineEnabled) {
  143. throw new DeveloperError(
  144. "This instance does not represent an outlined geometry.",
  145. );
  146. }
  147. //>>includeEnd('debug');
  148. const entity = this._entity;
  149. const isAvailable = entity.isAvailable(time);
  150. const outlineColor = Property.getValueOrDefault(
  151. this._outlineColorProperty,
  152. time,
  153. Color.BLACK,
  154. scratchColor,
  155. );
  156. const distanceDisplayCondition =
  157. this._distanceDisplayConditionProperty.getValue(time);
  158. const attributes = {
  159. show: new ShowGeometryInstanceAttribute(
  160. isAvailable &&
  161. entity.isShowing &&
  162. this._showProperty.getValue(time) &&
  163. this._showOutlineProperty.getValue(time),
  164. ),
  165. color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
  166. distanceDisplayCondition:
  167. DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  168. distanceDisplayCondition,
  169. ),
  170. offset: undefined,
  171. };
  172. if (defined(this._options.offsetAttribute)) {
  173. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
  174. Property.getValueOrDefault(
  175. this._terrainOffsetProperty,
  176. time,
  177. defaultOffset,
  178. offsetScratch,
  179. ),
  180. );
  181. }
  182. return new GeometryInstance({
  183. id: entity,
  184. geometry: new EllipseOutlineGeometry(this._options),
  185. attributes: attributes,
  186. });
  187. };
  188. EllipseGeometryUpdater.prototype._computeCenter = function (time, result) {
  189. return Property.getValueOrUndefined(this._entity.position, time, result);
  190. };
  191. EllipseGeometryUpdater.prototype._isHidden = function (entity, ellipse) {
  192. const position = entity.position;
  193. return (
  194. !defined(position) ||
  195. !defined(ellipse.semiMajorAxis) ||
  196. !defined(ellipse.semiMinorAxis) ||
  197. GeometryUpdater.prototype._isHidden.call(this, entity, ellipse)
  198. );
  199. };
  200. EllipseGeometryUpdater.prototype._isDynamic = function (entity, ellipse) {
  201. return (
  202. !entity.position.isConstant || //
  203. !ellipse.semiMajorAxis.isConstant || //
  204. !ellipse.semiMinorAxis.isConstant || //
  205. !Property.isConstant(ellipse.rotation) || //
  206. !Property.isConstant(ellipse.height) || //
  207. !Property.isConstant(ellipse.extrudedHeight) || //
  208. !Property.isConstant(ellipse.granularity) || //
  209. !Property.isConstant(ellipse.stRotation) || //
  210. !Property.isConstant(ellipse.outlineWidth) || //
  211. !Property.isConstant(ellipse.numberOfVerticalLines) || //
  212. !Property.isConstant(ellipse.zIndex) || //
  213. (this._onTerrain &&
  214. !Property.isConstant(this._materialProperty) &&
  215. !(this._materialProperty instanceof ColorMaterialProperty))
  216. );
  217. };
  218. EllipseGeometryUpdater.prototype._setStaticOptions = function (
  219. entity,
  220. ellipse,
  221. ) {
  222. let heightValue = Property.getValueOrUndefined(
  223. ellipse.height,
  224. Iso8601.MINIMUM_VALUE,
  225. );
  226. const heightReferenceValue = Property.getValueOrDefault(
  227. ellipse.heightReference,
  228. Iso8601.MINIMUM_VALUE,
  229. HeightReference.NONE,
  230. );
  231. let extrudedHeightValue = Property.getValueOrUndefined(
  232. ellipse.extrudedHeight,
  233. Iso8601.MINIMUM_VALUE,
  234. );
  235. const extrudedHeightReferenceValue = Property.getValueOrDefault(
  236. ellipse.extrudedHeightReference,
  237. Iso8601.MINIMUM_VALUE,
  238. HeightReference.NONE,
  239. );
  240. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  241. heightValue = 0;
  242. }
  243. const options = this._options;
  244. options.vertexFormat =
  245. this._materialProperty instanceof ColorMaterialProperty
  246. ? PerInstanceColorAppearance.VERTEX_FORMAT
  247. : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  248. options.center = entity.position.getValue(
  249. Iso8601.MINIMUM_VALUE,
  250. options.center,
  251. );
  252. options.semiMajorAxis = ellipse.semiMajorAxis.getValue(
  253. Iso8601.MINIMUM_VALUE,
  254. options.semiMajorAxis,
  255. );
  256. options.semiMinorAxis = ellipse.semiMinorAxis.getValue(
  257. Iso8601.MINIMUM_VALUE,
  258. options.semiMinorAxis,
  259. );
  260. options.rotation = Property.getValueOrUndefined(
  261. ellipse.rotation,
  262. Iso8601.MINIMUM_VALUE,
  263. );
  264. options.granularity = Property.getValueOrUndefined(
  265. ellipse.granularity,
  266. Iso8601.MINIMUM_VALUE,
  267. );
  268. options.stRotation = Property.getValueOrUndefined(
  269. ellipse.stRotation,
  270. Iso8601.MINIMUM_VALUE,
  271. );
  272. options.numberOfVerticalLines = Property.getValueOrUndefined(
  273. ellipse.numberOfVerticalLines,
  274. Iso8601.MINIMUM_VALUE,
  275. );
  276. options.offsetAttribute =
  277. GroundGeometryUpdater.computeGeometryOffsetAttribute(
  278. heightValue,
  279. heightReferenceValue,
  280. extrudedHeightValue,
  281. extrudedHeightReferenceValue,
  282. );
  283. options.height = GroundGeometryUpdater.getGeometryHeight(
  284. heightValue,
  285. heightReferenceValue,
  286. );
  287. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(
  288. extrudedHeightValue,
  289. extrudedHeightReferenceValue,
  290. );
  291. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  292. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(
  293. EllipseGeometry.computeRectangle(options, scratchRectangle),
  294. ).minimumTerrainHeight;
  295. }
  296. options.extrudedHeight = extrudedHeightValue;
  297. };
  298. EllipseGeometryUpdater.DynamicGeometryUpdater = DynamicEllipseGeometryUpdater;
  299. /**
  300. * @private
  301. */
  302. function DynamicEllipseGeometryUpdater(
  303. geometryUpdater,
  304. primitives,
  305. groundPrimitives,
  306. ) {
  307. DynamicGeometryUpdater.call(
  308. this,
  309. geometryUpdater,
  310. primitives,
  311. groundPrimitives,
  312. );
  313. }
  314. if (defined(Object.create)) {
  315. DynamicEllipseGeometryUpdater.prototype = Object.create(
  316. DynamicGeometryUpdater.prototype,
  317. );
  318. DynamicEllipseGeometryUpdater.prototype.constructor =
  319. DynamicEllipseGeometryUpdater;
  320. }
  321. DynamicEllipseGeometryUpdater.prototype._isHidden = function (
  322. entity,
  323. ellipse,
  324. time,
  325. ) {
  326. const options = this._options;
  327. return (
  328. !defined(options.center) ||
  329. !defined(options.semiMajorAxis) ||
  330. !defined(options.semiMinorAxis) ||
  331. DynamicGeometryUpdater.prototype._isHidden.call(this, entity, ellipse, time)
  332. );
  333. };
  334. DynamicEllipseGeometryUpdater.prototype._setOptions = function (
  335. entity,
  336. ellipse,
  337. time,
  338. ) {
  339. const options = this._options;
  340. let heightValue = Property.getValueOrUndefined(ellipse.height, time);
  341. const heightReferenceValue = Property.getValueOrDefault(
  342. ellipse.heightReference,
  343. time,
  344. HeightReference.NONE,
  345. );
  346. let extrudedHeightValue = Property.getValueOrUndefined(
  347. ellipse.extrudedHeight,
  348. time,
  349. );
  350. const extrudedHeightReferenceValue = Property.getValueOrDefault(
  351. ellipse.extrudedHeightReference,
  352. time,
  353. HeightReference.NONE,
  354. );
  355. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  356. heightValue = 0;
  357. }
  358. options.center = Property.getValueOrUndefined(
  359. entity.position,
  360. time,
  361. options.center,
  362. );
  363. options.semiMajorAxis = Property.getValueOrUndefined(
  364. ellipse.semiMajorAxis,
  365. time,
  366. );
  367. options.semiMinorAxis = Property.getValueOrUndefined(
  368. ellipse.semiMinorAxis,
  369. time,
  370. );
  371. options.rotation = Property.getValueOrUndefined(ellipse.rotation, time);
  372. options.granularity = Property.getValueOrUndefined(ellipse.granularity, time);
  373. options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time);
  374. options.numberOfVerticalLines = Property.getValueOrUndefined(
  375. ellipse.numberOfVerticalLines,
  376. time,
  377. );
  378. options.offsetAttribute =
  379. GroundGeometryUpdater.computeGeometryOffsetAttribute(
  380. heightValue,
  381. heightReferenceValue,
  382. extrudedHeightValue,
  383. extrudedHeightReferenceValue,
  384. );
  385. options.height = GroundGeometryUpdater.getGeometryHeight(
  386. heightValue,
  387. heightReferenceValue,
  388. );
  389. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(
  390. extrudedHeightValue,
  391. extrudedHeightReferenceValue,
  392. );
  393. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  394. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(
  395. EllipseGeometry.computeRectangle(options, scratchRectangle),
  396. ).minimumTerrainHeight;
  397. }
  398. options.extrudedHeight = extrudedHeightValue;
  399. };
  400. export default EllipseGeometryUpdater;