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