Skip to content

Commit

Permalink
Merge pull request #5043 from AnalyticalGraphicsInc/selectedEntityCha…
Browse files Browse the repository at this point in the history
…ngeEvent

Add viewer.selectedEntityChanged event
  • Loading branch information
lilleyse authored Feb 28, 2017
2 parents 8e395af + fbc0f0a commit 9afac5d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Change Log
* Add support for `Scene.pickPosition` in Columbus view and 2D. [#4990](https://github.com/AnalyticalGraphicsInc/cesium/pull/4990)
* Added `Label.scaleByDistance` to control minimum/maximum label size based on distance from the camera. [#5019](https://github.com/AnalyticalGraphicsInc/cesium/pull/5019)
* Add support for depth picking translucent primitives when `Scene.pickTranslucentDepth` is `true`. [#4979](https://github.com/AnalyticalGraphicsInc/cesium/pull/4979)
* Added the event `Viewer.selectedEntityChanged`, which is raised when the value of `viewer.selectedEntity` changes.

### 1.30 - 2017-02-01

Expand Down
15 changes: 15 additions & 0 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
'../../Core/defineProperties',
'../../Core/destroyObject',
'../../Core/DeveloperError',
'../../Core/Event',
'../../Core/EventHelper',
'../../Core/isArray',
'../../Core/Matrix4',
Expand Down Expand Up @@ -49,6 +50,7 @@ define([
defineProperties,
destroyObject,
DeveloperError,
Event,
EventHelper,
isArray,
Matrix4,
Expand Down Expand Up @@ -661,6 +663,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
this._zoomTarget = undefined;
this._zoomPromise = undefined;
this._zoomOptions = undefined;
this._selectedEntityChanged = new Event();

knockout.track(this, ['_trackedEntity', '_selectedEntity', '_clockTrackedDataSource']);

Expand Down Expand Up @@ -1200,9 +1203,21 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
selectionIndicatorViewModel.animateDepart();
}
}
this._selectedEntityChanged.raiseEvent(value);
}
}
},
/**
* Gets the event that is raised when the selected entity chages
* @memberof Viewer.prototype
* @type {Event}
* @readonly
*/
selectedEntityChanged : {
get : function() {
return this._selectedEntityChanged;
}
},
/**
* Gets or sets the data source to track with the viewer's clock.
* @memberof Viewer.prototype
Expand Down
24 changes: 24 additions & 0 deletions Specs/Widgets/Viewer/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,30 @@ defineSuite([
viewer.destroy();
});

it('raises an event when the selected 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.selectedEntityChanged.addEventListener(function(newSelection) {
myEntity = newSelection;
});
viewer.selectedEntity = entity;
expect(myEntity).toBe(entity);

viewer.selectedEntity = undefined;
expect(myEntity).toBeUndefined();

viewer.destroy();
});

it('selectedEntity sets InfoBox properties', function() {
var viewer = createViewer(container);

Expand Down

0 comments on commit 9afac5d

Please sign in to comment.