From ef19aec94ab80831a9ac4a724e950994572e9703 Mon Sep 17 00:00:00 2001 From: Ed Mackey Date: Wed, 1 Mar 2017 16:48:33 -0500 Subject: [PATCH 1/2] Add event for trackedEntity changes. Code stolen from @hpinkos selectedEntityChanged event. --- Source/Widgets/Viewer/Viewer.js | 21 +++++++++++++++++---- Specs/Widgets/Viewer/ViewerSpec.js | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index ec559ffe581b..3fd5049fe410 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -664,6 +664,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to this._zoomPromise = undefined; this._zoomOptions = undefined; this._selectedEntityChanged = new Event(); + this._trackedEntityChanged = new Event(); knockout.track(this, ['_trackedEntity', '_selectedEntity', '_clockTrackedDataSource']); @@ -1171,12 +1172,13 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to this._entityView = undefined; this.camera.lookAtTransform(Matrix4.IDENTITY); - return; + } else { + //We can't start tracking immediately, so we set a flag and start tracking + //when the bounding sphere is ready (most likely next frame). + this._needTrackedEntityUpdate = true; } - //We can't start tracking immediately, so we set a flag and start tracking - //when the bounding sphere is ready (most likely next frame). - this._needTrackedEntityUpdate = true; + this._trackedEntityChanged.raiseEvent(value); } } }, @@ -1218,6 +1220,17 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to return this._selectedEntityChanged; } }, + /** + * Gets the event that is raised when the tracked entity chages + * @memberof Viewer.prototype + * @type {Event} + * @readonly + */ + trackedEntityChanged : { + get : function() { + return this._trackedEntityChanged; + } + }, /** * Gets or sets the data source to track with the viewer's clock. * @memberof Viewer.prototype diff --git a/Specs/Widgets/Viewer/ViewerSpec.js b/Specs/Widgets/Viewer/ViewerSpec.js index b07e33146e95..9b91922c4b87 100644 --- a/Specs/Widgets/Viewer/ViewerSpec.js +++ b/Specs/Widgets/Viewer/ViewerSpec.js @@ -33,7 +33,7 @@ defineSuite([ 'Widgets/SceneModePicker/SceneModePicker', 'Widgets/SelectionIndicator/SelectionIndicator', 'Widgets/Timeline/Timeline' - ], function( + ], 'Widgets/Viewer/Viewer', function( Cartesian3, ClockRange, ClockStep, @@ -850,6 +850,30 @@ defineSuite([ viewer.destroy(); }); + it('raises an event when the tracked entity changes', function() { + var viewer = createViewer(container); + + var dataSource = new MockDataSource(); + viewer.dataSources.add(dataSource); + + var entity = new Entity(); + entity.position = new ConstantPositionProperty(new Cartesian3(123456, 123456, 123456)); + + dataSource.entities.add(entity); + + var myEntity; + viewer.trackedEntityChanged.addEventListener(function(newValue) { + myEntity = newValue; + }); + viewer.trackedEntity = entity; + expect(myEntity).toBe(entity); + + viewer.trackedEntity = undefined; + expect(myEntity).toBeUndefined(); + + viewer.destroy(); + }); + it('selectedEntity sets InfoBox properties', function() { var viewer = createViewer(container); From 0a8f549e55eddaa9312abeeb5d0eed11ef4e4715 Mon Sep 17 00:00:00 2001 From: Ed Mackey Date: Wed, 1 Mar 2017 16:51:15 -0500 Subject: [PATCH 2/2] CHANGES.md --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 93c047450e90..fa3560ce6cd2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ Change Log ========== +### 1.32 - 2017-04-03 + +* Added the event `Viewer.trackedEntityChanged`, which is raised when the value of `viewer.trackedEntity` changes. [#5060](https://github.com/AnalyticalGraphicsInc/cesium/pull/5060) + ### 1.31 - 2017-03-01 * Deprecated