Skip to content

Commit

Permalink
Merge pull request #1417 from AnalyticalGraphicsInc/description
Browse files Browse the repository at this point in the history
Description property for CZML
  • Loading branch information
shunter committed Jan 29, 2014
2 parents 5b2f277 + afdc787 commit 6f752e4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Source/DynamicScene/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ define([
dynamicObject.name = defaultValue(packet.name, dynamicObject.name);
}

function processDescription(dynamicObject, packet, dynamicObjectCollection, sourceUri) {
var descriptionData = packet.description;
if (defined(descriptionData)) {
processPacketData(String, dynamicObject, 'description', descriptionData, undefined, sourceUri);
}
}

function processPosition(dynamicObject, packet, dynamicObjectCollection, sourceUri) {
var positionData = packet.position;
if (defined(positionData)) {
Expand Down Expand Up @@ -1241,6 +1248,7 @@ define([
processCone, //
processLabel, //
processName, //
processDescription, //
processPath, //
processPoint, //
processPolygon, //
Expand Down
11 changes: 9 additions & 2 deletions Source/DynamicScene/DynamicObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ define(['../Core/createGuid',
this._vertexPositions = undefined;
this._vector = undefined;
this._viewFrom = undefined;
this._description = undefined;

this._propertyChanged = new Event();
this._propertyNames = ['parent', 'position', 'orientation', 'billboard', //
'cone', 'ellipsoid', 'ellipse', 'label', 'path', 'point', 'polygon', //
'polyline', 'pyramid', 'vertexPositions', 'vector', 'viewFrom'];
'polyline', 'pyramid', 'vertexPositions', 'vector', 'viewFrom', 'description'];
};

defineProperties(DynamicObject.prototype, {
Expand Down Expand Up @@ -226,7 +227,13 @@ define(['../Core/createGuid',
* @memberof DynamicObject.prototype
* @type {DynamicVector}
*/
vector : createDynamicPropertyDescriptor('vector', '_vector')
vector : createDynamicPropertyDescriptor('vector', '_vector'),
/**
* Gets or sets the description.
* @memberof DynamicObject.prototype
* @type {Property}
*/
description : createDynamicPropertyDescriptor('description', '_description')
});

/**
Expand Down
58 changes: 58 additions & 0 deletions Source/DynamicScene/GeoJsonDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ define([
topojson) {
"use strict";

function describe(properties, nameProperty) {
var html = '<table class="cesium-geoJsonDataSourceTable">';
for ( var key in properties) {
if (properties.hasOwnProperty(key)) {
if (key === nameProperty) {
continue;
}
var value = properties[key];
if (defined(value)) {
if (typeof value === 'object') {
html += '<tr><td>' + key + '</td><td>' + describe(value) + '</td></tr>';
} else {
html += '<tr><td>' + key + '</td><td>' + value + '</td></tr>';
}
}
}
}
html += '</table>';
return html;
}

//GeoJSON specifies only the Feature object has a usable id property
//But since "multi" geometries create multiple dynamicObject,
//we can't use it for them either.
Expand All @@ -57,8 +78,45 @@ define([
}
id = finalId;
}

var dynamicObject = dynamicObjectCollection.getOrCreateObject(id);
dynamicObject.geoJson = geoJson;

var properties = geoJson.properties;
if (defined(properties)) {
//Try and find a good name for the object from its meta-data
//TODO: Make both name and description creation user-configurable.
var key;
var nameProperty;
for (key in properties) {
if (properties.hasOwnProperty(key)) {
var upperKey = key.toUpperCase();
if (upperKey === 'NAME' || upperKey === 'TITLE') {
nameProperty = key;
dynamicObject.name = properties[key];
break;
}
}
}
if (!defined(nameProperty)) {
for (key in properties) {
if (properties.hasOwnProperty(key)) {
if (/name/i.test(key) || /title/i.test(key)) {
nameProperty = key;
dynamicObject.name = properties[key];
break;
}
}
}
}

var description = describe(properties, nameProperty);
dynamicObject.description = {
getValue : function() {
return description;
}
};
}
return dynamicObject;
}

Expand Down
11 changes: 11 additions & 0 deletions Specs/DynamicScene/CzmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,17 @@ defineSuite([
expect(dynamicObject.viewFrom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0));
});

it('CZML description works.', function() {
var packet = {
description : "this is a description"
};

var dataSource = new CzmlDataSource();
dataSource.load(packet);
var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0];
expect(dynamicObject.description.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.description);
});

it('CZML Availability works with a single interval.', function() {
var packet1 = {
id : 'testObject',
Expand Down
15 changes: 15 additions & 0 deletions Specs/DynamicScene/GeoJsonDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,21 @@ defineSuite([
});
});

it('Generates description', function() {
var dataSource = new GeoJsonDataSource();
dataSource.load(topoJson);

var dynamicObjectCollection = dataSource.getDynamicObjectCollection();
waitsFor(function() {
return dynamicObjectCollection.getObjects().length === 2;
});
runs(function() {
var objects = dynamicObjectCollection.getObjects();
var polygon = objects[0];
expect(polygon.description).toBeDefined();
});
});

it('Works with geometrycollection', function() {
var dataSource = new GeoJsonDataSource();
dataSource.load(geometryCollection);
Expand Down

0 comments on commit 6f752e4

Please sign in to comment.