123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- define([
- '../Core/Cartesian3',
- '../Core/createGuid',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- '../Core/Event',
- '../Core/Matrix3',
- '../Core/Matrix4',
- '../Core/Quaternion',
- '../Core/Transforms',
- './createPropertyDescriptor',
- './Property'
- ], function(
- Cartesian3,
- createGuid,
- defaultValue,
- defined,
- defineProperties,
- DeveloperError,
- Event,
- Matrix3,
- Matrix4,
- Quaternion,
- Transforms,
- createPropertyDescriptor,
- Property) {
- "use strict";
-
- var Entity = function(id) {
- if (!defined(id)) {
- id = createGuid();
- }
- this._availability = undefined;
- this._id = id;
- this._definitionChanged = new Event();
- this._name = undefined;
- this._parent = undefined;
- this._propertyNames = ['billboard', 'box', 'corridor', 'cylinder', 'description', 'ellipse',
- 'ellipsoid', 'label', 'model', 'orientation', 'path', 'point', 'polygon',
- 'polyline', 'position', 'rectangle', 'viewFrom', 'wall'];
- 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._orientation = undefined;
- this._orientationSubscription = undefined;
- this._path = undefined;
- this._pathSubscription = undefined;
- this._point = undefined;
- this._pointSubscription = undefined;
- this._polygon = undefined;
- this._polygonSubscription = undefined;
- this._polyline = undefined;
- this._polylineSubscription = undefined;
- this._position = undefined;
- this._positionSubscription = undefined;
- this._rectangle = undefined;
- this._rectangleSubscription = undefined;
- this._viewFrom = undefined;
- this._viewFromSubscription = undefined;
- this._wall = undefined;
- this._wallSubscription = undefined;
- };
- defineProperties(Entity.prototype, {
-
- availability : createPropertyDescriptor('availability'),
-
- id : {
- get : function() {
- return this._id;
- }
- },
-
- definitionChanged : {
- get : function() {
- return this._definitionChanged;
- }
- },
-
- name : {
- configurable : false,
- get : function() {
- return this._name;
- },
- set : function(value) {
- var oldValue = this._name;
- if (oldValue !== value) {
- this._name = value;
- this._definitionChanged.raiseEvent(this, 'name', value, oldValue);
- }
- }
- },
-
- parent : createPropertyDescriptor('parent'),
-
- propertyNames : {
- get : function() {
- return this._propertyNames;
- }
- },
-
- billboard : createPropertyDescriptor('billboard'),
-
- box : createPropertyDescriptor('box'),
-
- corridor : createPropertyDescriptor('corridor'),
-
- cylinder : createPropertyDescriptor('cylinder'),
-
- description : createPropertyDescriptor('description'),
-
- ellipse : createPropertyDescriptor('ellipse'),
-
- ellipsoid : createPropertyDescriptor('ellipsoid'),
-
- label : createPropertyDescriptor('label'),
-
- model : createPropertyDescriptor('model'),
-
- orientation : createPropertyDescriptor('orientation'),
-
- path : createPropertyDescriptor('path'),
-
- point : createPropertyDescriptor('point'),
-
- polygon : createPropertyDescriptor('polygon'),
-
- polyline : createPropertyDescriptor('polyline'),
-
- position : createPropertyDescriptor('position'),
-
- rectangle : createPropertyDescriptor('rectangle'),
-
- viewFrom : createPropertyDescriptor('viewFrom'),
-
- wall : createPropertyDescriptor('wall')
- });
-
- Entity.prototype.isAvailable = function(time) {
-
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
-
- var availability = this._availability;
- return !defined(availability) || availability.contains(time);
- };
-
- Entity.prototype.addProperty = function(propertyName) {
- var propertyNames = this._propertyNames;
-
- 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.');
- }
-
- propertyNames.push(propertyName);
- Object.defineProperty(this, propertyName, createPropertyDescriptor(propertyName, true));
- };
-
- Entity.prototype.removeProperty = function(propertyName) {
- var propertyNames = this._propertyNames;
-
- if (!defined(propertyName)) {
- throw new DeveloperError('propertyName is required.');
- }
- if (propertyNames.indexOf(propertyName) === -1) {
- throw new DeveloperError(propertyName + ' is not a registered property.');
- }
-
- this._propertyNames.push(propertyName);
- delete this[propertyName];
- };
-
- Entity.prototype.merge = function(source) {
-
- if (!defined(source)) {
- throw new DeveloperError('source is required.');
- }
-
-
- this.name = defaultValue(this.name, source.name);
- this.availability = defaultValue(source.availability, this.availability);
- var propertyNames = this._propertyNames;
- var sourcePropertyNames = source._propertyNames;
- var propertyNamesLength = sourcePropertyNames.length;
- for (var i = 0; i < propertyNamesLength; i++) {
- var name = sourcePropertyNames[i];
- var targetProperty = this[name];
- var sourceProperty = source[name];
-
-
- 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;
- }
- }
- }
- };
- var matrix3Scratch = new Matrix3();
- var positionScratch = new Cartesian3();
- var orientationScratch = new Quaternion();
-
- Entity.prototype._getModelMatrix = function(time, result) {
- var position = Property.getValueOrUndefined(this._position, time, positionScratch);
- if (!defined(position)) {
- return undefined;
- }
- var 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;
- };
- return Entity;
- });
|