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

Support for Entity.show #2600

Merged
merged 5 commits into from
Mar 25, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions Apps/Sandcastle/gallery/Custom DataSource.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@
set : function(value) {
this._seriesToDisplay = value;

//Iterate over all polylines and set their show property
//Iterate over all entities and set their show property
//to true only if they are part of the current series.
var collection = this._entityCollection;
var entities = collection.values;
collection.suspendEvents();
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
entity.polyline.show.setValue(value === entity.seriesName);
entity.show = value === entity.seriesName;
}
collection.resumeEvents();
}
Expand Down Expand Up @@ -287,7 +287,6 @@

//WebGL Globe only contains lines, so that's the only graphics we create.
var polyline = new Cesium.PolylineGraphics();
polyline.show = new Cesium.ConstantProperty(show);
polyline.material = new Cesium.ColorMaterialProperty(color);
polyline.width = new Cesium.ConstantProperty(2);
polyline.followSurface = new Cesium.ConstantProperty(false);
Expand All @@ -296,6 +295,7 @@
//The polyline instance itself needs to be on an entity.
var entity = new Cesium.Entity({
id : seriesName + ' index ' + i.toString(),
show : show,
polyline : polyline,
seriesName : seriesName //Custom property to indicate series name
});
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/BillboardVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ define([
var billboardGraphics = entity._billboard;
var textureValue;
var billboard = item.billboard;
var show = entity.isAvailable(time) && Property.getValueOrDefault(billboardGraphics._show, time, true);
var show = entity.isAvailableAndShowing(time) && Property.getValueOrDefault(billboardGraphics._show, time, true);

if (show) {
position = Property.getValueOrUndefined(entity._position, time, position);
Expand Down
102 changes: 94 additions & 8 deletions Source/DataSources/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ define([
this._id = id;
this._definitionChanged = new Event();
this._name = undefined;
this._show = true;
this._parent = options.parent;
this._propertyNames = ['billboard', 'box', 'corridor', 'cylinder', 'description', 'ellipse', //
'ellipsoid', 'label', 'model', 'orientation', 'path', 'point', 'polygon', //
Expand Down Expand Up @@ -176,10 +177,26 @@ define([
this._viewFromSubscription = undefined;
this._wall = undefined;
this._wallSubscription = undefined;
this._children = [];

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
};

function updateShow(entity, isShowing) {
var children = entity._children;
var length = children.length;
for (var i = 0; i < length; i++) {
var child = children[i];
var childShow = child._show;
var oldValue = !isShowing && childShow;
var newValue = isShowing && childShow;
if (oldValue !== newValue) {
child._definitionChanged.raiseEvent(child, 'isShowing', newValue, oldValue);
}
}
entity._definitionChanged.raiseEvent(entity, 'isShowing', isShowing, !isShowing);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be super old, but whenever you're passing 'isShowing' as a param inside of this function.. aren't you expecting to set the 'isShowing' property on the 'entity' object? The issue this raises is that the entity object only has a 'get' method defined but no set method for 'isShowing'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue occurs when dealing with entities from the CompositeEntityCollection. Its own CompositeEntityCollection.prototype._onDefinitionChanged throws an error whenever " entity._definitionChanged.raiseEvent(entity, 'isShowing', isShowing, !isShowing)" event is raised

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sceptre12 if you can reproduce this issue/error in a Sandcastle example, please open a new GitHub issue for it.

}

defineProperties(Entity.prototype, {
/**
* The availability, if any, associated with this object.
Expand Down Expand Up @@ -219,25 +236,84 @@ define([
* @memberof Entity.prototype
* @type {String}
*/
name : {
configurable : false,
name : createRawPropertyDescriptor('name'),
/**
* Gets or sets the name of the object. The name is intended for end-user
* consumption and does not need to be unique.
* @memberof Entity.prototype
* @type {Boolean}
*/
show : {
get : function() {
return this._name;
return this._show;
},
set : function(value) {
var oldValue = this._name;
if (oldValue !== value) {
this._name = value;
this._definitionChanged.raiseEvent(this, 'name', value, oldValue);
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required.');
}
//>>includeEnd('debug');

if (value === this._show) {
return;
}

var wasShowing = this.isShowing;
this._show = value;
var isShowing = this.isShowing;

if (wasShowing !== isShowing) {
updateShow(this, isShowing);
}

this._definitionChanged.raiseEvent(this, 'show', value, !value);
}
},
/**
* Gets or sets the name of the object. The name is intended for end-user
* consumption and does not need to be unique.
* @memberof Entity.prototype
* @type {Boolean}
*/
isShowing : {
get : function() {
return this._show && (!defined(this._parent) || this._parent._show);
}
},
/**
* Gets or sets the parent object.
* @memberof Entity.prototype
* @type {Entity}
*/
parent : createRawPropertyDescriptor('parent'),
parent : {
get : function() {
return this._parent;
},
set : function(value) {
var oldValue = this._parent;

if (oldValue === value) {
return;
}

var wasShowing = this.isShowing;
if (defined(oldValue)) {
var index = oldValue._children.indexOf(this);
oldValue._children.splice(index, 1);
}

this._parent = value;
value._children.push(value);

var isShowing = this.isShowing;

if (wasShowing !== isShowing) {
updateShow(this, isShowing);
}

this._definitionChanged.raiseEvent(this, 'parent', value, oldValue);
}
},
/**
* Gets the names of all properties registered on this instance.
* @memberof Entity.prototype
Expand Down Expand Up @@ -382,6 +458,16 @@ define([
return !defined(availability) || availability.contains(time);
};

/**
* Given a time, returns true if this entity should be displayed at that time.
*
* @param {JulianDate} time The time to check availability for.
* @returns true if this entity should be displayed during the provided time, false otherwise.
*/
Entity.prototype.isAvailableAndShowing = function(time) {
return this._show && this.isAvailable(time) && (!defined(this._parent) || this._parent.isAvailableAndShowing(time));
};

/**
* Adds a property to this object. Once a property is added, it can be
* observed with {@link Entity#definitionChanged} and composited
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/LabelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ define([
var labelGraphics = entity._label;
var text;
var label = item.label;
var show = entity.isAvailable(time) && Property.getValueOrDefault(labelGraphics._show, time, true);
var show = entity.isAvailableAndShowing(time) && Property.getValueOrDefault(labelGraphics._show, time, true);

if (show) {
position = Property.getValueOrUndefined(entity._position, time, position);
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ define([

var uri;
var modelData = modelHash[entity.id];
var show = entity.isAvailable(time) && Property.getValueOrDefault(modelGraphics._show, time, true);
var show = entity.isAvailableAndShowing(time) && Property.getValueOrDefault(modelGraphics._show, time, true);

var modelMatrix;
if (show) {
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/PathVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ define([
var sampleStop;
var showProperty = pathGraphics._show;
var polyline = item.polyline;
var show = !defined(showProperty) || showProperty.getValue(time);
var show = entity.isAvailableAndShowing(time) && (!defined(showProperty) || showProperty.getValue(time));

//While we want to show the path, there may not actually be anything to show
//depending on lead/trail settings. Compute the interval of the path to
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/PointVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ define([
var entity = item.entity;
var pointGraphics = entity._point;
var billboard = item.billboard;
var show = entity.isAvailable(time) && Property.getValueOrDefault(pointGraphics._show, time, true);
var show = entity.isAvailableAndShowing(time) && Property.getValueOrDefault(pointGraphics._show, time, true);
if (show) {
position = Property.getValueOrUndefined(entity._position, time, position);
show = defined(position);
Expand Down
42 changes: 40 additions & 2 deletions Source/DataSources/StaticGeometryColorBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ define([
this.updaters = new AssociativeArray();
this.updatersWithAttributes = new AssociativeArray();
this.attributes = new AssociativeArray();
this.subscriptions = new AssociativeArray();
this.showsUpdated = new AssociativeArray();
this.itemsToRemove = [];
};

Expand All @@ -41,14 +43,27 @@ define([
this.updaters.set(id, updater);
if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant) {
this.updatersWithAttributes.set(id, updater);
} else {
var that = this;
this.subscriptions.set(id, updater.entity.definitionChanged.addEventListener(function(entity, propertyName, newValue, oldValue) {
if (propertyName === 'isShowing') {
that.showsUpdated.set(entity.id, updater);
}
}));
}
};

Batch.prototype.remove = function(updater) {
var id = updater.entity.id;
this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;
this.updaters.remove(id);
this.updatersWithAttributes.remove(id);
if (this.updaters.remove(id)) {
this.updatersWithAttributes.remove(id);
var unsubscribe = this.subscriptions.get(id);
if (defined(unsubscribe)) {
unsubscribe();
this.subscriptions.remove(id);
}
}
};

Batch.prototype.update = function(time) {
Expand Down Expand Up @@ -117,13 +132,36 @@ define([
}
}
}

this.updateShows(primitive);
} else if (defined(primitive) && !primitive.ready) {
isUpdated = false;
}
this.itemsToRemove.length = removedCount;
return isUpdated;
};

Batch.prototype.updateShows = function(primitive) {
var showsUpdated = this.showsUpdated.values;
var length = showsUpdated.length;
for (var i = 0; i < length; i++) {
var updater = showsUpdated[i];
var instance = this.geometry.get(updater.entity.id);

var attributes = this.attributes.get(instance.id.id);
if (!defined(attributes)) {
attributes = primitive.getGeometryInstanceAttributes(instance.id);
this.attributes.set(instance.id.id, attributes);
}

var show = updater.entity.isShowing;
var currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
attributes.show = ShowGeometryInstanceAttribute.toValue(show, attributes.show);
}
}
};

Batch.prototype.contains = function(entity) {
return this.updaters.contains(entity.id);
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
var selectedEntity = this.selectedEntity;
var showSelection = defined(selectedEntity) && this._enableInfoOrSelection;

if (showSelection && selectedEntity.isAvailable(time)) {
if (showSelection && selectedEntity.isAvailableAndShowing(time)) {
var state = this._dataSourceDisplay.getBoundingSphere(selectedEntity, true, boundingSphereScratch);
if (state !== BoundingSphereState.FAILED) {
position = boundingSphereScratch.center;
Expand Down