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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Cartographic from "../Core/Cartographic.js";
  3. import Check from "../Core/Check.js";
  4. import createGuid from "../Core/createGuid.js";
  5. import Frozen from "../Core/Frozen.js";
  6. import defined from "../Core/defined.js";
  7. import DeveloperError from "../Core/DeveloperError.js";
  8. import Event from "../Core/Event.js";
  9. import CesiumMath from "../Core/Math.js";
  10. import Matrix3 from "../Core/Matrix3.js";
  11. import Matrix4 from "../Core/Matrix4.js";
  12. import Quaternion from "../Core/Quaternion.js";
  13. import TrackingReferenceFrame from "../Core/TrackingReferenceFrame.js";
  14. import Transforms from "../Core/Transforms.js";
  15. import GroundPolylinePrimitive from "../Scene/GroundPolylinePrimitive.js";
  16. import GroundPrimitive from "../Scene/GroundPrimitive.js";
  17. import HeightReference, {
  18. isHeightReferenceClamp,
  19. } from "../Scene/HeightReference.js";
  20. import BillboardGraphics from "./BillboardGraphics.js";
  21. import BoxGraphics from "./BoxGraphics.js";
  22. import ConstantPositionProperty from "./ConstantPositionProperty.js";
  23. import CorridorGraphics from "./CorridorGraphics.js";
  24. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  25. import createRawPropertyDescriptor from "./createRawPropertyDescriptor.js";
  26. import CylinderGraphics from "./CylinderGraphics.js";
  27. import EllipseGraphics from "./EllipseGraphics.js";
  28. import EllipsoidGraphics from "./EllipsoidGraphics.js";
  29. import LabelGraphics from "./LabelGraphics.js";
  30. import ModelGraphics from "./ModelGraphics.js";
  31. import Cesium3DTilesetGraphics from "./Cesium3DTilesetGraphics.js";
  32. import PathGraphics from "./PathGraphics.js";
  33. import PlaneGraphics from "./PlaneGraphics.js";
  34. import PointGraphics from "./PointGraphics.js";
  35. import PolygonGraphics from "./PolygonGraphics.js";
  36. import PolylineGraphics from "./PolylineGraphics.js";
  37. import PolylineVolumeGraphics from "./PolylineVolumeGraphics.js";
  38. import Property from "./Property.js";
  39. import PropertyBag from "./PropertyBag.js";
  40. import RectangleGraphics from "./RectangleGraphics.js";
  41. import WallGraphics from "./WallGraphics.js";
  42. const cartoScratch = new Cartographic();
  43. const ExtraPropertyNames = [];
  44. function createConstantPositionProperty(value) {
  45. return new ConstantPositionProperty(value);
  46. }
  47. function createPositionPropertyDescriptor(name) {
  48. return createPropertyDescriptor(
  49. name,
  50. undefined,
  51. createConstantPositionProperty,
  52. );
  53. }
  54. function createPropertyTypeDescriptor(name, Type) {
  55. return createPropertyDescriptor(name, undefined, function (value) {
  56. if (value instanceof Type) {
  57. return value;
  58. }
  59. return new Type(value);
  60. });
  61. }
  62. /**
  63. * @typedef {object} Entity.ConstructorOptions
  64. *
  65. * Initialization options for the Entity constructor
  66. *
  67. * @property {string} [id] A unique identifier for this object. If none is provided, a GUID is generated.
  68. * @property {string} [name] A human readable name to display to users. It does not have to be unique.
  69. * @property {TimeIntervalCollection} [availability] The availability, if any, associated with this object.
  70. * @property {boolean} [show] A boolean value indicating if the entity and its children are displayed.
  71. * @property {TrackingReferenceFrame} [trackingReferenceFrame=TrackingReferenceFrame.AUTODETECT] The reference frame used when this entity is being tracked. <br/> If <code>undefined</code>, reference frame is determined based on entity velocity: near-surface slow moving entities are tracked using the local east-north-up reference frame, whereas fast moving entities such as satellites are tracked using VVLH (Vehicle Velocity, Local Horizontal).
  72. * @property {Property | string} [description] A string Property specifying an HTML description for this entity.
  73. * @property {PositionProperty | Cartesian3 | CallbackPositionProperty} [position] A Property specifying the entity position.
  74. * @property {Property | Quaternion} [orientation=Transforms.eastNorthUpToFixedFrame(position)] A Property specifying the entity orientation in respect to Earth-fixed-Earth-centered (ECEF). If undefined, east-north-up at entity position is used.
  75. * @property {Property | Cartesian3} [viewFrom] A suggested initial offset for viewing this object.
  76. * @property {Entity} [parent] A parent entity to associate with this entity.
  77. * @property {BillboardGraphics | BillboardGraphics.ConstructorOptions} [billboard] A billboard to associate with this entity.
  78. * @property {BoxGraphics | BoxGraphics.ConstructorOptions} [box] A box to associate with this entity.
  79. * @property {CorridorGraphics | CorridorGraphics.ConstructorOptions} [corridor] A corridor to associate with this entity.
  80. * @property {CylinderGraphics | CylinderGraphics.ConstructorOptions} [cylinder] A cylinder to associate with this entity.
  81. * @property {EllipseGraphics | EllipseGraphics.ConstructorOptions} [ellipse] A ellipse to associate with this entity.
  82. * @property {EllipsoidGraphics | EllipsoidGraphics.ConstructorOptions} [ellipsoid] A ellipsoid to associate with this entity.
  83. * @property {LabelGraphics | LabelGraphics.ConstructorOptions} [label] A options.label to associate with this entity.
  84. * @property {ModelGraphics | ModelGraphics.ConstructorOptions} [model] A model to associate with this entity.
  85. * @property {Cesium3DTilesetGraphics | Cesium3DTilesetGraphics.ConstructorOptions} [tileset] A 3D Tiles tileset to associate with this entity.
  86. * @property {PathGraphics | PathGraphics.ConstructorOptions} [path] A path to associate with this entity.
  87. * @property {PlaneGraphics | PlaneGraphics.ConstructorOptions} [plane] A plane to associate with this entity.
  88. * @property {PointGraphics | PointGraphics.ConstructorOptions} [point] A point to associate with this entity.
  89. * @property {PolygonGraphics | PolygonGraphics.ConstructorOptions} [polygon] A polygon to associate with this entity.
  90. * @property {PolylineGraphics | PolylineGraphics.ConstructorOptions} [polyline] A polyline to associate with this entity.
  91. * @property {PropertyBag | Object<string,*>} [properties] Arbitrary properties to associate with this entity.
  92. * @property {PolylineVolumeGraphics | PolylineVolumeGraphics.ConstructorOptions} [polylineVolume] A polylineVolume to associate with this entity.
  93. * @property {RectangleGraphics | RectangleGraphics.ConstructorOptions} [rectangle] A rectangle to associate with this entity.
  94. * @property {WallGraphics | WallGraphics.ConstructorOptions} [wall] A wall to associate with this entity.
  95. */
  96. /**
  97. * Entity instances aggregate multiple forms of visualization into a single high-level object.
  98. * They can be created manually and added to {@link Viewer#entities} or be produced by
  99. * data sources, such as {@link CzmlDataSource} and {@link GeoJsonDataSource}.
  100. * @alias Entity
  101. * @constructor
  102. *
  103. * @param {Entity.ConstructorOptions} [options] Object describing initialization options
  104. *
  105. * @see {@link https://cesium.com/learn/cesiumjs-learn/cesiumjs-creating-entities/|Creating Entities}
  106. */
  107. function Entity(options) {
  108. options = options ?? Frozen.EMPTY_OBJECT;
  109. let id = options.id;
  110. if (!defined(id)) {
  111. id = createGuid();
  112. }
  113. this._availability = undefined;
  114. this._id = id;
  115. this._definitionChanged = new Event();
  116. this._name = options.name;
  117. this._show = options.show ?? true;
  118. this._trackingReferenceFrame =
  119. options.trackingReferenceFrame ?? TrackingReferenceFrame.AUTODETECT;
  120. this._parent = undefined;
  121. this._propertyNames = [
  122. "billboard",
  123. "box",
  124. "corridor",
  125. "cylinder",
  126. "description",
  127. "ellipse",
  128. "ellipsoid",
  129. "label",
  130. "model",
  131. "tileset",
  132. "orientation",
  133. "path",
  134. "plane",
  135. "point",
  136. "polygon",
  137. "polyline",
  138. "polylineVolume",
  139. "position",
  140. "properties",
  141. "rectangle",
  142. "viewFrom",
  143. "wall",
  144. ...ExtraPropertyNames,
  145. ];
  146. this._billboard = undefined;
  147. this._billboardSubscription = undefined;
  148. this._box = undefined;
  149. this._boxSubscription = undefined;
  150. this._corridor = undefined;
  151. this._corridorSubscription = undefined;
  152. this._cylinder = undefined;
  153. this._cylinderSubscription = undefined;
  154. this._description = undefined;
  155. this._descriptionSubscription = undefined;
  156. this._ellipse = undefined;
  157. this._ellipseSubscription = undefined;
  158. this._ellipsoid = undefined;
  159. this._ellipsoidSubscription = undefined;
  160. this._label = undefined;
  161. this._labelSubscription = undefined;
  162. this._model = undefined;
  163. this._modelSubscription = undefined;
  164. this._tileset = undefined;
  165. this._tilesetSubscription = undefined;
  166. this._orientation = undefined;
  167. this._orientationSubscription = undefined;
  168. this._path = undefined;
  169. this._pathSubscription = undefined;
  170. this._plane = undefined;
  171. this._planeSubscription = undefined;
  172. this._point = undefined;
  173. this._pointSubscription = undefined;
  174. this._polygon = undefined;
  175. this._polygonSubscription = undefined;
  176. this._polyline = undefined;
  177. this._polylineSubscription = undefined;
  178. this._polylineVolume = undefined;
  179. this._polylineVolumeSubscription = undefined;
  180. this._position = undefined;
  181. this._positionSubscription = undefined;
  182. this._properties = undefined;
  183. this._propertiesSubscription = undefined;
  184. this._rectangle = undefined;
  185. this._rectangleSubscription = undefined;
  186. this._viewFrom = undefined;
  187. this._viewFromSubscription = undefined;
  188. this._wall = undefined;
  189. this._wallSubscription = undefined;
  190. this._children = [];
  191. /**
  192. * Gets or sets the entity collection that this entity belongs to.
  193. * @type {EntityCollection}
  194. */
  195. this.entityCollection = undefined;
  196. this.parent = options.parent;
  197. this.merge(options);
  198. }
  199. function updateShow(entity, children, isShowing) {
  200. const length = children.length;
  201. for (let i = 0; i < length; i++) {
  202. const child = children[i];
  203. const childShow = child._show;
  204. const oldValue = !isShowing && childShow;
  205. const newValue = isShowing && childShow;
  206. if (oldValue !== newValue) {
  207. updateShow(child, child._children, isShowing);
  208. }
  209. }
  210. entity._definitionChanged.raiseEvent(
  211. entity,
  212. "isShowing",
  213. isShowing,
  214. !isShowing,
  215. );
  216. }
  217. Object.defineProperties(Entity.prototype, {
  218. /**
  219. * The availability, if any, associated with this object.
  220. * If availability is undefined, it is assumed that this object's
  221. * other properties will return valid data for any provided time.
  222. * If availability exists, the objects other properties will only
  223. * provide valid data if queried within the given interval.
  224. * @memberof Entity.prototype
  225. * @type {TimeIntervalCollection|undefined}
  226. */
  227. availability: createRawPropertyDescriptor("availability"),
  228. /**
  229. * Gets the unique ID associated with this object.
  230. * @memberof Entity.prototype
  231. * @type {string}
  232. */
  233. id: {
  234. get: function () {
  235. return this._id;
  236. },
  237. },
  238. /**
  239. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  240. * @memberof Entity.prototype
  241. *
  242. * @type {Event}
  243. * @readonly
  244. */
  245. definitionChanged: {
  246. get: function () {
  247. return this._definitionChanged;
  248. },
  249. },
  250. /**
  251. * Gets or sets the name of the object. The name is intended for end-user
  252. * consumption and does not need to be unique.
  253. * @memberof Entity.prototype
  254. * @type {string|undefined}
  255. */
  256. name: createRawPropertyDescriptor("name"),
  257. /**
  258. * Gets or sets whether this entity should be displayed. When set to true,
  259. * the entity is only displayed if the parent entity's show property is also true.
  260. * @memberof Entity.prototype
  261. * @type {boolean}
  262. */
  263. show: {
  264. get: function () {
  265. return this._show;
  266. },
  267. set: function (value) {
  268. //>>includeStart('debug', pragmas.debug);
  269. if (!defined(value)) {
  270. throw new DeveloperError("value is required.");
  271. }
  272. //>>includeEnd('debug');
  273. if (value === this._show) {
  274. return;
  275. }
  276. const wasShowing = this.isShowing;
  277. this._show = value;
  278. const isShowing = this.isShowing;
  279. if (wasShowing !== isShowing) {
  280. updateShow(this, this._children, isShowing);
  281. }
  282. this._definitionChanged.raiseEvent(this, "show", value, !value);
  283. },
  284. },
  285. /**
  286. * Gets or sets the entity's tracking reference frame.
  287. * @demo {@link https://sandcastle.cesium.com/index.html?id=entity-tracking|Cesium Sandcastle Entity tracking Demo}
  288. *
  289. * @memberof Entity.prototype
  290. * @type {TrackingReferenceFrame}
  291. */
  292. trackingReferenceFrame: createRawPropertyDescriptor("trackingReferenceFrame"),
  293. /**
  294. * Gets whether this entity is being displayed, taking into account
  295. * the visibility of any ancestor entities.
  296. * @memberof Entity.prototype
  297. * @type {boolean}
  298. */
  299. isShowing: {
  300. get: function () {
  301. return (
  302. this._show &&
  303. (!defined(this.entityCollection) || this.entityCollection.show) &&
  304. (!defined(this._parent) || this._parent.isShowing)
  305. );
  306. },
  307. },
  308. /**
  309. * Gets or sets the parent object.
  310. * @memberof Entity.prototype
  311. * @type {Entity|undefined}
  312. */
  313. parent: {
  314. get: function () {
  315. return this._parent;
  316. },
  317. set: function (value) {
  318. const oldValue = this._parent;
  319. if (oldValue === value) {
  320. return;
  321. }
  322. const wasShowing = this.isShowing;
  323. if (defined(oldValue)) {
  324. const index = oldValue._children.indexOf(this);
  325. oldValue._children.splice(index, 1);
  326. }
  327. this._parent = value;
  328. if (defined(value)) {
  329. value._children.push(this);
  330. }
  331. const isShowing = this.isShowing;
  332. if (wasShowing !== isShowing) {
  333. updateShow(this, this._children, isShowing);
  334. }
  335. this._definitionChanged.raiseEvent(this, "parent", value, oldValue);
  336. },
  337. },
  338. /**
  339. * Gets the names of all properties registered on this instance.
  340. * @memberof Entity.prototype
  341. * @type {string[]}
  342. */
  343. propertyNames: {
  344. get: function () {
  345. return this._propertyNames;
  346. },
  347. },
  348. /**
  349. * Gets or sets the billboard.
  350. * @memberof Entity.prototype
  351. * @type {BillboardGraphics|undefined}
  352. */
  353. billboard: createPropertyTypeDescriptor("billboard", BillboardGraphics),
  354. /**
  355. * Gets or sets the box.
  356. * @memberof Entity.prototype
  357. * @type {BoxGraphics|undefined}
  358. */
  359. box: createPropertyTypeDescriptor("box", BoxGraphics),
  360. /**
  361. * Gets or sets the corridor.
  362. * @memberof Entity.prototype
  363. * @type {CorridorGraphics|undefined}
  364. */
  365. corridor: createPropertyTypeDescriptor("corridor", CorridorGraphics),
  366. /**
  367. * Gets or sets the cylinder.
  368. * @memberof Entity.prototype
  369. * @type {CylinderGraphics|undefined}
  370. */
  371. cylinder: createPropertyTypeDescriptor("cylinder", CylinderGraphics),
  372. /**
  373. * Gets or sets the description.
  374. * @memberof Entity.prototype
  375. * @type {Property|undefined}
  376. */
  377. description: createPropertyDescriptor("description"),
  378. /**
  379. * Gets or sets the ellipse.
  380. * @memberof Entity.prototype
  381. * @type {EllipseGraphics|undefined}
  382. */
  383. ellipse: createPropertyTypeDescriptor("ellipse", EllipseGraphics),
  384. /**
  385. * Gets or sets the ellipsoid.
  386. * @memberof Entity.prototype
  387. * @type {EllipsoidGraphics|undefined}
  388. */
  389. ellipsoid: createPropertyTypeDescriptor("ellipsoid", EllipsoidGraphics),
  390. /**
  391. * Gets or sets the label.
  392. * @memberof Entity.prototype
  393. * @type {LabelGraphics|undefined}
  394. */
  395. label: createPropertyTypeDescriptor("label", LabelGraphics),
  396. /**
  397. * Gets or sets the model.
  398. * @memberof Entity.prototype
  399. * @type {ModelGraphics|undefined}
  400. */
  401. model: createPropertyTypeDescriptor("model", ModelGraphics),
  402. /**
  403. * Gets or sets the tileset.
  404. * @memberof Entity.prototype
  405. * @type {Cesium3DTilesetGraphics|undefined}
  406. */
  407. tileset: createPropertyTypeDescriptor("tileset", Cesium3DTilesetGraphics),
  408. /**
  409. * Gets or sets the orientation in respect to Earth-fixed-Earth-centered (ECEF).
  410. * Defaults to east-north-up at entity position.
  411. * @memberof Entity.prototype
  412. * @type {Property|undefined}
  413. */
  414. orientation: createPropertyDescriptor("orientation"),
  415. /**
  416. * Gets or sets the path.
  417. * @memberof Entity.prototype
  418. * @type {PathGraphics|undefined}
  419. */
  420. path: createPropertyTypeDescriptor("path", PathGraphics),
  421. /**
  422. * Gets or sets the plane.
  423. * @memberof Entity.prototype
  424. * @type {PlaneGraphics|undefined}
  425. */
  426. plane: createPropertyTypeDescriptor("plane", PlaneGraphics),
  427. /**
  428. * Gets or sets the point graphic.
  429. * @memberof Entity.prototype
  430. * @type {PointGraphics|undefined}
  431. */
  432. point: createPropertyTypeDescriptor("point", PointGraphics),
  433. /**
  434. * Gets or sets the polygon.
  435. * @memberof Entity.prototype
  436. * @type {PolygonGraphics|undefined}
  437. */
  438. polygon: createPropertyTypeDescriptor("polygon", PolygonGraphics),
  439. /**
  440. * Gets or sets the polyline.
  441. * @memberof Entity.prototype
  442. * @type {PolylineGraphics|undefined}
  443. */
  444. polyline: createPropertyTypeDescriptor("polyline", PolylineGraphics),
  445. /**
  446. * Gets or sets the polyline volume.
  447. * @memberof Entity.prototype
  448. * @type {PolylineVolumeGraphics|undefined}
  449. */
  450. polylineVolume: createPropertyTypeDescriptor(
  451. "polylineVolume",
  452. PolylineVolumeGraphics,
  453. ),
  454. /**
  455. * Gets or sets the bag of arbitrary properties associated with this entity.
  456. * @memberof Entity.prototype
  457. * @type {PropertyBag|undefined}
  458. */
  459. properties: createPropertyTypeDescriptor("properties", PropertyBag),
  460. /**
  461. * Gets or sets the position.
  462. * @memberof Entity.prototype
  463. * @type {PositionProperty|undefined}
  464. */
  465. position: createPositionPropertyDescriptor("position"),
  466. /**
  467. * Gets or sets the rectangle.
  468. * @memberof Entity.prototype
  469. * @type {RectangleGraphics|undefined}
  470. */
  471. rectangle: createPropertyTypeDescriptor("rectangle", RectangleGraphics),
  472. /**
  473. * Gets or sets the suggested initial offset when tracking this object.
  474. * The offset is typically defined in the east-north-up reference frame,
  475. * but may be another frame depending on the object's velocity.
  476. * @memberof Entity.prototype
  477. * @type {Property|undefined}
  478. */
  479. viewFrom: createPropertyDescriptor("viewFrom"),
  480. /**
  481. * Gets or sets the wall.
  482. * @memberof Entity.prototype
  483. * @type {WallGraphics|undefined}
  484. */
  485. wall: createPropertyTypeDescriptor("wall", WallGraphics),
  486. });
  487. /**
  488. * Add the specified type and construct the properties for it in the Entity class
  489. * @private
  490. * @param {string} propertyName name of the property that controls/accesses this entity type
  491. * @param {{ constructor: function }} Type The Graphics class to associate with this entity type
  492. */
  493. Entity.registerEntityType = function (propertyName, Type) {
  494. Object.defineProperties(Entity.prototype, {
  495. [propertyName]: createPropertyTypeDescriptor(propertyName, Type),
  496. });
  497. if (!ExtraPropertyNames.includes(propertyName)) {
  498. ExtraPropertyNames.push(propertyName);
  499. }
  500. };
  501. /**
  502. * Given a time, returns true if this object should have data during that time.
  503. *
  504. * @param {JulianDate} time The time to check availability for.
  505. * @returns {boolean} true if the object should have data during the provided time, false otherwise.
  506. */
  507. Entity.prototype.isAvailable = function (time) {
  508. //>>includeStart('debug', pragmas.debug);
  509. if (!defined(time)) {
  510. throw new DeveloperError("time is required.");
  511. }
  512. //>>includeEnd('debug');
  513. const availability = this._availability;
  514. return !defined(availability) || availability.contains(time);
  515. };
  516. /**
  517. * Adds a property to this object. Once a property is added, it can be
  518. * observed with {@link Entity#definitionChanged} and composited
  519. * with {@link CompositeEntityCollection}
  520. *
  521. * @param {string} propertyName The name of the property to add.
  522. *
  523. * @exception {DeveloperError} "propertyName" is a reserved property name.
  524. * @exception {DeveloperError} "propertyName" is already a registered property.
  525. */
  526. Entity.prototype.addProperty = function (propertyName) {
  527. const propertyNames = this._propertyNames;
  528. //>>includeStart('debug', pragmas.debug);
  529. if (!defined(propertyName)) {
  530. throw new DeveloperError("propertyName is required.");
  531. }
  532. if (propertyNames.indexOf(propertyName) !== -1) {
  533. throw new DeveloperError(
  534. `${propertyName} is already a registered property.`,
  535. );
  536. }
  537. if (propertyName in this) {
  538. throw new DeveloperError(`${propertyName} is a reserved property name.`);
  539. }
  540. //>>includeEnd('debug');
  541. propertyNames.push(propertyName);
  542. Object.defineProperty(
  543. this,
  544. propertyName,
  545. createRawPropertyDescriptor(propertyName, true),
  546. );
  547. };
  548. /**
  549. * Removed a property previously added with addProperty.
  550. *
  551. * @param {string} propertyName The name of the property to remove.
  552. *
  553. * @exception {DeveloperError} "propertyName" is a reserved property name.
  554. * @exception {DeveloperError} "propertyName" is not a registered property.
  555. */
  556. Entity.prototype.removeProperty = function (propertyName) {
  557. const propertyNames = this._propertyNames;
  558. const index = propertyNames.indexOf(propertyName);
  559. //>>includeStart('debug', pragmas.debug);
  560. if (!defined(propertyName)) {
  561. throw new DeveloperError("propertyName is required.");
  562. }
  563. if (index === -1) {
  564. throw new DeveloperError(`${propertyName} is not a registered property.`);
  565. }
  566. //>>includeEnd('debug');
  567. this._propertyNames.splice(index, 1);
  568. delete this[propertyName];
  569. };
  570. /**
  571. * Assigns each unassigned property on this object to the value
  572. * of the same property on the provided source object.
  573. *
  574. * @param {Entity} source The object to be merged into this object.
  575. */
  576. Entity.prototype.merge = function (source) {
  577. //>>includeStart('debug', pragmas.debug);
  578. if (!defined(source)) {
  579. throw new DeveloperError("source is required.");
  580. }
  581. //>>includeEnd('debug');
  582. //Name, show, and availability are not Property objects and are currently handled differently.
  583. //source.show is intentionally ignored because this.show always has a value.
  584. this.name = this.name ?? source.name;
  585. this.availability = this.availability ?? source.availability;
  586. const propertyNames = this._propertyNames;
  587. const sourcePropertyNames = defined(source._propertyNames)
  588. ? source._propertyNames
  589. : Object.keys(source);
  590. const propertyNamesLength = sourcePropertyNames.length;
  591. for (let i = 0; i < propertyNamesLength; i++) {
  592. const name = sourcePropertyNames[i];
  593. //While source is required by the API to be an Entity, we internally call this method from the
  594. //constructor with an options object to configure initial custom properties.
  595. //So we need to ignore reserved-non-property.
  596. if (
  597. name === "parent" ||
  598. name === "name" ||
  599. name === "availability" ||
  600. name === "children"
  601. ) {
  602. continue;
  603. }
  604. const targetProperty = this[name];
  605. const sourceProperty = source[name];
  606. //Custom properties that are registered on the source entity must also
  607. //get registered on this entity.
  608. if (!defined(targetProperty) && propertyNames.indexOf(name) === -1) {
  609. this.addProperty(name);
  610. }
  611. if (defined(sourceProperty)) {
  612. if (defined(targetProperty)) {
  613. if (defined(targetProperty.merge)) {
  614. targetProperty.merge(sourceProperty);
  615. }
  616. } else if (
  617. defined(sourceProperty.merge) &&
  618. defined(sourceProperty.clone)
  619. ) {
  620. this[name] = sourceProperty.clone();
  621. } else {
  622. this[name] = sourceProperty;
  623. }
  624. }
  625. }
  626. };
  627. const matrix3Scratch = new Matrix3();
  628. const positionScratch = new Cartesian3();
  629. const orientationScratch = new Quaternion();
  630. /**
  631. * Computes the model matrix for the entity's transform at specified time. Returns undefined if position is undefined
  632. *
  633. * @param {JulianDate} time The time to retrieve model matrix for.
  634. * @param {Matrix4} [result] The object onto which to store the result.
  635. *
  636. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. Result is undefined if position is undefined.
  637. */
  638. Entity.prototype.computeModelMatrix = function (time, result) {
  639. //>>includeStart('debug', pragmas.debug);
  640. Check.typeOf.object("time", time);
  641. //>>includeEnd('debug');
  642. const position = Property.getValueOrUndefined(
  643. this._position,
  644. time,
  645. positionScratch,
  646. );
  647. if (!defined(position)) {
  648. return undefined;
  649. }
  650. const orientation = Property.getValueOrUndefined(
  651. this._orientation,
  652. time,
  653. orientationScratch,
  654. );
  655. if (!defined(orientation)) {
  656. result = Transforms.eastNorthUpToFixedFrame(position, undefined, result);
  657. } else {
  658. result = Matrix4.fromRotationTranslation(
  659. Matrix3.fromQuaternion(orientation, matrix3Scratch),
  660. position,
  661. result,
  662. );
  663. }
  664. return result;
  665. };
  666. /**
  667. * @private
  668. */
  669. Entity.prototype.computeModelMatrixForHeightReference = function (
  670. time,
  671. heightReferenceProperty,
  672. heightOffset,
  673. ellipsoid,
  674. result,
  675. ) {
  676. //>>includeStart('debug', pragmas.debug);
  677. Check.typeOf.object("time", time);
  678. //>>includeEnd('debug');
  679. const heightReference = Property.getValueOrDefault(
  680. heightReferenceProperty,
  681. time,
  682. HeightReference.NONE,
  683. );
  684. let position = Property.getValueOrUndefined(
  685. this._position,
  686. time,
  687. positionScratch,
  688. );
  689. if (
  690. heightReference === HeightReference.NONE ||
  691. !defined(position) ||
  692. Cartesian3.equalsEpsilon(position, Cartesian3.ZERO, CesiumMath.EPSILON8)
  693. ) {
  694. return this.computeModelMatrix(time, result);
  695. }
  696. const carto = ellipsoid.cartesianToCartographic(position, cartoScratch);
  697. if (isHeightReferenceClamp(heightReference)) {
  698. carto.height = heightOffset;
  699. } else {
  700. carto.height += heightOffset;
  701. }
  702. position = ellipsoid.cartographicToCartesian(carto, position);
  703. const orientation = Property.getValueOrUndefined(
  704. this._orientation,
  705. time,
  706. orientationScratch,
  707. );
  708. if (!defined(orientation)) {
  709. result = Transforms.eastNorthUpToFixedFrame(position, undefined, result);
  710. } else {
  711. result = Matrix4.fromRotationTranslation(
  712. Matrix3.fromQuaternion(orientation, matrix3Scratch),
  713. position,
  714. result,
  715. );
  716. }
  717. return result;
  718. };
  719. /**
  720. * Checks if the given Scene supports materials besides Color on Entities draped on terrain or 3D Tiles.
  721. * If this feature is not supported, Entities with non-color materials but no `height` will
  722. * instead be rendered as if height is 0.
  723. *
  724. * @param {Scene} scene The current scene.
  725. * @returns {boolean} Whether or not the current scene supports materials for entities on terrain.
  726. */
  727. Entity.supportsMaterialsforEntitiesOnTerrain = function (scene) {
  728. return GroundPrimitive.supportsMaterials(scene);
  729. };
  730. /**
  731. * Checks if the given Scene supports polylines clamped to terrain or 3D Tiles.
  732. * If this feature is not supported, Entities with PolylineGraphics will be rendered with vertices at
  733. * the provided heights and using the `arcType` parameter instead of clamped to the ground.
  734. *
  735. * @param {Scene} scene The current scene.
  736. * @returns {boolean} Whether or not the current scene supports polylines on terrain or 3D TIles.
  737. */
  738. Entity.supportsPolylinesOnTerrain = function (scene) {
  739. return GroundPolylinePrimitive.isSupported(scene);
  740. };
  741. export default Entity;