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

RectangleGeometryUpdater.js 13KB

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