diff --git a/CHANGES.md b/CHANGES.md index 5e9611de2a5d..5bf20172e2d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,16 @@ Beta Releases * Renamed and moved `Scene.primitives.centralBody` moved to `Scene.globe`. * Removed `CesiumWidget.centralBody` and `Viewer.centralBody`. Use `Scene.globe`. * Renamed `CentralBody` to `Globe`. + * Refactored visualizers, removing `setDynamicObjectCollection`, `getDynamicObjectCollection`, `getScene`, and `removeAllPrimitives` which are all superfluous after the introduction of `DataSourceDisplay`. The affected classes are: + * `DynamicBillboardVisualizer` + * `DynamicConeVisualizerUsingCustomSensor` + * `DynamicLabelVisualizer` + * `DynamicModelVisualizer` + * `DynamicPathVisualizer` + * `DynamicPointVisualizer` + * `DynamicPyramidVisualizer` + * `DynamicVectorVisualizer` + * `GeometryVisualizer` * Renamed Extent to Rectangle * `Extent` -> `Rectangle` * `ExtentGeometry` -> `RectangleGeomtry` @@ -27,11 +37,11 @@ Beta Releases * `TilingScheme.tileXYToNativeExtent` -> `TilingScheme.tileXYToNativeRectangle` * `TilingScheme.tileXYToExtent` -> `TilingScheme.tileXYToRectangle` * Converted 'DataSource' get methods into properties. - * 'getName` -> `name` - * 'getClock` -> `clock` - * 'getChangedEvent` -> `changedEvent` - * 'getDynamicObjectCollection` -> `dynamicObjects` - * 'getErrorEvent` -> `errorEvent` + * 'getName` -> `name` + * 'getClock` -> `clock` + * 'getChangedEvent` -> `changedEvent` + * 'getDynamicObjectCollection` -> `dynamicObjects` + * 'getErrorEvent` -> `errorEvent` * `BaseLayerPicker` has been extended to support terrain selection. * The `BaseLayerPicker` constructor function now takes the container element and an options object instead of a CentralBody and ImageryLayerCollection. * The `BaseLayerPickerViewModel` constructor function now takes an options object instead of a CentralBody and ImageryLayerCollection. diff --git a/Source/DynamicScene/DynamicBillboardVisualizer.js b/Source/DynamicScene/DynamicBillboardVisualizer.js index 857e90a928b9..d013c0ed5071 100644 --- a/Source/DynamicScene/DynamicBillboardVisualizer.js +++ b/Source/DynamicScene/DynamicBillboardVisualizer.js @@ -23,7 +23,6 @@ define([ TextureAtlasBuilder) { "use strict"; - //Callback to create a callback so that we close over all of the proper values. function textureReady(dynamicObject, billboardCollection, textureValue) { return function(imageIndex) { //By the time the texture was loaded, the billboard might already be @@ -41,83 +40,41 @@ define([ } /** - * A DynamicObject visualizer which maps the DynamicBillboard instance - * in DynamicObject.billboard to a Billboard primitive. + * A {@link Visualizer} which maps {@link DynamicObject#billboard} to a {@link Billboard}. * @alias DynamicBillboardVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicBillboard - * @see DynamicObject - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicLabelVisualizer - * @see DynamicPointVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicBillboardVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); - this._scene = scene; - this._unusedIndexes = []; - this._dynamicObjectCollection = undefined; - - var billboardCollection = this._billboardCollection = new BillboardCollection(); - var atlas = this._textureAtlas = scene.createTextureAtlas(); - this._textureAtlasBuilder = new TextureAtlasBuilder(atlas); + var billboardCollection = new BillboardCollection(); + var atlas = scene.createTextureAtlas(); billboardCollection.textureAtlas = atlas; scene.primitives.add(billboardCollection); - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicBillboardVisualizer.prototype.getScene = function() { - return this._scene; - }; - - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicBillboardVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; + dynamicObjectCollection.collectionChanged.addEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this); - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicBillboardVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this); - } - } + this._scene = scene; + this._unusedIndexes = []; + this._textureAtlas = atlas; + this._billboardCollection = billboardCollection; + this._textureAtlasBuilder = new TextureAtlasBuilder(atlas); + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Updates all of the primitives created by this visualizer to match their + * Updates the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicBillboardVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -129,66 +86,36 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicBillboardVisualizer.prototype.removeAllPrimitives = function() { - if (defined(this._dynamicObjectCollection)) { - this._unusedIndexes = []; - this._billboardCollection.removeAll(); - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._billboardVisualizerIndex = undefined; - } - } - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicBillboardVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicBillboardVisualizer#destroy */ DynamicBillboardVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicBillboardVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicBillboardVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicBillboardVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this); + + var dynamicObjects = dynamicObjectCollection.getObjects(); + var length = dynamicObjects.length; + for (var i = 0; i < length; i++) { + dynamicObjects[i]._billboardVisualizerIndex = undefined; + } this._scene.primitives.remove(this._billboardCollection); return destroyObject(this); }; @@ -247,7 +174,6 @@ define([ billboard._visualizerUrl = undefined; billboard._visualizerTextureAvailable = false; - // CZML_TODO Determine official defaults billboard.color = Color.WHITE; billboard.eyeOffset = Cartesian3.ZERO; billboard.pixelOffset = Cartesian2.ZERO; @@ -369,7 +295,7 @@ define([ DynamicBillboardVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisBillboardCollection = this._billboardCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var billboardVisualizerIndex = dynamicObject._billboardVisualizerIndex; if (defined(billboardVisualizerIndex)) { diff --git a/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js b/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js index 097eb6e6ef27..95aedd0db096 100644 --- a/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js +++ b/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js @@ -29,12 +29,6 @@ define([ MaterialProperty) { "use strict"; - //CZML_TODO DynamicConeVisualizerUsingCustomSensor is a temporary workaround - //because ComplexConicSensor has major performance issues. As soon as - //ComplexConicSensor is working, this class can be deleted and - //DynamicConeVisualizer is a drop in replacement that already does things - //"the right way". - var matrix3Scratch = new Matrix3(); function assignSpherical(index, array, clock, cone) { @@ -77,79 +71,36 @@ define([ } /** - * A DynamicObject visualizer which maps the DynamicCone instance - * in DynamicObject.cone to a CustomSensor primitive. + * A {@link Visualizer} which maps {@link DynamicObject#cone} to a {@link CustomSensor}. * @alias DynamicConeVisualizerUsingCustomSensor * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicCone - * @see DynamicObject - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicLabelVisualizer - * @see DynamicPointVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicConeVisualizerUsingCustomSensor = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicConeVisualizerUsingCustomSensor.prototype._onObjectsRemoved, this); + this._scene = scene; this._unusedIndexes = []; this._primitives = scene.primitives; this._coneCollection = []; - this._dynamicObjectCollection = undefined; - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicConeVisualizerUsingCustomSensor.prototype.getScene = function() { - return this._scene; - }; - - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicConeVisualizerUsingCustomSensor.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicConeVisualizerUsingCustomSensor.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicConeVisualizerUsingCustomSensor.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicConeVisualizerUsingCustomSensor.prototype._onObjectsRemoved, this); - } - } + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Updates all of the primitives created by this visualizer to match their + * Updates the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicConeVisualizerUsingCustomSensor * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -161,72 +112,43 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicConeVisualizerUsingCustomSensor.prototype.removeAllPrimitives = function() { - var i, len; - for (i = 0, len = this._coneCollection.length; i < len; i++) { - this._primitives.remove(this._coneCollection[i]); - } - - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for (i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._coneVisualizerIndex = undefined; - } - } - - this._unusedIndexes = []; - this._coneCollection = []; - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicConeVisualizerUsingCustomSensor * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicConeVisualizerUsingCustomSensor#destroy */ DynamicConeVisualizerUsingCustomSensor.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicConeVisualizerUsingCustomSensor - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicConeVisualizerUsingCustomSensor#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicConeVisualizerUsingCustomSensor.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicConeVisualizerUsingCustomSensor.prototype._onObjectsRemoved, this); + + var i; + var dynamicObjects = dynamicObjectCollection.getObjects(); + var length = dynamicObjects.length; + for (i = 0; i < length; i++) { + dynamicObjects[i]._coneVisualizerIndex = undefined; + } + + length = this._coneCollection.length; + for (i = 0; i < length; i++) { + this._primitives.remove(this._coneCollection[i]); + } + return destroyObject(this); }; @@ -280,7 +202,6 @@ define([ dynamicObject._coneVisualizerIndex = coneVisualizerIndex; cone.id = dynamicObject; - // CZML_TODO Determine official defaults cone.material = Material.fromType(Material.ColorType); cone.intersectionColor = Color.clone(Color.YELLOW); cone.intersectionWidth = 5.0; @@ -379,7 +300,7 @@ define([ DynamicConeVisualizerUsingCustomSensor.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisConeCollection = this._coneCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var coneVisualizerIndex = dynamicObject._coneVisualizerIndex; if (defined(coneVisualizerIndex)) { diff --git a/Source/DynamicScene/DynamicLabelVisualizer.js b/Source/DynamicScene/DynamicLabelVisualizer.js index 4c0d810637e9..2fcd156f0219 100644 --- a/Source/DynamicScene/DynamicLabelVisualizer.js +++ b/Source/DynamicScene/DynamicLabelVisualizer.js @@ -24,81 +24,38 @@ define([ "use strict"; /** - * A DynamicObject visualizer which maps the DynamicLabel instance - * in DynamicObject.label to a Label primitive. + * A {@link Visualizer} which maps the {@link DynamicLabel} instance + * in {@link DynamicObject#label} to a {@link Label}. * @alias DynamicLabelVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicLabel - * @see Scene - * @see DynamicObject - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicPointVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicLabelVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); - this._scene = scene; - this._unusedIndexes = []; - this._dynamicObjectCollection = undefined; - - var labelCollection = this._labelCollection = new LabelCollection(); + var labelCollection = new LabelCollection(); scene.primitives.add(labelCollection); - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicLabelVisualizer.prototype.getScene = function() { - return this._scene; - }; + dynamicObjectCollection.collectionChanged.addEventListener(DynamicLabelVisualizer.prototype._onObjectsRemoved, this); - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicLabelVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicLabelVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicLabelVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicLabelVisualizer.prototype._onObjectsRemoved, this); - } - } + this._scene = scene; + this._unusedIndexes = []; + this._labelCollection = labelCollection; + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Updates all of the primitives created by this visualizer to match their + * Updates the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicLabelVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -110,66 +67,36 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicLabelVisualizer.prototype.removeAllPrimitives = function() { - this._unusedIndexes = []; - this._labelCollection.removeAll(); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._labelVisualizerIndex = undefined; - } - } - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicLabelVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicLabelVisualizer#destroy */ DynamicLabelVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicLabelVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicLabelVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicLabelVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicLabelVisualizer.prototype._onObjectsRemoved, this); + + var dynamicObjects = dynamicObjectCollection.getObjects(); + var length = dynamicObjects.length; + for (var i = 0; i < length; i++) { + dynamicObjects[i]._labelVisualizerIndex = undefined; + } this._scene.primitives.remove(this._labelCollection); return destroyObject(this); }; @@ -224,7 +151,6 @@ define([ dynamicObject._labelVisualizerIndex = labelVisualizerIndex; label.id = dynamicObject; - // CZML_TODO Determine official defaults label.text = ''; label.scale = 1.0; label.font = '30px sans-serif'; @@ -346,7 +272,7 @@ define([ DynamicLabelVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisLabelCollection = this._labelCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var labelVisualizerIndex = dynamicObject._labelVisualizerIndex; if (defined(labelVisualizerIndex)) { diff --git a/Source/DynamicScene/DynamicModelVisualizer.js b/Source/DynamicScene/DynamicModelVisualizer.js index 0ce0d92e8896..bc353f630aa5 100644 --- a/Source/DynamicScene/DynamicModelVisualizer.js +++ b/Source/DynamicScene/DynamicModelVisualizer.js @@ -24,67 +24,35 @@ define([ var matrix3Scratch = new Matrix3(); /** - * A {@link DynamicObject} visualizer which maps the {@link DynamicModel} instance - * in DynamicObject.model to a {@link Model} primitive. + * A {@link Visualizer} which maps {@link DynamicObject#model} to a {@link Model}. * @alias DynamicModelVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicModelVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicModelVisualizer.prototype._onObjectsRemoved, this); + this._scene = scene; this._primitives = scene.primitives; this._dynamicObjectCollection = undefined; - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicModelVisualizer.prototype.getScene = function() { - return this._scene; + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicModelVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicModelVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicModelVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicModelVisualizer.prototype._onObjectsRemoved, this); - } - } - }; - - /** - * Updates all of the primitives created by this visualizer to match their + * Updates models created this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicModelVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -96,74 +64,46 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for (var i = 0, len = dynamicObjects.length; i < len; i++) { - this._updateObject(time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + this._updateObject(time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicModelVisualizer.prototype.removeAllPrimitives = function() { - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for (var i = dynamicObjects.length - 1; i > -1; i--) { - var model = dynamicObjects[i]._modelPrimitive; - if (defined(model)) { - this._primitives.remove(model); - if (!model.isDestroyed()) { - model.destroy(); - } - model = undefined; - } - } - } - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicModelVisualizer * - * @return {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicModelVisualizer#destroy + * @returns {Boolean} True if this object was destroyed; otherwise, false. */ DynamicModelVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicModelVisualizer - * - * @return {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicModelVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicModelVisualizer.prototype.destroy = function() { - this.removeAllPrimitives(); + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = dynamicObjects.length - 1; i > -1; i--) { + var dynamicObject = dynamicObjects[i]; + var model = dynamicObject._modelPrimitive; + if (defined(model)) { + this._primitives.remove(model); + if (!model.isDestroyed()) { + model.destroy(); + } + dynamicObject._modelPrimitive = undefined; + } + } return destroyObject(this); }; + /** + * @private + */ DynamicModelVisualizer.prototype._updateObject = function(time, dynamicObject) { var context = this._scene._context; var dynamicModel = dynamicObject._model; @@ -244,6 +184,9 @@ define([ } }; + /** + * @private + */ DynamicModelVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, removed) { for (var i = removed.length - 1; i > -1; i--) { var dynamicObject = removed[i]; diff --git a/Source/DynamicScene/DynamicObject.js b/Source/DynamicScene/DynamicObject.js index a9a094ba7eb4..e29f5b81beeb 100644 --- a/Source/DynamicScene/DynamicObject.js +++ b/Source/DynamicScene/DynamicObject.js @@ -285,7 +285,7 @@ define(['../Core/createGuid', /** * Adds a property to this object. Once a property is added, it can be - * observed with {@link DynamicObject.definitionChanged} and composited + * observed with {@link DynamicObject#definitionChanged} and composited * with {@link CompositeDynamicObjectCollection} * @memberof DynamicObject * @@ -358,7 +358,7 @@ define(['../Core/createGuid', var propertyNames = this._propertyNames; var propertyNamesLength = propertyNames.length; - for ( var i = 0; i < propertyNamesLength; i++) { + for (var i = 0; i < propertyNamesLength; i++) { var name = propertyNames[i]; var targetProperty = this[name]; var sourceProperty = source[name]; diff --git a/Source/DynamicScene/DynamicPathVisualizer.js b/Source/DynamicScene/DynamicPathVisualizer.js index b17f077e2939..037dab5181a6 100644 --- a/Source/DynamicScene/DynamicPathVisualizer.js +++ b/Source/DynamicScene/DynamicPathVisualizer.js @@ -354,7 +354,6 @@ define([ dynamicObject._pathVisualizerIndex = pathVisualizerIndex; polyline.id = dynamicObject; - // CZML_TODO Determine official defaults polyline.width = 1; var material = polyline.material; if (!defined(material) || (material.type !== Material.PolylineOutlineType)) { @@ -423,78 +422,34 @@ define([ }; /** - * A DynamicObject visualizer which maps the DynamicPath instance - * in DynamicObject.path to a Polyline primitive. + * A {@link Visualizer} which maps {@link DynamicObject#path} to a {@link Polyline}. * @alias DynamicPathVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicPath - * @see Polyline - * @see DynamicObject - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicLabelVisualizer - * @see DynamicPointVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicPathVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicPathVisualizer.prototype._onObjectsRemoved, this); + this._scene = scene; this._updaters = {}; - this._dynamicObjectCollection = undefined; - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicPathVisualizer.prototype.getScene = function() { - return this._scene; - }; - - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicPathVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicPathVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicPathVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicPathVisualizer.prototype._onObjectsRemoved, this); - } - } + this._dynamicObjectCollection = dynamicObjectCollection; }; /** * Updates all of the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicPathVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -506,123 +461,94 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var updaters = this._updaters; - for ( var key in updaters) { - if (updaters.hasOwnProperty(key)) { - updaters[key].update(time); - } + var updaters = this._updaters; + for ( var key in updaters) { + if (updaters.hasOwnProperty(key)) { + updaters[key].update(time); } + } - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - var dynamicObject = dynamicObjects[i]; - - if (!defined(dynamicObject._path)) { - continue; - } - - var positionProperty = dynamicObject._position; - if (!defined(positionProperty)) { - continue; - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + var dynamicObject = dynamicObjects[i]; - var lastUpdater = dynamicObject._pathUpdater; + if (!defined(dynamicObject._path)) { + continue; + } - var frameToVisualize = ReferenceFrame.FIXED; - if (this._scene.mode === SceneMode.SCENE3D) { - frameToVisualize = positionProperty._referenceFrame; - } + var positionProperty = dynamicObject._position; + if (!defined(positionProperty)) { + continue; + } - var currentUpdater = this._updaters[frameToVisualize]; + var lastUpdater = dynamicObject._pathUpdater; - if ((lastUpdater === currentUpdater) && (defined(currentUpdater))) { - currentUpdater.updateObject(time, dynamicObject); - continue; - } + var frameToVisualize = ReferenceFrame.FIXED; + if (this._scene.mode === SceneMode.SCENE3D) { + frameToVisualize = positionProperty._referenceFrame; + } - if (defined(lastUpdater)) { - lastUpdater.removeObject(dynamicObject); - } + var currentUpdater = this._updaters[frameToVisualize]; - if (!defined(currentUpdater)) { - currentUpdater = new PolylineUpdater(this._scene, frameToVisualize); - currentUpdater.update(time); - this._updaters[frameToVisualize] = currentUpdater; - } + if ((lastUpdater === currentUpdater) && (defined(currentUpdater))) { + currentUpdater.updateObject(time, dynamicObject); + continue; + } - dynamicObject._pathUpdater = currentUpdater; - if (defined(currentUpdater)) { - currentUpdater.updateObject(time, dynamicObject); - } + if (defined(lastUpdater)) { + lastUpdater.removeObject(dynamicObject); } - } - return true; - }; - /** - * Removes all primitives from the scene. - */ - DynamicPathVisualizer.prototype.removeAllPrimitives = function() { - var updaters = this._updaters; - for ( var key in updaters) { - if (updaters.hasOwnProperty(key)) { - updaters[key].destroy(); + if (!defined(currentUpdater)) { + currentUpdater = new PolylineUpdater(this._scene, frameToVisualize); + currentUpdater.update(time); + this._updaters[frameToVisualize] = currentUpdater; } - } - this._updaters = {}; - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._pathUpdater = undefined; - dynamicObjects[i]._pathVisualizerIndex = undefined; + dynamicObject._pathUpdater = currentUpdater; + if (defined(currentUpdater)) { + currentUpdater.updateObject(time, dynamicObject); } } + return true; }; /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicPathVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicPathVisualizer#destroy */ DynamicPathVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicPathVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicPathVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicPathVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicPathVisualizer.prototype._onObjectsRemoved, this); + + var updaters = this._updaters; + for ( var key in updaters) { + if (updaters.hasOwnProperty(key)) { + updaters[key].destroy(); + } + } + + var dynamicObjects = dynamicObjectCollection.getObjects(); + var length = dynamicObjects.length; + for (var i = 0; i < length; i++) { + dynamicObjects[i]._pathUpdater = undefined; + dynamicObjects[i]._pathVisualizerIndex = undefined; + } return destroyObject(this); }; DynamicPathVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var _pathUpdater = dynamicObject._pathUpdater; if (defined(_pathUpdater)) { diff --git a/Source/DynamicScene/DynamicPointVisualizer.js b/Source/DynamicScene/DynamicPointVisualizer.js index 0255b12cf8bb..03d007c443bd 100644 --- a/Source/DynamicScene/DynamicPointVisualizer.js +++ b/Source/DynamicScene/DynamicPointVisualizer.js @@ -18,83 +18,42 @@ define([ "use strict"; /** - * A DynamicObject visualizer which maps the DynamicPoint instance - * in DynamicObject.point to a Billboard primitive with a point texture. + * A {@link Visualizer} which maps {@link DynamicObject#point} to a {@link Billboard}. * @alias DynamicPointVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicPoint - * @see Scene - * @see DynamicObject - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicLabelVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicPointVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); - this._scene = scene; - this._unusedIndexes = []; - this._dynamicObjectCollection = undefined; - var billboardCollection = this._billboardCollection = new BillboardCollection(); - var atlas = this._textureAtlas = scene.createTextureAtlas(); - this._textureAtlasBuilder = new TextureAtlasBuilder(atlas); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicPointVisualizer.prototype._onObjectsRemoved, this); + + var atlas = scene.createTextureAtlas(); + var billboardCollection = new BillboardCollection(); billboardCollection.textureAtlas = atlas; scene.primitives.add(billboardCollection); - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicPointVisualizer.prototype.getScene = function() { - return this._scene; - }; - - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicPointVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicPointVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicPointVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicPointVisualizer.prototype._onObjectsRemoved, this); - } - } + this._scene = scene; + this._unusedIndexes = []; + this._dynamicObjectCollection = dynamicObjectCollection; + this._textureAtlas = atlas; + this._billboardCollection = billboardCollection; + this._textureAtlasBuilder = new TextureAtlasBuilder(atlas); }; /** - * Updates all of the primitives created by this visualizer to match their + * Updates the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicPointVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -106,66 +65,34 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicPointVisualizer.prototype.removeAllPrimitives = function() { - this._unusedIndexes = []; - this._billboardCollection.removeAll(); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._pointVisualizerIndex = undefined; - } - } - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicPointVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicPointVisualizer#destroy */ DynamicPointVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicPointVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicPointVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicPointVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + var dynamicObjects = dynamicObjectCollection.getObjects(); + for (var i = dynamicObjects.length - 1; i > -1; i--) { + dynamicObjects[i]._pointVisualizerIndex = undefined; + } + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicPointVisualizer.prototype._onObjectsRemoved, this); this._scene.primitives.remove(this._billboardCollection); return destroyObject(this); }; @@ -216,7 +143,6 @@ define([ dynamicObject._pointVisualizerIndex = pointVisualizerIndex; billboard.id = dynamicObject; - // CZML_TODO Determine official defaults billboard._visualizerColor = Color.clone(Color.WHITE, billboard._visualizerColor); billboard._visualizerOutlineColor = Color.clone(Color.BLACK, billboard._visualizerOutlineColor); billboard._visualizerOutlineWidth = 0; @@ -330,7 +256,7 @@ define([ DynamicPointVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisBillboardCollection = this._billboardCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var pointVisualizerIndex = dynamicObject._pointVisualizerIndex; if (defined(pointVisualizerIndex)) { diff --git a/Source/DynamicScene/DynamicPyramidVisualizer.js b/Source/DynamicScene/DynamicPyramidVisualizer.js index 168752f29ec3..625014a48d1e 100644 --- a/Source/DynamicScene/DynamicPyramidVisualizer.js +++ b/Source/DynamicScene/DynamicPyramidVisualizer.js @@ -30,78 +30,36 @@ define([ var matrix3Scratch = new Matrix3(); /** - * A DynamicObject visualizer which maps the DynamicPyramid instance - * in DynamicObject.pyramid to a Pyramid primitive. + * A {@link Visualizer} which maps {@link DynamicObject#pyramid} to a {@link CustomSensorVolume}. * @alias DynamicPyramidVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicPyramid - * @see DynamicObject - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicLabelVisualizer - * @see DynamicPointVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicPyramidVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicPyramidVisualizer.prototype._onObjectsRemoved, this); + this._scene = scene; this._unusedIndexes = []; this._primitives = scene.primitives; this._pyramidCollection = []; - this._dynamicObjectCollection = undefined; - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicPyramidVisualizer.prototype.getScene = function() { - return this._scene; + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicPyramidVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicPyramidVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicPyramidVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicPyramidVisualizer.prototype._onObjectsRemoved, this); - } - } - }; - - /** - * Updates all of the primitives created by this visualizer to match their + * Updates the sensors created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicPyramidVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -113,72 +71,41 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicPyramidVisualizer.prototype.removeAllPrimitives = function() { - var i, len; - for (i = 0, len = this._pyramidCollection.length; i < len; i++) { - this._primitives.remove(this._pyramidCollection[i]); - } - - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for (i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._pyramidVisualizerIndex = undefined; - } - } - - this._unusedIndexes = []; - this._pyramidCollection = []; - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicPyramidVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicPyramidVisualizer#destroy */ DynamicPyramidVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicPyramidVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicPyramidVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicPyramidVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var i; + var length = this._pyramidCollection.length; + var primitives = this._primitives; + for (i = 0; i < length; i++) { + primitives.remove(this._pyramidCollection[i]); + } + + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + length = dynamicObjects.length; + for (i = 0; i < length; i++) { + dynamicObjects[i]._pyramidVisualizerIndex = undefined; + } + return destroyObject(this); }; @@ -237,7 +164,6 @@ define([ dynamicObject._pyramidVisualizerIndex = pyramidVisualizerIndex; pyramid.id = dynamicObject; - // CZML_TODO Determine official defaults pyramid.radius = Number.POSITIVE_INFINITY; pyramid.showIntersection = true; pyramid.intersectionColor = Color.YELLOW; @@ -297,7 +223,7 @@ define([ DynamicPyramidVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisPyramidCollection = this._pyramidCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var pyramidVisualizerIndex = dynamicObject._pyramidVisualizerIndex; if (defined(pyramidVisualizerIndex)) { diff --git a/Source/DynamicScene/DynamicVectorVisualizer.js b/Source/DynamicScene/DynamicVectorVisualizer.js index 0b3734d81b2b..3fb624eed5b9 100644 --- a/Source/DynamicScene/DynamicVectorVisualizer.js +++ b/Source/DynamicScene/DynamicVectorVisualizer.js @@ -18,80 +18,38 @@ define([ "use strict"; /** - * A DynamicObject visualizer which maps the DynamicPolyline instance - * in DynamicObject.vector to a Polyline primitive. + * A {@link Visualizer} which maps {@link DynamicObject#vector} to a {@link Polyline}. * @alias DynamicVectorVisualizer * @constructor * * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. - * - * @see DynamicPolyline - * @see DynamicObject - * @see CompositeDynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see DynamicConeVisualizer - * @see DynamicConeVisualizerUsingCustomSensor - * @see DynamicLabelVisualizer - * @see DynamicPointVisualizer - * @see DynamicPyramidVisualizer + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var DynamicVectorVisualizer = function(scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); + dynamicObjectCollection.collectionChanged.addEventListener(DynamicVectorVisualizer.prototype._onObjectsRemoved, this); + var polylineCollection = new PolylineCollection(); + scene.primitives.add(polylineCollection); + this._scene = scene; this._unusedIndexes = []; this._primitives = scene.primitives; - var polylineCollection = this._polylineCollection = new PolylineCollection(); - scene.primitives.add(polylineCollection); - this._dynamicObjectCollection = undefined; - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - - /** - * Returns the scene being used by this visualizer. - * - * @returns {Scene} The scene being used by this visualizer. - */ - DynamicVectorVisualizer.prototype.getScene = function() { - return this._scene; - }; - - /** - * Gets the DynamicObjectCollection being visualized. - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - DynamicVectorVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * - * @param dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - DynamicVectorVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(DynamicVectorVisualizer.prototype._onObjectsRemoved, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(DynamicVectorVisualizer.prototype._onObjectsRemoved, this); - } - } + this._polylineCollection = polylineCollection; + this._dynamicObjectCollection = dynamicObjectCollection; }; /** - * Updates all of the primitives created by this visualizer to match their + * Updates the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. + * @memberof DynamicVectorVisualizer * * @param {JulianDate} time The time to update to. * @returns {Boolean} This function always returns true. @@ -103,69 +61,36 @@ define([ } //>>includeEnd('debug'); - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for ( var i = 0, len = dynamicObjects.length; i < len; i++) { - updateObject(this, time, dynamicObjects[i]); - } + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = 0, len = dynamicObjects.length; i < len; i++) { + updateObject(this, time, dynamicObjects[i]); } return true; }; - /** - * Removes all primitives from the scene. - */ - DynamicVectorVisualizer.prototype.removeAllPrimitives = function() { - var i; - this._polylineCollection.removeAll(); - - if (defined(this._dynamicObjectCollection)) { - var dynamicObjects = this._dynamicObjectCollection.getObjects(); - for (i = dynamicObjects.length - 1; i > -1; i--) { - dynamicObjects[i]._vectorVisualizerIndex = undefined; - } - } - - this._unusedIndexes = []; - }; - /** * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * * @memberof DynamicVectorVisualizer * * @returns {Boolean} True if this object was destroyed; otherwise, false. - * - * @see DynamicVectorVisualizer#destroy */ DynamicVectorVisualizer.prototype.isDestroyed = function() { return false; }; /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * + * Removes and destroys all primitives created by this instance. * @memberof DynamicVectorVisualizer - * - * @returns {undefined} - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - * - * @see DynamicVectorVisualizer#isDestroyed - * - * @example - * visualizer = visualizer && visualizer.destroy(); */ DynamicVectorVisualizer.prototype.destroy = function() { - this.setDynamicObjectCollection(undefined); + var dynamicObjectCollection = this._dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.removeEventListener(DynamicVectorVisualizer.prototype._onObjectsRemoved, this); + + var dynamicObjects = this._dynamicObjectCollection.getObjects(); + for (var i = dynamicObjects.length - 1; i > -1; i--) { + dynamicObjects[i]._vectorVisualizerIndex = undefined; + } + this._scene.primitives.remove(this._polylineCollection); return destroyObject(this); }; @@ -209,7 +134,6 @@ define([ dynamicObject._vectorVisualizerIndex = vectorVisualizerIndex; polyline.id = dynamicObject; - // CZML_TODO Determine official defaults polyline.width = 1; var material = polyline.material; if (!defined(material) || (material.type !== Material.PolylineArrowType)) { @@ -251,7 +175,7 @@ define([ DynamicVectorVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) { var thisPolylineCollection = this._polylineCollection; var thisUnusedIndexes = this._unusedIndexes; - for ( var i = dynamicObjects.length - 1; i > -1; i--) { + for (var i = dynamicObjects.length - 1; i > -1; i--) { var dynamicObject = dynamicObjects[i]; var vectorVisualizerIndex = dynamicObject._vectorVisualizerIndex; if (defined(vectorVisualizerIndex)) { diff --git a/Source/DynamicScene/GeometryVisualizer.js b/Source/DynamicScene/GeometryVisualizer.js index cd33dd64b5ac..9464d124cb70 100644 --- a/Source/DynamicScene/GeometryVisualizer.js +++ b/Source/DynamicScene/GeometryVisualizer.js @@ -54,14 +54,51 @@ define(['../Core/AssociativeArray', this._dynamicUpdaters.removeAll(); }; + function removeUpdater(that, updater) { + //We don't keep track of which batch an updater is in, so just remove it from all of them. + that._outlineBatch.remove(updater); + that._closedColorBatch.remove(updater); + that._closedMaterialBatch.remove(updater); + that._openColorBatch.remove(updater); + that._openMaterialBatch.remove(updater); + that._dynamicBatch.remove(updater); + } + + function insertUpdaterIntoBatch(that, time, updater) { + if (updater.isDynamic) { + that._dynamicBatch.add(time, updater); + return; + } + + if (updater.outlineEnabled) { + that._outlineBatch.add(time, updater); + } + + if (updater.fillEnabled) { + if (updater.isClosed) { + if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { + that._closedColorBatch.add(time, updater); + } else { + that._closedMaterialBatch.add(time, updater); + } + } else { + if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { + that._openColorBatch.add(time, updater); + } else { + that._openMaterialBatch.add(time, updater); + } + } + } + } + /** - * A general purpose visualizer for all graphics that can be represented by {@link Primitive} instances. + * A general purpose visualizer for geometry represented by {@link Primitive} instances. * @alias GeometryVisualizer * @constructor * * @param {GeometryUpdater} type The updater to be used for creating the geometry. * @param {Scene} scene The scene the primitives will be rendered in. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize. + * @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize. */ var GeometryVisualizer = function(type, scene, dynamicObjectCollection) { //>>includeStart('debug', pragmas.debug); @@ -71,6 +108,9 @@ define(['../Core/AssociativeArray', if (!defined(scene)) { throw new DeveloperError('scene is required.'); } + if (!defined(dynamicObjectCollection)) { + throw new DeveloperError('dynamicObjectCollection is required.'); + } //>>includeEnd('debug'); this._type = type; @@ -92,88 +132,12 @@ define(['../Core/AssociativeArray', this._subscriptions = new AssociativeArray(); this._updaters = new AssociativeArray(); - this.setDynamicObjectCollection(dynamicObjectCollection); - }; - /** - * Returns the scene being used by this visualizer. - * @memberof GeometryVisualizer - * - * @returns {Scene} The scene being used by this visualizer. - */ - GeometryVisualizer.prototype.getScene = function() { - return this._scene; + this._dynamicObjectCollection = dynamicObjectCollection; + dynamicObjectCollection.collectionChanged.addEventListener(GeometryVisualizer.prototype._onCollectionChanged, this); + this._onCollectionChanged(dynamicObjectCollection, dynamicObjectCollection.getObjects(), emptyArray); }; - /** - * Gets the DynamicObjectCollection being visualized. - * @memberof GeometryVisualizer - * - * @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized. - */ - GeometryVisualizer.prototype.getDynamicObjectCollection = function() { - return this._dynamicObjectCollection; - }; - - /** - * Sets the DynamicObjectCollection to visualize. - * @memberof GeometryVisualizer - * - * @param {DynamicObjectCollection} dynamicObjectCollection The DynamicObjectCollection to visualizer. - */ - GeometryVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - var oldCollection = this._dynamicObjectCollection; - if (oldCollection !== dynamicObjectCollection) { - if (defined(oldCollection)) { - oldCollection.collectionChanged.removeEventListener(GeometryVisualizer.prototype._onCollectionChanged, this); - this.removeAllPrimitives(); - } - this._dynamicObjectCollection = dynamicObjectCollection; - if (defined(dynamicObjectCollection)) { - dynamicObjectCollection.collectionChanged.addEventListener(GeometryVisualizer.prototype._onCollectionChanged, this); - //Add all existing items to the collection. - this._onCollectionChanged(dynamicObjectCollection, dynamicObjectCollection.getObjects(), emptyArray); - } - } - }; - - function removeUpdater(that, updater) { - //We don't keep track of which batch an updater is in, so just remove it from all of them. - that._outlineBatch.remove(updater); - that._closedColorBatch.remove(updater); - that._closedMaterialBatch.remove(updater); - that._openColorBatch.remove(updater); - that._openMaterialBatch.remove(updater); - that._dynamicBatch.remove(updater); - } - - function insertUpdaterIntoBatch(that, time, updater) { - if (updater.isDynamic) { - that._dynamicBatch.add(time, updater); - return; - } - - if (updater.outlineEnabled) { - that._outlineBatch.add(time, updater); - } - - if (updater.fillEnabled) { - if (updater.isClosed) { - if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { - that._closedColorBatch.add(time, updater); - } else { - that._closedMaterialBatch.add(time, updater); - } - } else { - if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { - that._openColorBatch.add(time, updater); - } else { - that._openMaterialBatch.add(time, updater); - } - } - } - } - /** * Updates all of the primitives created by this visualizer to match their * DynamicObject counterpart at the given time. @@ -190,7 +154,6 @@ define(['../Core/AssociativeArray', } //>>includeEnd('debug'); - var addedObjects = this._addedObjects; var added = addedObjects.values; var removedObjects = this._removedObjects; @@ -245,10 +208,20 @@ define(['../Core/AssociativeArray', }; /** - * Removes all primitives from the scene. + * Returns true if this object was destroyed; otherwise, false. + * @memberof GeometryVisualizer + * + * @returns {Boolean} True if this object was destroyed; otherwise, false. + */ + GeometryVisualizer.prototype.isDestroyed = function() { + return false; + }; + + /** + * Removes and destroys all primitives created by this instance. * @memberof GeometryVisualizer */ - GeometryVisualizer.prototype.removeAllPrimitives = function() { + GeometryVisualizer.prototype.destroy = function() { this._addedObjects.removeAll(); this._removedObjects.removeAll(); @@ -265,34 +238,6 @@ define(['../Core/AssociativeArray', subscriptions[i](); } this._subscriptions.removeAll(); - }; - - /** - * Returns true if this object was destroyed; otherwise, false. - *

- * If this object was destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. - * @memberof GeometryVisualizer - * - * @returns {Boolean} True if this object was destroyed; otherwise, false. - */ - GeometryVisualizer.prototype.isDestroyed = function() { - return false; - }; - - /** - * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic - * release of WebGL resources, instead of relying on the garbage collector to destroy this object. - *

- * Once an object is destroyed, it should not be used; calling any function other than - * isDestroyed will result in a {@link DeveloperError} exception. Therefore, - * assign the return value (undefined) to the object as done in the example. - * @memberof GeometryVisualizer - * - * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. - */ - GeometryVisualizer.prototype.destroy = function() { - this.removeAllPrimitives(); return destroyObject(this); }; diff --git a/Source/DynamicScene/Visualizer.js b/Source/DynamicScene/Visualizer.js new file mode 100644 index 000000000000..277dd15fefb6 --- /dev/null +++ b/Source/DynamicScene/Visualizer.js @@ -0,0 +1,58 @@ +/*global define*/ +define(['../Core/DeveloperError'], function(DeveloperError) { + "use strict"; + + /** + * Defines the interface for visualizers. Visualizers are plug-ins to + * {@link DataSourceDisplay} that render data associated with + * {@link DataSource} instances. + * This object is an interface for documentation purposes and is not intended + * to be instantiated directly. + * @alias Visualizer + * @constructor + * + * @see DynamicBillboardVisualizer + * @see DynamicConeVisualizerUsingCustomSensor + * @see DynamicLabelVisualizer + * @see DynamicModelVisualizer + * @see DynamicPathVisualizer + * @see DynamicPointVisualizer + * @see DynamicPyramidVisualizer + * @see DynamicVectorVisualizer + * @see GeometryVisualizer + */ + var Visualizer = function() { + DeveloperError.throwInstantiationError(); + }; + + /** + * Updates the visualization to the provided time. + * @memberof Visualizer + * @function + * + * @param {JulianDate} time The time. + * + * @returns {Boolean} True if the display was updated to the provided time, + * false if the visualizer is waiting for an asynchronous operation to + * complete before data can be updated. + */ + Visualizer.prototype.update = DeveloperError.throwInstantiationError; + + /** + * Returns true if this object was destroyed; otherwise, false. + * @memberof Visualizer + * @function + * + * @returns {Boolean} True if this object was destroyed; otherwise, false. + */ + Visualizer.prototype.isDestroyed = DeveloperError.throwInstantiationError; + + /** + * Removes all visualization and cleans up any resources associated with this instance. + * @memberof Visualizer + * @function + */ + Visualizer.prototype.destroy = DeveloperError.throwInstantiationError; + + return Visualizer; +}); \ No newline at end of file diff --git a/Specs/DynamicScene/DataSourceDisplaySpec.js b/Specs/DynamicScene/DataSourceDisplaySpec.js index 5bf18a4706de..25ec30f1b789 100644 --- a/Specs/DynamicScene/DataSourceDisplaySpec.js +++ b/Specs/DynamicScene/DataSourceDisplaySpec.js @@ -37,26 +37,11 @@ defineSuite([ this.destroyed = false; }; - MockVisualizer.prototype.getScene = function() { - return this.scene; - }; - - MockVisualizer.prototype.getDynamicObjectCollection = function() { - return this.dynamicObjectCollection; - }; - - MockVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) { - this.dynamicObjectCollection = dynamicObjectCollection; - }; - MockVisualizer.prototype.update = function(time) { this.lastUpdateTime = time; this.updatesCalled++; }; - MockVisualizer.prototype.removeAllPrimitives = function() { - }; - MockVisualizer.prototype.isDestroyed = function() { return this.destroyed; }; diff --git a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js index 74d192597bd3..cbe215c40d68 100644 --- a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js @@ -59,11 +59,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters and adds collection to scene.', function() { + it('constructor adds collection to scene.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); var billboardCollection = scene.primitives.get(0); expect(billboardCollection instanceof BillboardCollection).toEqual(true); }); @@ -76,13 +74,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicBillboardVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicBillboardVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -289,36 +283,4 @@ defineSuite([ var bb = billboardCollection.get(0); expect(bb.id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.billboard = new DynamicBillboard(); - testObject.billboard.show = new ConstantProperty(true); - testObject.billboard.image = new ConstantProperty('Data/Images/Blue.png'); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.billboard = new DynamicBillboard(); - testObject2.billboard.show = new ConstantProperty(true); - testObject2.billboard.image = new ConstantProperty('Data/Images/Green.png'); - - visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); - - var time = new JulianDate(); - var billboardCollection = scene.primitives.get(0); - - visualizer.update(time); - expect(billboardCollection.length).toEqual(1); - var bb = billboardCollection.get(0); - expect(bb.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(billboardCollection.length).toEqual(1); - bb = billboardCollection.get(0); - expect(bb.id).toEqual(testObject2); - }); }, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js index c2cc1f975765..ea220cbdcd20 100644 --- a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js +++ b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js @@ -57,13 +57,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); - }); - it('update throws if no time specified.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); @@ -72,13 +65,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicConeVisualizerUsingCustomSensor(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicConeVisualizerUsingCustomSensor(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -252,37 +241,4 @@ defineSuite([ visualizer.update(time); expect(scene.primitives.get(0).id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); - var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new ConstantProperty(1); - cone.outerHalfAngle = new ConstantProperty(1); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.orientation = new ConstantProperty(new Quaternion(1, 0, 0, 0)); - var cone2 = testObject2.cone = new DynamicCone(); - cone2.maximumClockAngle = new ConstantProperty(0.12); - cone2.outerHalfAngle = new ConstantProperty(1.1); - - visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); - - var time = new JulianDate(); - - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - var conePrimitive = scene.primitives.get(0); - expect(conePrimitive.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - conePrimitive = scene.primitives.get(0); - expect(conePrimitive.id).toEqual(testObject2); - }); }, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js index 8578fe444357..717e52b45683 100644 --- a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js @@ -55,11 +55,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters and adds collection to scene.', function() { + it('constructor adds collection to scene.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); var labelCollection = scene.primitives.get(0); expect(labelCollection instanceof LabelCollection).toEqual(true); }); @@ -72,13 +70,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicLabelVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicLabelVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -261,36 +255,4 @@ defineSuite([ var l = labelCollection.get(0); expect(l.id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.label = new DynamicLabel(); - testObject.label.show = new ConstantProperty(true); - testObject.label.text = new ConstantProperty('lorum ipsum'); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.label = new DynamicLabel(); - testObject2.label.show = new ConstantProperty(true); - testObject2.label.text = new ConstantProperty('the quick brown'); - - visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); - - var time = new JulianDate(); - var labelCollection = scene.primitives.get(0); - - visualizer.update(time); - expect(labelCollection.length).toEqual(1); - var l = labelCollection.get(0); - expect(l.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(labelCollection.length).toEqual(1); - l = labelCollection.get(0); - expect(l.id).toEqual(testObject2); - }); }, 'WebGL'); \ No newline at end of file diff --git a/Specs/DynamicScene/DynamicModelVisualizerSpec.js b/Specs/DynamicScene/DynamicModelVisualizerSpec.js index 3e55729b0894..a914b8024432 100644 --- a/Specs/DynamicScene/DynamicModelVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicModelVisualizerSpec.js @@ -55,13 +55,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - visualizer = new DynamicModelVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); - }); - it('update throws if no time specified.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicModelVisualizer(scene, dynamicObjectCollection); @@ -70,13 +63,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicModelVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicModelVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicModelVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); diff --git a/Specs/DynamicScene/DynamicPathVisualizerSpec.js b/Specs/DynamicScene/DynamicPathVisualizerSpec.js index 3aadf6633ea5..36e06a153912 100644 --- a/Specs/DynamicScene/DynamicPathVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPathVisualizerSpec.js @@ -55,14 +55,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters and adds no primitives to scene.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); - expect(scene.primitives.length).toEqual(0); - }); - it('update throws if no time specified.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); @@ -71,13 +63,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicPathVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicPathVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -220,61 +208,6 @@ defineSuite([ expect(primitive.id).toEqual(testObject); }); - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; - var updateTime = new JulianDate(0.5, 0); - var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; - - var dynamicObjectCollection = new DynamicObjectCollection(); - visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); - - expect(scene.primitives.length).toEqual(0); - - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var position = new SampledPositionProperty(); - testObject.position = position; - position.addSamples(times, positions); - - var path = testObject.path = new DynamicPath(); - path.show = new ConstantProperty(true); - path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); - path.width = new ConstantProperty(12.5); - path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); - path.outlineWidth = new ConstantProperty(2.5); - path.leadTime = new ConstantProperty(25); - path.trailTime = new ConstantProperty(10); - - visualizer.update(updateTime); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - var position2 = new SampledPositionProperty(); - testObject2.position = position; - position2.addSamples(times, positions); - - var path2 = testObject2.path = new DynamicPath(); - path2.show = new ConstantProperty(true); - path2.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); - path2.width = new ConstantProperty(12.5); - path2.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); - path2.outlineWidth = new ConstantProperty(2.5); - path2.leadTime = new ConstantProperty(25); - path2.trailTime = new ConstantProperty(10); - - expect(scene.primitives.length).toEqual(1); - var polylineCollection = scene.primitives.get(0); - expect(polylineCollection.length).toEqual(1); - var primitive = polylineCollection.get(0); - expect(primitive.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(updateTime); - expect(scene.primitives.length).toEqual(1); - polylineCollection = scene.primitives.get(0); - primitive = polylineCollection.get(0); - expect(primitive.id).toEqual(testObject2); - }); - it('subSample works for constant properties', function() { var property = new ConstantPositionProperty(new Cartesian3(1000, 2000, 3000)); var start = new JulianDate(0, 0); diff --git a/Specs/DynamicScene/DynamicPointVisualizerSpec.js b/Specs/DynamicScene/DynamicPointVisualizerSpec.js index a94d8e474e6e..4881c148655c 100644 --- a/Specs/DynamicScene/DynamicPointVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPointVisualizerSpec.js @@ -47,11 +47,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters and adds collection to scene.', function() { + it('constructor adds collection to scene.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); expect(scene.primitives.length).toEqual(1); var billboardCollection = scene.primitives.get(0); expect(billboardCollection instanceof BillboardCollection).toEqual(true); @@ -65,13 +63,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicPointVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicPointVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -203,34 +197,4 @@ defineSuite([ var bb = billboardCollection.get(0); expect(bb.id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.point = new DynamicPoint(); - testObject.point.show = new ConstantProperty(true); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.point = new DynamicPoint(); - testObject2.point.show = new ConstantProperty(true); - - visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); - - var time = new JulianDate(); - var billboardCollection = scene.primitives.get(0); - - visualizer.update(time); - expect(billboardCollection.length).toEqual(1); - var bb = billboardCollection.get(0); - expect(bb.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(billboardCollection.length).toEqual(1); - bb = billboardCollection.get(0); - expect(bb.id).toEqual(testObject2); - }); }, 'WebGL'); \ No newline at end of file diff --git a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js index 68faee020d1b..bc5305f7ae4b 100644 --- a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js @@ -55,13 +55,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); - }); - it('update throws if no time specified.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); @@ -70,13 +63,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicPyramidVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicPyramidVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -187,35 +176,4 @@ defineSuite([ visualizer.update(time); expect(scene.primitives.get(0).id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); - var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.orientation = new ConstantProperty(new Quaternion(1, 0, 0, 0)); - var pyramid2 = testObject2.pyramid = new DynamicPyramid(); - pyramid2.directions = new ConstantProperty([new Spherical(3, 0, 0), new Spherical(2, 0, 0), new Spherical(1, 0, 0), new Spherical(0.5, 0, 0)]); - - visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); - - var time = new JulianDate(); - - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - var pyramidPrimitive = scene.primitives.get(0); - expect(pyramidPrimitive.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - pyramidPrimitive = scene.primitives.get(0); - expect(pyramidPrimitive.id).toEqual(testObject2); - }); }, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js index 988e4062f43d..18355afb26e6 100644 --- a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js @@ -53,11 +53,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('constructor sets expected parameters and adds collection to scene.', function() { + it('constructor adds collection to scene.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); - expect(visualizer.getScene()).toEqual(scene); - expect(visualizer.getDynamicObjectCollection()).toEqual(dynamicObjectCollection); expect(scene.primitives.length).toEqual(1); }); @@ -69,13 +67,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update does nothing if no dynamicObjectCollection.', function() { - visualizer = new DynamicVectorVisualizer(scene); - visualizer.update(new JulianDate()); - }); - it('isDestroy returns false until destroyed.', function() { - visualizer = new DynamicVectorVisualizer(scene); + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); expect(visualizer.isDestroyed()).toEqual(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toEqual(true); @@ -209,43 +203,4 @@ defineSuite([ var primitive = polylineCollection.get(0); expect(primitive.id).toEqual(testObject); }); - - it('setDynamicObjectCollection removes old objects and add new ones.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); - testObject.vector = new DynamicVector(); - testObject.vector.show = new ConstantProperty(true); - testObject.vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); - testObject.vector.width = new ConstantProperty(12.5); - testObject.vector.length = new ConstantProperty(13.5); - testObject.vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); - - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - testObject2.vector = new DynamicVector(); - testObject2.vector.show = new ConstantProperty(true); - testObject2.vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); - testObject2.vector.width = new ConstantProperty(12.5); - testObject2.vector.length = new ConstantProperty(13.5); - testObject2.vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); - - visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); - - var time = new JulianDate(); - - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - var polylineCollection = scene.primitives.get(0); - expect(polylineCollection.length).toEqual(1); - var primitive = polylineCollection.get(0); - expect(primitive.id).toEqual(testObject); - - visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); - expect(scene.primitives.length).toEqual(1); - primitive = polylineCollection.get(0); - expect(primitive.id).toEqual(testObject2); - }); }, 'WebGL'); diff --git a/Specs/DynamicScene/GeometryVisualizerSpec.js b/Specs/DynamicScene/GeometryVisualizerSpec.js index e749e36598e0..001cff7f61ae 100644 --- a/Specs/DynamicScene/GeometryVisualizerSpec.js +++ b/Specs/DynamicScene/GeometryVisualizerSpec.js @@ -50,22 +50,14 @@ defineSuite(['DynamicScene/GeometryVisualizer', destroyScene(scene); }); - it('Constructor sets expected values', function() { + it('Can create and destroy', function() { var objects = new DynamicObjectCollection(); var visualizer = new GeometryVisualizer(EllipseGeometryUpdater, scene, objects); - expect(visualizer.getScene()).toBe(scene); - expect(visualizer.getDynamicObjectCollection()).toBe(objects); expect(visualizer.update(time)).toBe(true); expect(scene.primitives.length).toBe(0); expect(visualizer.isDestroyed()).toBe(false); visualizer.destroy(); expect(visualizer.isDestroyed()).toBe(true); - - visualizer = new GeometryVisualizer(EllipseGeometryUpdater, scene); - expect(visualizer.getDynamicObjectCollection()).toBeUndefined(); - expect(visualizer.update(time)).toBe(true); - expect(scene.primitives.length).toBe(0); - visualizer.destroy(); }); it('Creates and removes static color open geometry', function() { @@ -384,4 +376,4 @@ defineSuite(['DynamicScene/GeometryVisualizer', visualizer.update(undefined); }).toThrowDeveloperError(); }); -}, 'WebGL'); \ No newline at end of file +}, 'WebGL');