Skip to content

Commit

Permalink
Merge pull request #5060 from AnalyticalGraphicsInc/trackedEntityChan…
Browse files Browse the repository at this point in the history
…gedEvent

Add event for trackedEntity changes.
  • Loading branch information
Hannah authored Mar 2, 2017
2 parents 9687c3e + 2544dab commit 06d23f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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)
* Fix crunch compressed textures in IE11. [#5057](https://github.com/AnalyticalGraphicsInc/cesium/pull/5057)

### 1.31 - 2017-03-01
Expand Down
21 changes: 17 additions & 4 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down Expand Up @@ -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);
}
}
},
Expand Down Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion Specs/Widgets/Viewer/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defineSuite([
'Widgets/SceneModePicker/SceneModePicker',
'Widgets/SelectionIndicator/SelectionIndicator',
'Widgets/Timeline/Timeline'
], function(
], 'Widgets/Viewer/Viewer', function(
Cartesian3,
ClockRange,
ClockStep,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 06d23f1

Please sign in to comment.