Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event for trackedEntity changes. #5060

Merged
merged 3 commits into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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