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

PointPrimitive.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. import BoundingRectangle from "../Core/BoundingRectangle.js";
  2. import Cartesian2 from "../Core/Cartesian2.js";
  3. import Cartesian3 from "../Core/Cartesian3.js";
  4. import Cartesian4 from "../Core/Cartesian4.js";
  5. import Color from "../Core/Color.js";
  6. import Frozen from "../Core/Frozen.js";
  7. import defined from "../Core/defined.js";
  8. import DeveloperError from "../Core/DeveloperError.js";
  9. import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
  10. import Matrix4 from "../Core/Matrix4.js";
  11. import NearFarScalar from "../Core/NearFarScalar.js";
  12. import SceneMode from "./SceneMode.js";
  13. import SceneTransforms from "./SceneTransforms.js";
  14. import SplitDirection from "./SplitDirection.js";
  15. /**
  16. * <div class="notice">
  17. * A point is created and its initial properties are set by calling {@link PointPrimitiveCollection#add}. Do not call the constructor directly.
  18. * </div>
  19. * A graphical point positioned in the 3D scene, that is created
  20. * and rendered using a {@link PointPrimitiveCollection}.
  21. *
  22. * @alias PointPrimitive
  23. *
  24. * @performance Reading a property, e.g., {@link PointPrimitive#show}, is constant time.
  25. * Assigning to a property is constant time but results in
  26. * CPU to GPU traffic when {@link PointPrimitiveCollection#update} is called. The per-pointPrimitive traffic is
  27. * the same regardless of how many properties were updated. If most pointPrimitives in a collection need to be
  28. * updated, it may be more efficient to clear the collection with {@link PointPrimitiveCollection#removeAll}
  29. * and add new pointPrimitives instead of modifying each one.
  30. *
  31. * @exception {DeveloperError} scaleByDistance.far must be greater than scaleByDistance.near
  32. * @exception {DeveloperError} translucencyByDistance.far must be greater than translucencyByDistance.near
  33. * @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near
  34. *
  35. * @see PointPrimitiveCollection
  36. * @see PointPrimitiveCollection#add
  37. *
  38. * @internalConstructor
  39. * @class
  40. *
  41. * @demo {@link https://sandcastle.cesium.com/index.html?id=points|Cesium Sandcastle Points Demo}
  42. */
  43. function PointPrimitive(options, pointPrimitiveCollection) {
  44. options = options ?? Frozen.EMPTY_OBJECT;
  45. //>>includeStart('debug', pragmas.debug);
  46. if (
  47. defined(options.disableDepthTestDistance) &&
  48. options.disableDepthTestDistance < 0.0
  49. ) {
  50. throw new DeveloperError(
  51. "disableDepthTestDistance must be greater than or equal to 0.0.",
  52. );
  53. }
  54. //>>includeEnd('debug');
  55. let translucencyByDistance = options.translucencyByDistance;
  56. let scaleByDistance = options.scaleByDistance;
  57. let distanceDisplayCondition = options.distanceDisplayCondition;
  58. if (defined(translucencyByDistance)) {
  59. //>>includeStart('debug', pragmas.debug);
  60. if (translucencyByDistance.far <= translucencyByDistance.near) {
  61. throw new DeveloperError(
  62. "translucencyByDistance.far must be greater than translucencyByDistance.near.",
  63. );
  64. }
  65. //>>includeEnd('debug');
  66. translucencyByDistance = NearFarScalar.clone(translucencyByDistance);
  67. }
  68. if (defined(scaleByDistance)) {
  69. //>>includeStart('debug', pragmas.debug);
  70. if (scaleByDistance.far <= scaleByDistance.near) {
  71. throw new DeveloperError(
  72. "scaleByDistance.far must be greater than scaleByDistance.near.",
  73. );
  74. }
  75. //>>includeEnd('debug');
  76. scaleByDistance = NearFarScalar.clone(scaleByDistance);
  77. }
  78. if (defined(distanceDisplayCondition)) {
  79. //>>includeStart('debug', pragmas.debug);
  80. if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {
  81. throw new DeveloperError(
  82. "distanceDisplayCondition.far must be greater than distanceDisplayCondition.near.",
  83. );
  84. }
  85. //>>includeEnd('debug');
  86. distanceDisplayCondition = DistanceDisplayCondition.clone(
  87. distanceDisplayCondition,
  88. );
  89. }
  90. this._show = options.show ?? true;
  91. this._position = Cartesian3.clone(options.position ?? Cartesian3.ZERO);
  92. this._actualPosition = Cartesian3.clone(this._position); // For columbus view and 2D
  93. this._color = Color.clone(options.color ?? Color.WHITE);
  94. this._outlineColor = Color.clone(options.outlineColor ?? Color.TRANSPARENT);
  95. this._outlineWidth = options.outlineWidth ?? 0.0;
  96. this._pixelSize = options.pixelSize ?? 10.0;
  97. this._scaleByDistance = scaleByDistance;
  98. this._translucencyByDistance = translucencyByDistance;
  99. this._distanceDisplayCondition = distanceDisplayCondition;
  100. this._disableDepthTestDistance = options.disableDepthTestDistance ?? 0.0;
  101. this._id = options.id;
  102. this._collection = options.collection ?? pointPrimitiveCollection;
  103. this._clusterShow = true;
  104. this._pickId = undefined;
  105. this._pointPrimitiveCollection = pointPrimitiveCollection;
  106. this._dirty = false;
  107. this._index = -1; //Used only by PointPrimitiveCollection
  108. this._splitDirection = options.splitDirection ?? SplitDirection.NONE;
  109. }
  110. const SHOW_INDEX = (PointPrimitive.SHOW_INDEX = 0);
  111. const POSITION_INDEX = (PointPrimitive.POSITION_INDEX = 1);
  112. const COLOR_INDEX = (PointPrimitive.COLOR_INDEX = 2);
  113. const OUTLINE_COLOR_INDEX = (PointPrimitive.OUTLINE_COLOR_INDEX = 3);
  114. const OUTLINE_WIDTH_INDEX = (PointPrimitive.OUTLINE_WIDTH_INDEX = 4);
  115. const PIXEL_SIZE_INDEX = (PointPrimitive.PIXEL_SIZE_INDEX = 5);
  116. const SCALE_BY_DISTANCE_INDEX = (PointPrimitive.SCALE_BY_DISTANCE_INDEX = 6);
  117. const TRANSLUCENCY_BY_DISTANCE_INDEX =
  118. (PointPrimitive.TRANSLUCENCY_BY_DISTANCE_INDEX = 7);
  119. const DISTANCE_DISPLAY_CONDITION_INDEX =
  120. (PointPrimitive.DISTANCE_DISPLAY_CONDITION_INDEX = 8);
  121. const DISABLE_DEPTH_DISTANCE_INDEX =
  122. (PointPrimitive.DISABLE_DEPTH_DISTANCE_INDEX = 9);
  123. const SPLIT_DIRECTION_INDEX = (PointPrimitive.SPLIT_DIRECTION_INDEX = 10);
  124. PointPrimitive.NUMBER_OF_PROPERTIES = 11;
  125. function makeDirty(pointPrimitive, propertyChanged) {
  126. const pointPrimitiveCollection = pointPrimitive._pointPrimitiveCollection;
  127. if (defined(pointPrimitiveCollection)) {
  128. pointPrimitiveCollection._updatePointPrimitive(
  129. pointPrimitive,
  130. propertyChanged,
  131. );
  132. pointPrimitive._dirty = true;
  133. }
  134. }
  135. Object.defineProperties(PointPrimitive.prototype, {
  136. /**
  137. * Determines if this point will be shown. Use this to hide or show a point, instead
  138. * of removing it and re-adding it to the collection.
  139. * @memberof PointPrimitive.prototype
  140. * @type {boolean}
  141. */
  142. show: {
  143. get: function () {
  144. return this._show;
  145. },
  146. set: function (value) {
  147. //>>includeStart('debug', pragmas.debug);
  148. if (!defined(value)) {
  149. throw new DeveloperError("value is required.");
  150. }
  151. //>>includeEnd('debug');
  152. if (this._show !== value) {
  153. this._show = value;
  154. makeDirty(this, SHOW_INDEX);
  155. }
  156. },
  157. },
  158. /**
  159. * Gets or sets the Cartesian position of this point.
  160. * @memberof PointPrimitive.prototype
  161. * @type {Cartesian3}
  162. */
  163. position: {
  164. get: function () {
  165. return this._position;
  166. },
  167. set: function (value) {
  168. //>>includeStart('debug', pragmas.debug)
  169. if (!defined(value)) {
  170. throw new DeveloperError("value is required.");
  171. }
  172. //>>includeEnd('debug');
  173. const position = this._position;
  174. if (!Cartesian3.equals(position, value)) {
  175. Cartesian3.clone(value, position);
  176. Cartesian3.clone(value, this._actualPosition);
  177. makeDirty(this, POSITION_INDEX);
  178. }
  179. },
  180. },
  181. /**
  182. * Gets or sets near and far scaling properties of a point based on the point's distance from the camera.
  183. * A point's scale will interpolate between the {@link NearFarScalar#nearValue} and
  184. * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds
  185. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  186. * Outside of these ranges the point's scale remains clamped to the nearest bound. This scale
  187. * multiplies the pixelSize and outlineWidth to affect the total size of the point. If undefined,
  188. * scaleByDistance will be disabled.
  189. * @memberof PointPrimitive.prototype
  190. * @type {NearFarScalar}
  191. *
  192. * @example
  193. * // Example 1.
  194. * // Set a pointPrimitive's scaleByDistance to scale to 15 when the
  195. * // camera is 1500 meters from the pointPrimitive and disappear as
  196. * // the camera distance approaches 8.0e6 meters.
  197. * p.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 15, 8.0e6, 0.0);
  198. *
  199. * @example
  200. * // Example 2.
  201. * // disable scaling by distance
  202. * p.scaleByDistance = undefined;
  203. */
  204. scaleByDistance: {
  205. get: function () {
  206. return this._scaleByDistance;
  207. },
  208. set: function (value) {
  209. //>>includeStart('debug', pragmas.debug);
  210. if (defined(value) && value.far <= value.near) {
  211. throw new DeveloperError(
  212. "far distance must be greater than near distance.",
  213. );
  214. }
  215. //>>includeEnd('debug');
  216. const scaleByDistance = this._scaleByDistance;
  217. if (!NearFarScalar.equals(scaleByDistance, value)) {
  218. this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);
  219. makeDirty(this, SCALE_BY_DISTANCE_INDEX);
  220. }
  221. },
  222. },
  223. /**
  224. * Gets or sets near and far translucency properties of a point based on the point's distance from the camera.
  225. * A point's translucency will interpolate between the {@link NearFarScalar#nearValue} and
  226. * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds
  227. * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.
  228. * Outside of these ranges the point's translucency remains clamped to the nearest bound. If undefined,
  229. * translucencyByDistance will be disabled.
  230. * @memberof PointPrimitive.prototype
  231. * @type {NearFarScalar}
  232. *
  233. * @example
  234. * // Example 1.
  235. * // Set a point's translucency to 1.0 when the
  236. * // camera is 1500 meters from the point and disappear as
  237. * // the camera distance approaches 8.0e6 meters.
  238. * p.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);
  239. *
  240. * @example
  241. * // Example 2.
  242. * // disable translucency by distance
  243. * p.translucencyByDistance = undefined;
  244. */
  245. translucencyByDistance: {
  246. get: function () {
  247. return this._translucencyByDistance;
  248. },
  249. set: function (value) {
  250. //>>includeStart('debug', pragmas.debug);
  251. if (defined(value) && value.far <= value.near) {
  252. throw new DeveloperError(
  253. "far distance must be greater than near distance.",
  254. );
  255. }
  256. //>>includeEnd('debug');
  257. const translucencyByDistance = this._translucencyByDistance;
  258. if (!NearFarScalar.equals(translucencyByDistance, value)) {
  259. this._translucencyByDistance = NearFarScalar.clone(
  260. value,
  261. translucencyByDistance,
  262. );
  263. makeDirty(this, TRANSLUCENCY_BY_DISTANCE_INDEX);
  264. }
  265. },
  266. },
  267. /**
  268. * Gets or sets the inner size of the point in pixels.
  269. * @memberof PointPrimitive.prototype
  270. * @type {number}
  271. */
  272. pixelSize: {
  273. get: function () {
  274. return this._pixelSize;
  275. },
  276. set: function (value) {
  277. //>>includeStart('debug', pragmas.debug);
  278. if (!defined(value)) {
  279. throw new DeveloperError("value is required.");
  280. }
  281. //>>includeEnd('debug');
  282. if (this._pixelSize !== value) {
  283. this._pixelSize = value;
  284. makeDirty(this, PIXEL_SIZE_INDEX);
  285. }
  286. },
  287. },
  288. /**
  289. * Gets or sets the inner color of the point.
  290. * The red, green, blue, and alpha values are indicated by <code>value</code>'s <code>red</code>, <code>green</code>,
  291. * <code>blue</code>, and <code>alpha</code> properties as shown in Example 1. These components range from <code>0.0</code>
  292. * (no intensity) to <code>1.0</code> (full intensity).
  293. * @memberof PointPrimitive.prototype
  294. * @type {Color}
  295. *
  296. * @example
  297. * // Example 1. Assign yellow.
  298. * p.color = Cesium.Color.YELLOW;
  299. *
  300. * @example
  301. * // Example 2. Make a pointPrimitive 50% translucent.
  302. * p.color = new Cesium.Color(1.0, 1.0, 1.0, 0.5);
  303. */
  304. color: {
  305. get: function () {
  306. return this._color;
  307. },
  308. set: function (value) {
  309. //>>includeStart('debug', pragmas.debug);
  310. if (!defined(value)) {
  311. throw new DeveloperError("value is required.");
  312. }
  313. //>>includeEnd('debug');
  314. const color = this._color;
  315. if (!Color.equals(color, value)) {
  316. Color.clone(value, color);
  317. makeDirty(this, COLOR_INDEX);
  318. }
  319. },
  320. },
  321. /**
  322. * Gets or sets the outline color of the point.
  323. * @memberof PointPrimitive.prototype
  324. * @type {Color}
  325. */
  326. outlineColor: {
  327. get: function () {
  328. return this._outlineColor;
  329. },
  330. set: function (value) {
  331. //>>includeStart('debug', pragmas.debug);
  332. if (!defined(value)) {
  333. throw new DeveloperError("value is required.");
  334. }
  335. //>>includeEnd('debug');
  336. const outlineColor = this._outlineColor;
  337. if (!Color.equals(outlineColor, value)) {
  338. Color.clone(value, outlineColor);
  339. makeDirty(this, OUTLINE_COLOR_INDEX);
  340. }
  341. },
  342. },
  343. /**
  344. * Gets or sets the outline width in pixels. This width adds to pixelSize,
  345. * increasing the total size of the point.
  346. * @memberof PointPrimitive.prototype
  347. * @type {number}
  348. */
  349. outlineWidth: {
  350. get: function () {
  351. return this._outlineWidth;
  352. },
  353. set: function (value) {
  354. //>>includeStart('debug', pragmas.debug);
  355. if (!defined(value)) {
  356. throw new DeveloperError("value is required.");
  357. }
  358. //>>includeEnd('debug');
  359. if (this._outlineWidth !== value) {
  360. this._outlineWidth = value;
  361. makeDirty(this, OUTLINE_WIDTH_INDEX);
  362. }
  363. },
  364. },
  365. /**
  366. * Gets or sets the condition specifying at what distance from the camera that this point will be displayed.
  367. * @memberof PointPrimitive.prototype
  368. * @type {DistanceDisplayCondition}
  369. * @default undefined
  370. */
  371. distanceDisplayCondition: {
  372. get: function () {
  373. return this._distanceDisplayCondition;
  374. },
  375. set: function (value) {
  376. //>>includeStart('debug', pragmas.debug);
  377. if (defined(value) && value.far <= value.near) {
  378. throw new DeveloperError("far must be greater than near");
  379. }
  380. //>>includeEnd('debug');
  381. if (
  382. !DistanceDisplayCondition.equals(this._distanceDisplayCondition, value)
  383. ) {
  384. this._distanceDisplayCondition = DistanceDisplayCondition.clone(
  385. value,
  386. this._distanceDisplayCondition,
  387. );
  388. makeDirty(this, DISTANCE_DISPLAY_CONDITION_INDEX);
  389. }
  390. },
  391. },
  392. /**
  393. * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
  394. * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
  395. * @memberof PointPrimitive.prototype
  396. * @type {number}
  397. * @default 0.0
  398. */
  399. disableDepthTestDistance: {
  400. get: function () {
  401. return this._disableDepthTestDistance;
  402. },
  403. set: function (value) {
  404. if (this._disableDepthTestDistance !== value) {
  405. //>>includeStart('debug', pragmas.debug);
  406. if (!defined(value) || value < 0.0) {
  407. throw new DeveloperError(
  408. "disableDepthTestDistance must be greater than or equal to 0.0.",
  409. );
  410. }
  411. //>>includeEnd('debug');
  412. this._disableDepthTestDistance = value;
  413. makeDirty(this, DISABLE_DEPTH_DISTANCE_INDEX);
  414. }
  415. },
  416. },
  417. /**
  418. * Gets or sets the user-defined value returned when the point is picked.
  419. * @memberof PointPrimitive.prototype
  420. * @type {*}
  421. */
  422. id: {
  423. get: function () {
  424. return this._id;
  425. },
  426. set: function (value) {
  427. this._id = value;
  428. if (defined(this._pickId)) {
  429. this._pickId.object.id = value;
  430. }
  431. },
  432. },
  433. /**
  434. * @private
  435. */
  436. pickId: {
  437. get: function () {
  438. return this._pickId;
  439. },
  440. },
  441. /**
  442. * Determines whether or not this point will be shown or hidden because it was clustered.
  443. * @memberof PointPrimitive.prototype
  444. * @type {boolean}
  445. * @private
  446. */
  447. clusterShow: {
  448. get: function () {
  449. return this._clusterShow;
  450. },
  451. set: function (value) {
  452. if (this._clusterShow !== value) {
  453. this._clusterShow = value;
  454. makeDirty(this, SHOW_INDEX);
  455. }
  456. },
  457. },
  458. /**
  459. * The {@link SplitDirection} to apply to this point.
  460. * @memberof PointPrimitive.prototype
  461. * @type {SplitDirection}
  462. * @default {@link SplitDirection.NONE}
  463. */
  464. splitDirection: {
  465. get: function () {
  466. return this._splitDirection;
  467. },
  468. set: function (value) {
  469. if (this._splitDirection !== value) {
  470. this._splitDirection = value;
  471. makeDirty(this, SPLIT_DIRECTION_INDEX);
  472. }
  473. },
  474. },
  475. });
  476. PointPrimitive.prototype.getPickId = function (context) {
  477. if (!defined(this._pickId)) {
  478. this._pickId = context.createPickId({
  479. primitive: this,
  480. collection: this._collection,
  481. id: this._id,
  482. });
  483. }
  484. return this._pickId;
  485. };
  486. PointPrimitive.prototype._getActualPosition = function () {
  487. return this._actualPosition;
  488. };
  489. PointPrimitive.prototype._setActualPosition = function (value) {
  490. Cartesian3.clone(value, this._actualPosition);
  491. makeDirty(this, POSITION_INDEX);
  492. };
  493. const tempCartesian3 = new Cartesian4();
  494. PointPrimitive._computeActualPosition = function (
  495. position,
  496. frameState,
  497. modelMatrix,
  498. ) {
  499. if (frameState.mode === SceneMode.SCENE3D) {
  500. return position;
  501. }
  502. Matrix4.multiplyByPoint(modelMatrix, position, tempCartesian3);
  503. return SceneTransforms.computeActualEllipsoidPosition(
  504. frameState,
  505. tempCartesian3,
  506. );
  507. };
  508. const scratchCartesian4 = new Cartesian4();
  509. // This function is basically a stripped-down JavaScript version of PointPrimitiveCollectionVS.glsl
  510. PointPrimitive._computeScreenSpacePosition = function (
  511. modelMatrix,
  512. position,
  513. scene,
  514. result,
  515. ) {
  516. // Model to world coordinates
  517. const positionWorld = Matrix4.multiplyByVector(
  518. modelMatrix,
  519. Cartesian4.fromElements(
  520. position.x,
  521. position.y,
  522. position.z,
  523. 1,
  524. scratchCartesian4,
  525. ),
  526. scratchCartesian4,
  527. );
  528. const positionWC = SceneTransforms.worldToWindowCoordinates(
  529. scene,
  530. positionWorld,
  531. result,
  532. );
  533. return positionWC;
  534. };
  535. /**
  536. * Computes the screen-space position of the point's origin.
  537. * The screen space origin is the top, left corner of the canvas; <code>x</code> increases from
  538. * left to right, and <code>y</code> increases from top to bottom.
  539. *
  540. * @param {Scene} scene The scene.
  541. * @param {Cartesian2} [result] The object onto which to store the result.
  542. * @returns {Cartesian2} The screen-space position of the point.
  543. *
  544. * @exception {DeveloperError} PointPrimitive must be in a collection.
  545. *
  546. * @example
  547. * console.log(p.computeScreenSpacePosition(scene).toString());
  548. */
  549. PointPrimitive.prototype.computeScreenSpacePosition = function (scene, result) {
  550. const pointPrimitiveCollection = this._pointPrimitiveCollection;
  551. if (!defined(result)) {
  552. result = new Cartesian2();
  553. }
  554. //>>includeStart('debug', pragmas.debug);
  555. if (!defined(pointPrimitiveCollection)) {
  556. throw new DeveloperError("PointPrimitive must be in a collection.");
  557. }
  558. if (!defined(scene)) {
  559. throw new DeveloperError("scene is required.");
  560. }
  561. //>>includeEnd('debug');
  562. const modelMatrix = pointPrimitiveCollection.modelMatrix;
  563. const windowCoordinates = PointPrimitive._computeScreenSpacePosition(
  564. modelMatrix,
  565. this._actualPosition,
  566. scene,
  567. result,
  568. );
  569. if (!defined(windowCoordinates)) {
  570. return undefined;
  571. }
  572. windowCoordinates.y = scene.canvas.clientHeight - windowCoordinates.y;
  573. return windowCoordinates;
  574. };
  575. /**
  576. * Gets a point's screen space bounding box centered around screenSpacePosition.
  577. * @param {PointPrimitive} point The point to get the screen space bounding box for.
  578. * @param {Cartesian2} screenSpacePosition The screen space center of the label.
  579. * @param {BoundingRectangle} [result] The object onto which to store the result.
  580. * @returns {BoundingRectangle} The screen space bounding box.
  581. *
  582. * @private
  583. */
  584. PointPrimitive.getScreenSpaceBoundingBox = function (
  585. point,
  586. screenSpacePosition,
  587. result,
  588. ) {
  589. const size = point.pixelSize;
  590. const halfSize = size * 0.5;
  591. const x = screenSpacePosition.x - halfSize;
  592. const y = screenSpacePosition.y - halfSize;
  593. const width = size;
  594. const height = size;
  595. if (!defined(result)) {
  596. result = new BoundingRectangle();
  597. }
  598. result.x = x;
  599. result.y = y;
  600. result.width = width;
  601. result.height = height;
  602. return result;
  603. };
  604. /**
  605. * Determines if this point equals another point. Points are equal if all their properties
  606. * are equal. Points in different collections can be equal.
  607. *
  608. * @param {PointPrimitive} [other] The point to compare for equality.
  609. * @returns {boolean} <code>true</code> if the points are equal; otherwise, <code>false</code>.
  610. */
  611. PointPrimitive.prototype.equals = function (other) {
  612. return (
  613. this === other ||
  614. (defined(other) &&
  615. this._id === other._id &&
  616. Cartesian3.equals(this._position, other._position) &&
  617. Color.equals(this._color, other._color) &&
  618. this._pixelSize === other._pixelSize &&
  619. this._outlineWidth === other._outlineWidth &&
  620. this._show === other._show &&
  621. Color.equals(this._outlineColor, other._outlineColor) &&
  622. NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&
  623. NearFarScalar.equals(
  624. this._translucencyByDistance,
  625. other._translucencyByDistance,
  626. ) &&
  627. DistanceDisplayCondition.equals(
  628. this._distanceDisplayCondition,
  629. other._distanceDisplayCondition,
  630. ) &&
  631. this._disableDepthTestDistance === other._disableDepthTestDistance &&
  632. this._splitDirection === other._splitDirection)
  633. );
  634. };
  635. PointPrimitive.prototype._destroy = function () {
  636. this._pickId = this._pickId && this._pickId.destroy();
  637. this._pointPrimitiveCollection = undefined;
  638. };
  639. export default PointPrimitive;