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

Update InfoBox title when entity name changes #2644

Merged
merged 1 commit into from
Apr 17, 2015
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
52 changes: 18 additions & 34 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ define([
'../../DataSources/DataSourceDisplay',
'../../DataSources/Entity',
'../../DataSources/EntityView',
'../../DataSources/Property',
'../../Scene/SceneMode',
'../../ThirdParty/knockout',
'../../ThirdParty/when',
Expand Down Expand Up @@ -57,6 +58,7 @@ define([
DataSourceDisplay,
Entity,
EntityView,
Property,
SceneMode,
knockout,
when,
Expand Down Expand Up @@ -126,12 +128,10 @@ define([
}

// Imagery layer feature picking is asynchronous, so put up a message while loading.
var loadingMessage = new Entity('Loading...');
loadingMessage.description = {
getValue : function() {
return 'Loading feature information...';
}
};
var loadingMessage = new Entity({
id : 'Loading...',
description : 'Loading feature information...'
});

when(imageryLayerFeaturePromise, function(features) {
// Has this async pick been superseded by a later one?
Expand All @@ -147,12 +147,10 @@ define([
// Select the first feature.
var feature = features[0];

var entity = new Entity(feature.name);
entity.description = {
getValue : function() {
return feature.description;
}
};
var entity = new Entity({
id : feature.name,
description : feature.description
});

if (defined(feature.position)) {
var ecfPosition = viewer.scene.globe.ellipsoid.cartographicToCartesian(feature.position, cartesian3Scratch);
Expand All @@ -165,28 +163,17 @@ define([
if (viewer.selectedEntity !== loadingMessage) {
return;
}

var entity = new Entity('None');
entity.description = {
getValue : function() {
return 'No features found.';
}
};

viewer.selectedEntity = createNoFeaturesEntity();
});

return loadingMessage;
}

function createNoFeaturesEntity() {
var entity = new Entity('None');
entity.description = {
getValue : function() {
return 'No features found.';
}
};
return entity;
return new Entity({
id : 'None',
description : 'No features found.'
});
}

/**
Expand Down Expand Up @@ -1024,11 +1011,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
this._selectedEntity = value;
var selectionIndicatorViewModel = defined(this._selectionIndicator) ? this._selectionIndicator.viewModel : undefined;
if (defined(value)) {
var infoBoxViewModel = defined(this._infoBox) ? this._infoBox.viewModel : undefined;
if (defined(infoBoxViewModel)) {
infoBoxViewModel.titleText = defined(value.name) ? value.name : value.id;
}

if (defined(selectionIndicatorViewModel)) {
selectionIndicatorViewModel.animateAppear();
}
Expand Down Expand Up @@ -1336,9 +1318,11 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
infoBoxViewModel.enableCamera = enableCamera;
infoBoxViewModel.isCameraTracking = (this.trackedEntity === this.selectedEntity);

if (showSelection && defined(selectedEntity.description)) {
infoBoxViewModel.description = defaultValue(selectedEntity.description.getValue(time), '');
if (showSelection) {
infoBoxViewModel.titleText = defaultValue(selectedEntity.name, selectedEntity.id);
infoBoxViewModel.description = Property.getValueOrDefault(selectedEntity.description, time, '');
} else {
infoBoxViewModel.titleText = '';
infoBoxViewModel.description = '';
}
}
Expand Down
33 changes: 33 additions & 0 deletions Specs/Widgets/Viewer/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,39 @@ defineSuite([
viewer.destroy();
});

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

var entity = new Entity();

var viewModel = viewer.infoBox.viewModel;
expect(viewModel.showInfo).toBe(false);

viewer.selectedEntity = entity;

viewer.clock.tick();
expect(viewModel.showInfo).toBe(true);
expect(viewModel.titleText).toEqual(entity.id);
expect(viewModel.description).toEqual('');

entity.name = 'Yes, this is name.';
entity.description = 'tubelcane';

viewer.clock.tick();
expect(viewModel.showInfo).toBe(true);
expect(viewModel.titleText).toEqual(entity.name);
expect(viewModel.description).toEqual(entity.description.getValue());

viewer.selectedEntity = undefined;

viewer.clock.tick();
expect(viewModel.showInfo).toBe(false);
expect(viewModel.titleText).toEqual('');
expect(viewModel.description).toEqual('');

viewer.destroy();
});

it('home button resets tracked object', function() {
viewer = new Viewer(container);

Expand Down