diff --git a/Apps/Sandcastle/gallery/CZML Polygon - Interpolating References.html b/Apps/Sandcastle/gallery/CZML Polygon - Interpolating References.html index 3adf3c856e2d..a1d962242998 100644 --- a/Apps/Sandcastle/gallery/CZML Polygon - Interpolating References.html +++ b/Apps/Sandcastle/gallery/CZML Polygon - Interpolating References.html @@ -95,6 +95,70 @@ 3600, -45, 65, 3000 ] } +}, { + "id": "Polygon with Dynamic Holes", + "polygon": { + "positions": { + "cartographicDegrees" : [ + -110, 43, 0, + -90, 43, 0, + -90, 30, 0, + -110, 30, 0 + ] + }, + "holes": { + references: [ + [ + 'target4#position', + 'target5#position', + 'target6#position' + ] + ] + }, + "material": { + "solidColor": { + "color": { + "rgba" : [255, 150, 0, 255] + } + } + } + } +},{ + "id": "target4", + "position": { + "interpolationAlgorithm": "LINEAR", + "interpolationDegree": 1, + "interval" : "2012-08-04T16:00:00Z/2012-08-04T17:00:00Z", + "epoch" : "2012-08-04T16:00:00Z", + "cartographicDegrees": [ + 0, -100, 41, 0, + 3600, -95, 41, 0 + ] + } +},{ + "id": "target5", + "position": { + "interpolationAlgorithm": "LINEAR", + "interpolationDegree": 1, + "interval" : "2012-08-04T16:00:00Z/2012-08-04T17:00:00Z", + "epoch" : "2012-08-04T16:00:00Z", + "cartographicDegrees": [ + 0, -92, 42, 0, + 3600, -92, 36, 0 + ] + } +},{ + "id": "target6", + "position": { + "interpolationAlgorithm": "LINEAR", + "interpolationDegree": 1, + "interval" : "2012-08-04T16:00:00Z/2012-08-04T17:00:00Z", + "epoch" : "2012-08-04T16:00:00Z", + "cartographicDegrees": [ + 0, -95, 37, 0, + 3600, -108, 38, 0 + ] + } }]; var viewer = new Cesium.Viewer('cesiumContainer', { diff --git a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html index 51b0a9ff2058..9b4206a8c0d4 100644 --- a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html +++ b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html @@ -66,6 +66,16 @@ -35, 20, 0 ] }], + "holes": [{ + "interval" : "2012-08-04T16:00:00Z/2012-08-04T16:20:00Z", + "cartographicDegrees" : [ + [ + -47, 35, 0, + -46, 25, 0, + -42, 30, 0 + ] + ] + }], "material": { "solidColor": { "color": [{ diff --git a/Apps/Sandcastle/gallery/CZML Polygon.html b/Apps/Sandcastle/gallery/CZML Polygon.html index 310764e85276..b8fb1ca055f8 100644 --- a/Apps/Sandcastle/gallery/CZML Polygon.html +++ b/Apps/Sandcastle/gallery/CZML Polygon.html @@ -125,6 +125,41 @@ "rgba" : [0, 0, 0, 255] } } +}, { + "id" : "bluePolygonWithHoles", + "name" : "Blue polygon with holes", + "polygon" : { + "positions" : { + "cartographicDegrees" : [ + -82.0, 40.8, 0, + -83.0, 36.5, 0, + -76.0, 35.6, 0, + -73.5, 43.6, 0 + ] + }, + "holes" : { + "cartographicDegrees" : [ + [ + -81.0, 40.0, 0, + -81.0, 38.2, 0, + -79.0, 38.2, 0, + -78.0, 40.8, 0 + ], + [ + -77.5, 36.7, 0, + -78.5, 37.0, 0, + -76.5, 39.6, 0 + ] + ] + }, + "material" : { + "solidColor" : { + "color" : { + "rgba" : [0, 0, 255, 255] + } + } + } + } }]; var viewer = new Cesium.Viewer('cesiumContainer'); diff --git a/CHANGES.md b/CHANGES.md index 2f64215860d7..5761648cb6c1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,10 @@ Change Log * Reworked label rendering to use signed distance fields (SDF) for crisper text. [#7730](https://github.com/AnalyticalGraphicsInc/cesium/pull/7730) * Added a [new Sandcastle example](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Labels%20SDF.html) to showcase the new SDF labels. * Added `totalScale` property to `Label` which is the total scale of the label taking into account the label's scale and the relative size of the desired font compared to the generated glyph size. +* Added support for polygon holes to CZML. [#7991](https://github.com/AnalyticalGraphicsInc/cesium/pull/7991) + +##### Fixes :wrench: +* `PolygonGraphics.hierarchy` now converts constant array values to a `PolygonHierarchy` when set, so code that accesses the value of the property can rely on it always being a `PolygonHierarchy`. ### 1.59 - 2019-07-01 diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 1eb992f5a63b..bb627fe2df09 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -26,6 +26,7 @@ define([ '../Core/LinearApproximation', '../Core/Math', '../Core/NearFarScalar', + '../Core/PolygonHierarchy', '../Core/Quaternion', '../Core/Rectangle', '../Core/ReferenceFrame', @@ -75,6 +76,7 @@ define([ './PolylineGraphics', './PolylineOutlineMaterialProperty', './PositionPropertyArray', + './Property', './PropertyArray', './PropertyBag', './RectangleGraphics', @@ -117,6 +119,7 @@ define([ LinearApproximation, CesiumMath, NearFarScalar, + PolygonHierarchy, Quaternion, Rectangle, ReferenceFrame, @@ -166,6 +169,7 @@ define([ PolylineGraphics, PolylineOutlineMaterialProperty, PositionPropertyArray, + Property, PropertyArray, PropertyBag, RectangleGraphics, @@ -633,10 +637,11 @@ define([ function updateInterpolationSettings(packetData, property) { var interpolationAlgorithm = packetData.interpolationAlgorithm; - if (defined(interpolationAlgorithm) || defined(packetData.interpolationDegree)) { + var interpolationDegree = packetData.interpolationDegree; + if (defined(interpolationAlgorithm) || defined(interpolationDegree)) { property.setInterpolationOptions({ interpolationAlgorithm : interpolators[interpolationAlgorithm], - interpolationDegree : packetData.interpolationDegree + interpolationDegree : interpolationDegree }); } @@ -665,17 +670,42 @@ define([ iso8601 : undefined }; + function intervalFromString(intervalString) { + if (!defined(intervalString)) { + return undefined; + } + iso8601Scratch.iso8601 = intervalString; + return TimeInterval.fromIso8601(iso8601Scratch); + } + + function wrapPropertyInInfiniteInterval(property) { + var interval = Iso8601.MAXIMUM_INTERVAL.clone(); + interval.data = property; + return interval; + } + + function convertPropertyToComposite(property) { + // Create the composite and add the old property, wrapped in an infinite interval. + var composite = new CompositeProperty(); + composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property)); + return composite; + } + + function convertPositionPropertyToComposite(property) { + // Create the composite and add the old property, wrapped in an infinite interval. + var composite = new CompositePositionProperty(property.referenceFrame); + composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property)); + return composite; + } + function processProperty(type, object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) { - var combinedInterval; - var packetInterval = packetData.interval; - if (defined(packetInterval)) { - iso8601Scratch.iso8601 = packetInterval; - combinedInterval = TimeInterval.fromIso8601(iso8601Scratch); - if (defined(constrainedInterval)) { + var combinedInterval = intervalFromString(packetData.interval); + if (defined(constrainedInterval)) { + if (defined(combinedInterval)) { combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval); + } else { + combinedInterval = constrainedInterval; } - } else if (defined(constrainedInterval)) { - combinedInterval = constrainedInterval; } var packedLength; @@ -706,6 +736,10 @@ define([ if (isValue) { unwrappedInterval = unwrapInterval(type, packetData, sourceUri); + if (!defined(unwrappedInterval)) { + // not a known value type, bail + return; + } packedLength = defaultValue(type.packedLength, 1); unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1); isSampled = !defined(packetData.array) && (typeof unwrappedInterval !== 'string') && (unwrappedIntervalLength > packedLength) && (type !== Object); @@ -737,8 +771,7 @@ define([ // replaces any non-sampled property that may exist. if (isSampled && !hasInterval) { if (!(property instanceof SampledProperty)) { - property = new SampledProperty(type); - object[propertyName] = property; + object[propertyName] = property = new SampledProperty(type); } property.addSamplesPackedArray(unwrappedInterval, epoch); updateInterpolationSettings(packetData, property); @@ -761,16 +794,11 @@ define([ // If no property exists, simply use a new interval collection if (!defined(property)) { - if (isValue) { - property = new TimeIntervalCollectionProperty(); - } else { - property = new CompositeProperty(); - } - object[propertyName] = property; + object[propertyName] = property = isValue ? new TimeIntervalCollectionProperty() : new CompositeProperty(); } if (isValue && property instanceof TimeIntervalCollectionProperty) { - // If we create a collection, or it already existed, use it. + // If we created a collection, or it already was one, use it. property.intervals.addInterval(combinedInterval); } else if (property instanceof CompositeProperty) { // If the collection was already a CompositeProperty, use it. @@ -780,16 +808,7 @@ define([ property.intervals.addInterval(combinedInterval); } else { // Otherwise, create a CompositeProperty but preserve the existing data. - // Put the old property in an infinite interval. - interval = Iso8601.MAXIMUM_INTERVAL.clone(); - interval.data = property; - - // Create the composite. - property = new CompositeProperty(); - object[propertyName] = property; - - // Add the old property interval. - property.intervals.addInterval(interval); + object[propertyName] = property = convertPropertyToComposite(property); // Change the new data to a ConstantProperty and add it. if (isValue) { @@ -801,24 +820,14 @@ define([ return; } - //isSampled && hasInterval + // isSampled && hasInterval if (!defined(property)) { - property = new CompositeProperty(); - object[propertyName] = property; + object[propertyName] = property = new CompositeProperty(); } // Create a CompositeProperty but preserve the existing data. if (!(property instanceof CompositeProperty)) { - // Put the old property in an infinite interval. - interval = Iso8601.MAXIMUM_INTERVAL.clone(); - interval.data = property; - - // Create the composite. - property = new CompositeProperty(); - object[propertyName] = property; - - // Add the old property interval. - property.intervals.addInterval(interval); + object[propertyName] = property = convertPropertyToComposite(property); } // Check if the interval already exists in the composite. @@ -862,7 +871,7 @@ define([ } if (isArray(packetData)) { - for (var i = 0, len = packetData.length; i < len; i++) { + for (var i = 0, len = packetData.length; i < len; ++i) { processProperty(type, object, propertyName, packetData[i], interval, sourceUri, entityCollection); } } else { @@ -871,16 +880,13 @@ define([ } function processPositionProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) { - var combinedInterval; - var packetInterval = packetData.interval; - if (defined(packetInterval)) { - iso8601Scratch.iso8601 = packetInterval; - combinedInterval = TimeInterval.fromIso8601(iso8601Scratch); - if (defined(constrainedInterval)) { + var combinedInterval = intervalFromString(packetData.interval); + if (defined(constrainedInterval)) { + if (defined(combinedInterval)) { combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval); + } else { + combinedInterval = constrainedInterval; } - } else if (defined(constrainedInterval)) { - combinedInterval = constrainedInterval; } var numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0; @@ -936,8 +942,7 @@ define([ // replaces any non-sampled property that may exist. if (isSampled && !hasInterval) { if (!(property instanceof SampledPositionProperty) || (defined(referenceFrame) && property.referenceFrame !== referenceFrame)) { - property = new SampledPositionProperty(referenceFrame, numberOfDerivatives); - object[propertyName] = property; + object[propertyName] = property = new SampledPositionProperty(referenceFrame, numberOfDerivatives); } property.addSamplesPackedArray(unwrappedInterval, epoch); updateInterpolationSettings(packetData, property); @@ -979,17 +984,7 @@ define([ property.intervals.addInterval(combinedInterval); } else { // Otherwise, create a CompositePositionProperty but preserve the existing data. - - // Put the old property in an infinite interval. - interval = Iso8601.MAXIMUM_INTERVAL.clone(); - interval.data = property; - - // Create the composite. - property = new CompositePositionProperty(property.referenceFrame); - object[propertyName] = property; - - // Add the old property interval. - property.intervals.addInterval(interval); + object[propertyName] = property = convertPositionPropertyToComposite(property); // Change the new data to a ConstantPositionProperty and add it. if (isValue) { @@ -1001,29 +996,19 @@ define([ return; } - //isSampled && hasInterval + // isSampled && hasInterval if (!defined(property)) { - property = new CompositePositionProperty(referenceFrame); - object[propertyName] = property; + object[propertyName] = property = new CompositePositionProperty(referenceFrame); } else if (!(property instanceof CompositePositionProperty)) { // Create a CompositeProperty but preserve the existing data. - // Put the old property in an infinite interval. - interval = Iso8601.MAXIMUM_INTERVAL.clone(); - interval.data = property; - - // Create the composite. - property = new CompositePositionProperty(property.referenceFrame); - object[propertyName] = property; - - // Add the old property interval. - property.intervals.addInterval(interval); + object[propertyName] = property = convertPositionPropertyToComposite(property); } - //Check if the interval already exists in the composite. + // Check if the interval already exists in the composite. var intervals = property.intervals; interval = intervals.findInterval(combinedInterval); if (!defined(interval) || !(interval.data instanceof SampledPositionProperty) || (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)) { - //If not, create a SampledPositionProperty for it. + // If not, create a SampledPositionProperty for it. interval = combinedInterval.clone(); interval.data = new SampledPositionProperty(referenceFrame, numberOfDerivatives); intervals.addInterval(interval); @@ -1060,7 +1045,7 @@ define([ } if (isArray(packetData)) { - for (var i = 0, len = packetData.length; i < len; i++) { + for (var i = 0, len = packetData.length; i < len; ++i) { processPositionProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection); } } else { @@ -1069,16 +1054,13 @@ define([ } function processMaterialProperty(object, propertyName, packetData, constrainedInterval, sourceUri, entityCollection) { - var combinedInterval; - var packetInterval = packetData.interval; - if (defined(packetInterval)) { - iso8601Scratch.iso8601 = packetInterval; - combinedInterval = TimeInterval.fromIso8601(iso8601Scratch); - if (defined(constrainedInterval)) { + var combinedInterval = intervalFromString(packetData.interval); + if (defined(constrainedInterval)) { + if (defined(combinedInterval)) { combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval); + } else { + combinedInterval = constrainedInterval; } - } else if (defined(constrainedInterval)) { - combinedInterval = constrainedInterval; } var property = object[propertyName]; @@ -1199,7 +1181,7 @@ define([ } if (isArray(packetData)) { - for (var i = 0, len = packetData.length; i < len; i++) { + for (var i = 0, len = packetData.length; i < len; ++i) { processMaterialProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection); } } else { @@ -1208,7 +1190,10 @@ define([ } function processName(entity, packet, entityCollection, sourceUri) { - entity.name = defaultValue(packet.name, entity.name); + var nameData = packet.name; + if (defined(nameData)) { + entity.name = packet.name; + } } function processDescription(entity, packet, entityCollection, sourceUri) { @@ -1245,9 +1230,10 @@ define([ if (!defined(entity.properties)) { entity.properties = new PropertyBag(); } - //We cannot simply call processPacketData(entity, 'properties', propertyData, undefined, sourceUri, entityCollection) - //because each property of "properties" may vary separately. - //The properties will be accessible as entity.properties.myprop.getValue(time). + + // We cannot simply call processPacketData(entity, 'properties', propertyData, undefined, sourceUri, entityCollection) + // because each property of "properties" may vary separately. + // The properties will be accessible as entity.properties.myprop.getValue(time). for (var key in propertiesData) { if (propertiesData.hasOwnProperty(key)) { @@ -1257,7 +1243,7 @@ define([ var propertyData = propertiesData[key]; if (isArray(propertyData)) { - for (var i = 0, len = propertyData.length; i < len; i++) { + for (var i = 0, len = propertyData.length; i < len; ++i) { processProperty(getPropertyType(propertyData[i]), entity.properties, key, propertyData[i], undefined, sourceUri, entityCollection); } } else { @@ -1268,25 +1254,36 @@ define([ } } + function processReferencesArrayPacketData(object, propertyName, references, interval, entityCollection, PropertyArrayType, CompositePropertyArrayType) { + var properties = references.map(function(reference) { + return createReferenceProperty(entityCollection, reference); + }); + + if (defined(interval)) { + interval = intervalFromString(interval); + var property = object[propertyName]; + if (!(property instanceof CompositePropertyArrayType)) { + // If the property was not already a CompositeProperty, + // create a CompositeProperty but preserve the existing data. + + // Create the composite and add the old property, wrapped in an infinite interval. + var composite = new CompositePropertyArrayType(); + composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property)); + + object[propertyName] = property = composite; + } + + interval.data = new PropertyArrayType(properties); + property.intervals.addInterval(interval); + } else { + object[propertyName] = new PropertyArrayType(properties); + } + } + function processArrayPacketData(object, propertyName, packetData, entityCollection) { var references = packetData.references; if (defined(references)) { - var properties = references.map(function(reference) { - return createReferenceProperty(entityCollection, reference); - }); - - var iso8601Interval = packetData.interval; - if (defined(iso8601Interval)) { - iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - if (!(object[propertyName] instanceof CompositePositionProperty)) { - iso8601Interval.data = new PropertyArray(properties); - var property = new CompositeProperty(); - property.intervals.addInterval(iso8601Interval); - object[propertyName] = property; - } - } else { - object[propertyName] = new PropertyArray(properties); - } + processReferencesArrayPacketData(object, propertyName, references, packetData.interval, entityCollection, PropertyArray, CompositeProperty); } else { processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection); } @@ -1306,55 +1303,90 @@ define([ } } - function processPositionsPacketData(object, propertyName, positionsData, entityCollection) { - if (defined(positionsData.references)) { - var properties = positionsData.references.map(function(reference) { - return createReferenceProperty(entityCollection, reference); - }); + function processPositionArrayPacketData(object, propertyName, packetData, entityCollection) { + var references = packetData.references; + if (defined(references)) { + processReferencesArrayPacketData(object, propertyName, references, packetData.interval, entityCollection, PositionPropertyArray, CompositePositionProperty); + } else { + if (defined(packetData.cartesian)) { + packetData.array = Cartesian3.unpackArray(packetData.cartesian); + } else if (defined(packetData.cartographicRadians)) { + packetData.array = Cartesian3.fromRadiansArrayHeights(packetData.cartographicRadians); + } else if (defined(packetData.cartographicDegrees)) { + packetData.array = Cartesian3.fromDegreesArrayHeights(packetData.cartographicDegrees); + } - var iso8601Interval = positionsData.interval; - if (defined(iso8601Interval)) { - iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - if (!(object[propertyName] instanceof CompositePositionProperty)) { - iso8601Interval.data = new PositionPropertyArray(properties); - var property = new CompositePositionProperty(); - property.intervals.addInterval(iso8601Interval); - object[propertyName] = property; - } - } else { - object[propertyName] = new PositionPropertyArray(properties); + if (defined(packetData.array)) { + processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection); } + } + } + + function processPositionArray(object, propertyName, packetData, entityCollection) { + if (!defined(packetData)) { + return; + } + + if (isArray(packetData)) { + for (var i = 0, length = packetData.length; i < length; ++i) { + processPositionArrayPacketData(object, propertyName, packetData[i], entityCollection); + } + } else { + processPositionArrayPacketData(object, propertyName, packetData, entityCollection); + } + } + + function unpackCartesianArray(array) { + return Cartesian3.unpackArray(array); + } + + function unpackCartographicRadiansArray(array) { + return Cartesian3.fromRadiansArrayHeights(array); + } + + function unpackCartographicDegreesArray(array) { + return Cartesian3.fromDegreesArrayHeights(array); + } + + function processPositionArrayOfArraysPacketData(object, propertyName, packetData, entityCollection) { + var references = packetData.references; + if (defined(references)) { + var properties = references.map(function(referenceArray) { + var tempObj = {}; + processReferencesArrayPacketData(tempObj, 'positions', referenceArray, packetData.interval, entityCollection, PositionPropertyArray, CompositePositionProperty); + return tempObj.positions; + }); + object[propertyName] = new PositionPropertyArray(properties); } else { - if (defined(positionsData.cartesian)) { - positionsData.array = Cartesian3.unpackArray(positionsData.cartesian); - } else if (defined(positionsData.cartographicRadians)) { - positionsData.array = Cartesian3.fromRadiansArrayHeights(positionsData.cartographicRadians); - } else if (defined(positionsData.cartographicDegrees)) { - positionsData.array = Cartesian3.fromDegreesArrayHeights(positionsData.cartographicDegrees); + if (defined(packetData.cartesian)) { + packetData.array = packetData.cartesian.map(unpackCartesianArray); + } else if (defined(packetData.cartographicRadians)) { + packetData.array = packetData.cartographicRadians.map(unpackCartographicRadiansArray); + } else if (defined(packetData.cartographicDegrees)) { + packetData.array = packetData.cartographicDegrees.map(unpackCartographicDegreesArray); } - if (defined(positionsData.array)) { - processPacketData(Array, object, propertyName, positionsData, undefined, undefined, entityCollection); + if (defined(packetData.array)) { + processPacketData(Array, object, propertyName, packetData, undefined, undefined, entityCollection); } } } - function processPositions(object, propertyName, positionsData, entityCollection) { - if (!defined(positionsData)) { + function processPositionArrayOfArrays(object, propertyName, packetData, entityCollection) { + if (!defined(packetData)) { return; } - if (isArray(positionsData)) { - for (var i = 0, length = positionsData.length; i < length; i++) { - processPositionsPacketData(object, propertyName, positionsData[i], entityCollection); + if (isArray(packetData)) { + for (var i = 0, length = packetData.length; i < length; ++i) { + processPositionArrayOfArraysPacketData(object, propertyName, packetData[i], entityCollection); } } else { - processPositionsPacketData(object, propertyName, positionsData, entityCollection); + processPositionArrayOfArraysPacketData(object, propertyName, packetData, entityCollection); } } function processAvailability(entity, packet, entityCollection, sourceUri) { - var interval; var packetData = packet.availability; if (!defined(packetData)) { return; @@ -1362,20 +1394,15 @@ define([ var intervals; if (isArray(packetData)) { - var length = packetData.length; - for (var i = 0; i < length; i++) { + for (var i = 0, len = packetData.length; i < len; ++i) { if (!defined(intervals)) { intervals = new TimeIntervalCollection(); } - iso8601Scratch.iso8601 = packetData[i]; - interval = TimeInterval.fromIso8601(iso8601Scratch); - intervals.addInterval(interval); + intervals.addInterval(intervalFromString(packetData[i])); } } else { - iso8601Scratch.iso8601 = packetData; - interval = TimeInterval.fromIso8601(iso8601Scratch); intervals = new TimeIntervalCollection(); - intervals.addInterval(interval); + intervals.addInterval(intervalFromString(packetData)); } entity.availability = intervals; } @@ -1394,13 +1421,7 @@ define([ return; } - var interval; - var intervalString = billboardData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(billboardData.interval); var billboard = entity.billboard; if (!defined(billboard)) { entity.billboard = billboard = new BillboardGraphics(); @@ -1434,13 +1455,7 @@ define([ return; } - var interval; - var intervalString = boxData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(boxData.interval); var box = entity.box; if (!defined(box)) { entity.box = box = new BoxGraphics(); @@ -1464,20 +1479,14 @@ define([ return; } - var interval; - var intervalString = corridorData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(corridorData.interval); var corridor = entity.corridor; if (!defined(corridor)) { entity.corridor = corridor = new CorridorGraphics(); } processPacketData(Boolean, corridor, 'show', corridorData.show, interval, sourceUri, entityCollection); - processPositions(corridor, 'positions', corridorData.positions, entityCollection); + processPositionArray(corridor, 'positions', corridorData.positions, entityCollection); processPacketData(Number, corridor, 'width', corridorData.width, interval, sourceUri, entityCollection); processPacketData(Number, corridor, 'height', corridorData.height, interval, sourceUri, entityCollection); processPacketData(HeightReference, corridor, 'heightReference', corridorData.heightReference, interval, sourceUri, entityCollection); @@ -1502,13 +1511,7 @@ define([ return; } - var interval; - var intervalString = cylinderData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(cylinderData.interval); var cylinder = entity.cylinder; if (!defined(cylinder)) { entity.cylinder = cylinder = new CylinderGraphics(); @@ -1581,13 +1584,7 @@ define([ return; } - var interval; - var intervalString = ellipseData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(ellipseData.interval); var ellipse = entity.ellipse; if (!defined(ellipse)) { entity.ellipse = ellipse = new EllipseGraphics(); @@ -1621,13 +1618,7 @@ define([ return; } - var interval; - var intervalString = ellipsoidData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(ellipsoidData.interval); var ellipsoid = entity.ellipsoid; if (!defined(ellipsoid)) { entity.ellipsoid = ellipsoid = new EllipsoidGraphics(); @@ -1654,13 +1645,7 @@ define([ return; } - var interval; - var intervalString = labelData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(labelData.interval); var label = entity.label; if (!defined(label)) { entity.label = label = new LabelGraphics(); @@ -1695,13 +1680,7 @@ define([ return; } - var interval; - var intervalString = modelData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(modelData.interval); var model = entity.model; if (!defined(model)) { entity.model = model = new ModelGraphics(); @@ -1728,7 +1707,7 @@ define([ var nodeTransformationsData = modelData.nodeTransformations; if (defined(nodeTransformationsData)) { if (isArray(nodeTransformationsData)) { - for (i = 0, len = nodeTransformationsData.length; i < len; i++) { + for (i = 0, len = nodeTransformationsData.length; i < len; ++i) { processNodeTransformations(model, nodeTransformationsData[i], interval, sourceUri, entityCollection); } } else { @@ -1739,7 +1718,7 @@ define([ var articulationsData = modelData.articulations; if (defined(articulationsData)) { if (isArray(articulationsData)) { - for (i = 0, len = articulationsData.length; i < len; i++) { + for (i = 0, len = articulationsData.length; i < len; ++i) { processArticulations(model, articulationsData[i], interval, sourceUri, entityCollection); } } else { @@ -1749,29 +1728,24 @@ define([ } function processNodeTransformations(model, nodeTransformationsData, constrainedInterval, sourceUri, entityCollection) { - var combinedInterval; - var packetInterval = nodeTransformationsData.interval; - if (defined(packetInterval)) { - iso8601Scratch.iso8601 = packetInterval; - combinedInterval = TimeInterval.fromIso8601(iso8601Scratch); - if (defined(constrainedInterval)) { + var combinedInterval = intervalFromString(nodeTransformationsData.interval); + if (defined(constrainedInterval)) { + if (defined(combinedInterval)) { combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval); + } else { + combinedInterval = constrainedInterval; } - } else if (defined(constrainedInterval)) { - combinedInterval = constrainedInterval; } var nodeTransformations = model.nodeTransformations; var nodeNames = Object.keys(nodeTransformationsData); for (var i = 0, len = nodeNames.length; i < len; ++i) { var nodeName = nodeNames[i]; - if (nodeName === 'interval') { continue; } var nodeTransformationData = nodeTransformationsData[nodeName]; - if (!defined(nodeTransformationData)) { continue; } @@ -1796,29 +1770,24 @@ define([ } function processArticulations(model, articulationsData, constrainedInterval, sourceUri, entityCollection) { - var combinedInterval; - var packetInterval = articulationsData.interval; - if (defined(packetInterval)) { - iso8601Scratch.iso8601 = packetInterval; - combinedInterval = TimeInterval.fromIso8601(iso8601Scratch); - if (defined(constrainedInterval)) { + var combinedInterval = intervalFromString(articulationsData.interval); + if (defined(constrainedInterval)) { + if (defined(combinedInterval)) { combinedInterval = TimeInterval.intersect(combinedInterval, constrainedInterval, scratchTimeInterval); + } else { + combinedInterval = constrainedInterval; } - } else if (defined(constrainedInterval)) { - combinedInterval = constrainedInterval; } var articulations = model.articulations; var keys = Object.keys(articulationsData); for (var i = 0, len = keys.length; i < len; ++i) { var key = keys[i]; - if (key === 'interval') { continue; } var articulationStageData = articulationsData[key]; - if (!defined(articulationStageData)) { continue; } @@ -1841,13 +1810,7 @@ define([ return; } - var interval; - var intervalString = pathData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(pathData.interval); var path = entity.path; if (!defined(path)) { entity.path = path = new PathGraphics(); @@ -1868,13 +1831,7 @@ define([ return; } - var interval; - var intervalString = pointData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(pointData.interval); var point = entity.point; if (!defined(point)) { entity.point = point = new PointGraphics(); @@ -1892,26 +1849,82 @@ define([ processPacketData(Number, point, 'disableDepthTestDistance', pointData.disableDepthTestDistance, interval, sourceUri, entityCollection); } + function PolygonHierarchyProperty(polygon) { + this.polygon = polygon; + this._definitionChanged = new Event(); + } + + defineProperties(PolygonHierarchyProperty.prototype, { + isConstant : { + get : function() { + var positions = this.polygon._positions; + var holes = this.polygon._holes; + return (!defined(positions) || positions.isConstant) && + (!defined(holes) || holes.isConstant); + } + }, + definitionChanged : { + get : function() { + return this._definitionChanged; + } + } + }); + + PolygonHierarchyProperty.prototype.getValue = function(time, result) { + var positions; + if (defined(this.polygon._positions)) { + positions = this.polygon._positions.getValue(time); + } + + var holes; + if (defined(this.polygon._holes)) { + holes = this.polygon._holes.getValue(time); + if (defined(holes)) { + holes = holes.map(function(holePositions) { + return new PolygonHierarchy(holePositions); + }); + } + } + + if (!defined(result)) { + return new PolygonHierarchy(positions, holes); + } + + result.positions = positions; + result.holes = holes; + return result; + }; + + PolygonHierarchyProperty.prototype.equals = function(other) { + return this === other || + (other instanceof PolygonHierarchyProperty && + Property.equals(this.polygon._positions, other.polygon._positions) && + Property.equals(this.polygon._holes, other.polygon._holes)); + }; + function processPolygon(entity, packet, entityCollection, sourceUri) { var polygonData = packet.polygon; if (!defined(polygonData)) { return; } - var interval; - var intervalString = polygonData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(polygonData.interval); var polygon = entity.polygon; if (!defined(polygon)) { entity.polygon = polygon = new PolygonGraphics(); } processPacketData(Boolean, polygon, 'show', polygonData.show, interval, sourceUri, entityCollection); - processPositions(polygon, 'hierarchy', polygonData.positions, entityCollection); + + // adapt 'position' property producing Cartesian[] + // and 'holes' property producing Cartesian[][] + // to a single property producing PolygonHierarchy + processPositionArray(polygon, '_positions', polygonData.positions, entityCollection); + processPositionArrayOfArrays(polygon, '_holes', polygonData.holes, entityCollection); + if (defined(polygon._positions) || defined(polygon._holes)) { + polygon.hierarchy = new PolygonHierarchyProperty(polygon); + } + processPacketData(Number, polygon, 'height', polygonData.height, interval, sourceUri, entityCollection); processPacketData(HeightReference, polygon, 'heightReference', polygonData.heightReference, interval, sourceUri, entityCollection); processPacketData(Number, polygon, 'extrudedHeight', polygonData.extrudedHeight, interval, sourceUri, entityCollection); @@ -1943,20 +1956,14 @@ define([ return; } - var interval; - var intervalString = polylineData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(polylineData.interval); var polyline = entity.polyline; if (!defined(polyline)) { entity.polyline = polyline = new PolylineGraphics(); } processPacketData(Boolean, polyline, 'show', polylineData.show, interval, sourceUri, entityCollection); - processPositions(polyline, 'positions', polylineData.positions, entityCollection); + processPositionArray(polyline, 'positions', polylineData.positions, entityCollection); processPacketData(Number, polyline, 'width', polylineData.width, interval, sourceUri, entityCollection); processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); @@ -1982,13 +1989,7 @@ define([ return; } - var interval; - var intervalString = rectangleData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(rectangleData.interval); var rectangle = entity.rectangle; if (!defined(rectangle)) { entity.rectangle = rectangle = new RectangleGraphics(); @@ -2020,20 +2021,14 @@ define([ return; } - var interval; - var intervalString = wallData.interval; - if (defined(intervalString)) { - iso8601Scratch.iso8601 = intervalString; - interval = TimeInterval.fromIso8601(iso8601Scratch); - } - + var interval = intervalFromString(wallData.interval); var wall = entity.wall; if (!defined(wall)) { entity.wall = wall = new WallGraphics(); } processPacketData(Boolean, wall, 'show', wallData.show, interval, sourceUri, entityCollection); - processPositions(wall, 'positions', wallData.positions, entityCollection); + processPositionArray(wall, 'positions', wallData.positions, entityCollection); processArray(wall, 'minimumHeights', wallData.minimumHeights, entityCollection); processArray(wall, 'maximumHeights', wallData.maximumHeights, entityCollection); processPacketData(Number, wall, 'granularity', wallData.granularity, interval, sourceUri, entityCollection); @@ -2115,12 +2110,13 @@ define([ clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER; clock.multiplier = 1.0; } - if (defined(clockPacket.interval)) { - iso8601Scratch.iso8601 = clockPacket.interval; - var interval = TimeInterval.fromIso8601(iso8601Scratch); + + var interval = intervalFromString(clockPacket.interval); + if (defined(interval)) { clock.startTime = interval.start; clock.stopTime = interval.stop; } + if (defined(clockPacket.currentTime)) { clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime); } @@ -2212,7 +2208,7 @@ define([ } /** - * A {@link DataSource} which processes {@link https://github.com/AnalyticalGraphicsInc/cesium/wiki/CZML-Guide|CZML}. + * A {@link DataSource} which processes {@link https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CZML-Guide|CZML}. * @alias CzmlDataSource * @constructor * @@ -2449,10 +2445,10 @@ define([ CzmlDataSource.processMaterialPacketData = processMaterialPacketData; CzmlDataSource._processCzml = function(czml, entityCollection, sourceUri, updaterFunctions, dataSource) { - updaterFunctions = defined(updaterFunctions) ? updaterFunctions : CzmlDataSource.updaters; + updaterFunctions = defaultValue(updaterFunctions, CzmlDataSource.updaters); if (isArray(czml)) { - for (var i = 0, len = czml.length; i < len; i++) { + for (var i = 0, len = czml.length; i < len; ++i) { processCzmlPacket(czml[i], entityCollection, updaterFunctions, sourceUri, dataSource); } } else { diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index dc3d160eb289..5974687b6858 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -13,17 +13,13 @@ define([ '../Core/DistanceDisplayConditionGeometryInstanceAttribute', '../Core/EllipsoidTangentPlane', '../Core/GeometryInstance', - '../Core/GeometryOffsetAttribute', - '../Core/isArray', '../Core/Iso8601', - '../Core/oneTimeWarning', '../Core/OffsetGeometryInstanceAttribute', + '../Core/oneTimeWarning', '../Core/PolygonGeometry', - '../Core/PolygonHierarchy', '../Core/PolygonOutlineGeometry', '../Core/Rectangle', '../Core/ShowGeometryInstanceAttribute', - '../Scene/GroundPrimitive', '../Scene/HeightReference', '../Scene/MaterialAppearance', '../Scene/PerInstanceColorAppearance', @@ -47,17 +43,13 @@ define([ DistanceDisplayConditionGeometryInstanceAttribute, EllipsoidTangentPlane, GeometryInstance, - GeometryOffsetAttribute, - isArray, Iso8601, - oneTimeWarning, OffsetGeometryInstanceAttribute, + oneTimeWarning, PolygonGeometry, - PolygonHierarchy, PolygonOutlineGeometry, Rectangle, ShowGeometryInstanceAttribute, - GroundPrimitive, HeightReference, MaterialAppearance, PerInstanceColorAppearance, @@ -223,10 +215,11 @@ define([ }; PolygonGeometryUpdater.prototype._computeCenter = function(time, result) { - var positions = Property.getValueOrUndefined(this._entity.polygon.hierarchy, time); - if (defined(positions) && !isArray(positions)) { - positions = positions.positions; + var hierarchy = Property.getValueOrUndefined(this._entity.polygon.hierarchy, time); + if (!defined(hierarchy)) { + return; } + var positions = hierarchy.positions; if (positions.length === 0) { return; } @@ -289,10 +282,6 @@ define([ options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; var hierarchyValue = polygon.hierarchy.getValue(Iso8601.MINIMUM_VALUE); - if (isArray(hierarchyValue)) { - hierarchyValue = new PolygonHierarchy(hierarchyValue); - } - var heightValue = Property.getValueOrUndefined(polygon.height, Iso8601.MINIMUM_VALUE); var heightReferenceValue = Property.getValueOrDefault(polygon.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE); var extrudedHeightValue = Property.getValueOrUndefined(polygon.extrudedHeight, Iso8601.MINIMUM_VALUE); @@ -364,12 +353,7 @@ define([ DyanmicPolygonGeometryUpdater.prototype._setOptions = function(entity, polygon, time) { var options = this._options; - var hierarchy = Property.getValueOrUndefined(polygon.hierarchy, time); - if (isArray(hierarchy)) { - options.polygonHierarchy = new PolygonHierarchy(hierarchy); - } else { - options.polygonHierarchy = hierarchy; - } + options.polygonHierarchy = Property.getValueOrUndefined(polygon.hierarchy, time); var heightValue = Property.getValueOrUndefined(polygon.height, time); var heightReferenceValue = Property.getValueOrDefault(polygon.heightReference, time, HeightReference.NONE); diff --git a/Source/DataSources/PolygonGraphics.js b/Source/DataSources/PolygonGraphics.js index 77ef91c5029f..f3239e7ec6da 100644 --- a/Source/DataSources/PolygonGraphics.js +++ b/Source/DataSources/PolygonGraphics.js @@ -4,6 +4,9 @@ define([ '../Core/defineProperties', '../Core/DeveloperError', '../Core/Event', + '../Core/isArray', + '../Core/PolygonHierarchy', + './ConstantProperty', './createMaterialPropertyDescriptor', './createPropertyDescriptor' ], function( @@ -12,10 +15,21 @@ define([ defineProperties, DeveloperError, Event, + isArray, + PolygonHierarchy, + ConstantProperty, createMaterialPropertyDescriptor, createPropertyDescriptor) { 'use strict'; + function createPolygonHierarchyProperty(value) { + if (isArray(value)) { + // convert array of positions to PolygonHierarchy object + value = new PolygonHierarchy(value); + } + return new ConstantProperty(value); + } + /** * Describes a polygon defined by an hierarchy of linear rings which make up the outer shape and any nested holes. * The polygon conforms to the curvature of the globe and can be placed on the surface or @@ -125,7 +139,7 @@ define([ * @memberof PolygonGraphics.prototype * @type {Property} */ - hierarchy : createPropertyDescriptor('hierarchy'), + hierarchy : createPropertyDescriptor('hierarchy', undefined, createPolygonHierarchyProperty), /** * Gets or sets the numeric Property specifying the constant altitude of the polygon. diff --git a/Source/DataSources/PositionPropertyArray.js b/Source/DataSources/PositionPropertyArray.js index 6615277e6369..b2a231ffd9d3 100644 --- a/Source/DataSources/PositionPropertyArray.js +++ b/Source/DataSources/PositionPropertyArray.js @@ -91,7 +91,7 @@ define([ /** * Gets the value of the property. * - * @param {JulianDate} [time] The time for which to retrieve the value. This parameter is unused since the value does not change with respect to time. + * @param {JulianDate} time The time for which to retrieve the value. * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned. * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied. */ @@ -104,8 +104,8 @@ define([ * * @param {JulianDate} time The time for which to retrieve the value. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. - * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. - * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied. */ PositionPropertyArray.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { //>>includeStart('debug', pragmas.debug); diff --git a/Specs/Data/CZML/ValidationDocument.czml b/Specs/Data/CZML/ValidationDocument.czml index 323dd451a657..4bc97b24680f 100644 --- a/Specs/Data/CZML/ValidationDocument.czml +++ b/Specs/Data/CZML/ValidationDocument.czml @@ -440,6 +440,21 @@ 27161,33386,62338 ] }, + "holes":{ + "cartesian":[ + [ + 47462,20409,3151, + 58636,39653,53914, + 31954,4988,47462 + ], + [ + 20409,3151,58636, + 39653,53914,31954, + 4988,47462,20409, + 3151,58636,39653 + ] + ] + }, "arcType":"RHUMB", "height":26391, "heightReference":"CLAMP_TO_GROUND", @@ -2379,23 +2394,63 @@ } }, { - "id":"constant_polygon_hierarchy_cartographicRadians", + "id":"constant_polygon_positions_cartographicRadians", "polygon":{ "positions":{ "cartographicRadians":[ - 0.612948853926511,1.3346715688367,54401, - 1.1867596160592,0.345663242797974,35811 + 0.278819883450618,1.34192534297912,13112, + 1.08460649779701,1.26665808721843,9013 ] } } }, { - "id":"constant_polygon_hierarchy_cartographicDegrees", + "id":"constant_polygon_positions_cartographicDegrees", "polygon":{ "positions":{ "cartographicDegrees":[ - 19,41,50907, - 28,40,24937 + 20,42,343, + 21,14,24042 + ] + } + } + }, + { + "id":"constant_polygon_holes_cartographicRadians", + "polygon":{ + "holes":{ + "cartographicRadians":[ + [ + 0.799220652820836,1.50366253893541,4776, + 0.179862066646486,1.42489853818289,42245, + 0.0636782022426772,0.558333087028927,32510 + ], + [ + 1.50366253893541,0.779166543514464,33810, + 1.42489853818289,0.00358717805196918,20389, + 0.558333087028927,0.799220652820836,43134, + 0.779166543514464,0.179862066646486,1412 + ] + ] + } + } + }, + { + "id":"constant_polygon_holes_cartographicDegrees", + "polygon":{ + "holes":{ + "cartographicDegrees":[ + [ + 38,39,52122, + 30,41,40406, + 9,42,55073 + ], + [ + 39,12,5835, + 41,41,39069, + 42,38,39639, + 12,30,54806 + ] ] } } @@ -7202,6 +7257,20 @@ "scale":16451 } }, + { + "id":"ConstantPosition3", + "position":{ + "cartesian":[ + 1758,45062,8624 + ] + } + }, + { + "id":"ConstantDouble3", + "billboard":{ + "scale":50938 + } + }, { "id":"Reference", "description":{ @@ -7735,6 +7804,15 @@ "ConstantPosition2#position" ] }, + "holes":{ + "references":[ + [ + "ConstantPosition1#position", + "ConstantPosition2#position", + "ConstantPosition3#position" + ] + ] + }, "arcType":{ "reference":"Constant#polygon.arcType" }, @@ -19841,7 +19919,7 @@ "epoch":"2016-06-17T12:00:00Z", "unitCartesian":[ 0,0.5532827915003591,0.6961099100967651,0.4575031646826541, - 3600,0.7546657014303162,0.11520131359926604,0.6459166636878882 + 3600,0.7546657014303163,0.11520131359926505,0.6459166636878884 ] } } diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index 20d075d1576d..f90a1a86a1fe 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -4,19 +4,18 @@ defineSuite([ 'Core/BoundingRectangle', 'Core/Cartesian2', 'Core/Cartesian3', - 'Core/Cartographic', 'Core/ClockRange', 'Core/ClockStep', 'Core/Color', 'Core/CornerType', 'Core/DistanceDisplayCondition', - 'Core/Ellipsoid', 'Core/Event', 'Core/ExtrapolationType', 'Core/Iso8601', 'Core/JulianDate', 'Core/Math', 'Core/NearFarScalar', + 'Core/PolygonHierarchy', 'Core/Quaternion', 'Core/Rectangle', 'Core/ReferenceFrame', @@ -27,6 +26,7 @@ defineSuite([ 'Core/Transforms', 'Core/TranslationRotationScale', 'DataSources/CompositeEntityCollection', + 'DataSources/CompositeMaterialProperty', 'DataSources/CompositePositionProperty', 'DataSources/CompositeProperty', 'DataSources/ConstantPositionProperty', @@ -52,19 +52,18 @@ defineSuite([ BoundingRectangle, Cartesian2, Cartesian3, - Cartographic, ClockRange, ClockStep, Color, CornerType, DistanceDisplayCondition, - Ellipsoid, Event, ExtrapolationType, Iso8601, JulianDate, CesiumMath, NearFarScalar, + PolygonHierarchy, Quaternion, Rectangle, ReferenceFrame, @@ -75,6 +74,7 @@ defineSuite([ Transforms, TranslationRotationScale, CompositeEntityCollection, + CompositeMaterialProperty, CompositePositionProperty, CompositeProperty, ConstantPositionProperty, @@ -96,11 +96,12 @@ defineSuite([ when) { 'use strict'; - function makePacket(packet) { - return [{ + function makeDocument(packet) { + var documentPacket = { id : 'document', version : '1.0' - }, packet]; + }; + return [documentPacket, packet]; } var staticCzml = { @@ -188,6 +189,19 @@ defineSuite([ })); }); + function arraySubset(array, startIndex, count) { + startIndex = startIndex === undefined ? 0 : startIndex; + return array.slice(startIndex, startIndex + count); + } + + function cartesianFromArrayDegrees(array, startIndex) { + return Cartesian3.fromDegrees.apply(null, arraySubset(array, startIndex, 3)); + } + + function cartesianFromArrayRadians(array, startIndex) { + return Cartesian3.fromRadians.apply(null, arraySubset(array, startIndex, 3)); + } + it('default constructor has expected values', function() { var dataSource = new CzmlDataSource(); expect(dataSource.changedEvent).toBeInstanceOf(Event); @@ -196,31 +210,29 @@ defineSuite([ expect(dataSource.clock).toBeUndefined(); expect(dataSource.entities).toBeInstanceOf(EntityCollection); expect(dataSource.entities.values.length).toEqual(0); - expect(dataSource.show).toBe(true); + expect(dataSource.show).toEqual(true); }); it('show sets underlying entity collection show.', function() { var dataSource = new CzmlDataSource(); dataSource.show = false; - expect(dataSource.show).toBe(false); + expect(dataSource.show).toEqual(false); expect(dataSource.show).toEqual(dataSource.entities.show); dataSource.show = true; - expect(dataSource.show).toBe(true); + expect(dataSource.show).toEqual(true); expect(dataSource.show).toEqual(dataSource.entities.show); }); it('name returns CZML defined name', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(nameCzml).then(function(dataSource) { - expect(dataSource.name).toEqual('czmlName'); + return CzmlDataSource.load(nameCzml).then(function(dataSource) { + expect(dataSource.name).toEqual(nameCzml.name); }); }); it('name uses source name if CZML name is undefined', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(clockCzml, { + return CzmlDataSource.load(clockCzml, { sourceUri: 'Gallery/simple.czml?asd=true' }).then(function(dataSource) { expect(dataSource.name).toEqual('simple.czml'); @@ -228,24 +240,23 @@ defineSuite([ }); it('does not overwrite existing name if CZML name is undefined', function() { - var dataSource = new CzmlDataSource('myName'); + var name = 'myName'; + var dataSource = new CzmlDataSource(name); return dataSource.load(clockCzml, { sourceUri: 'Gallery/simple.czml' }).then(function(dataSource) { - expect(dataSource.name).toEqual('myName'); + expect(dataSource.name).toEqual(name); }); }); it('clock returns undefined for static CZML', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(staticCzml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(staticCzml)).then(function(dataSource) { expect(dataSource.clock).toBeUndefined(); }); }); it('clock returns CZML defined clock', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(clockCzml).then(function(dataSource) { + return CzmlDataSource.load(clockCzml).then(function(dataSource) { var clock = dataSource.clock; expect(clock).toBeDefined(); expect(clock.startTime).toEqual(parsedClock.interval.start); @@ -273,8 +284,7 @@ defineSuite([ iso8601 : dynamicCzml.availability }); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(dynamicCzml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(dynamicCzml)).then(function(dataSource) { var clock = dataSource.clock; expect(clock).toBeDefined(); expect(clock.startTime).toEqual(interval.start); @@ -461,9 +471,9 @@ defineSuite([ }); }); - it('CZML adds data for infinite billboard.', function() { + it('can load constant data for billboard', function() { var sourceUri = 'http://someImage.invalid/'; - var billboardPacket = { + var packet = { billboard : { image : 'image.png', scale : 1.0, @@ -502,39 +512,38 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket), { + return CzmlDataSource.load(makeDocument(packet), { sourceUri: sourceUri }).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); - expect(entity.billboard.image.getValue(Iso8601.MINIMUM_VALUE).url).toEqual(sourceUri + 'image.png'); - expect(entity.billboard.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(billboardPacket.billboard.rotation); - expect(entity.billboard.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(billboardPacket.billboard.scale); - expect(entity.billboard.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference.CLAMP_TO_GROUND); - expect(entity.billboard.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.CENTER); - expect(entity.billboard.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); - expect(entity.billboard.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); - expect(entity.billboard.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); - expect(entity.billboard.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(1.0, 2.0)); - expect(entity.billboard.alignedAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 0.0, 0.0)); - expect(entity.billboard.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.billboard.sizeInMeters.getValue(Iso8601.MINIMUM_VALUE)).toEqual(false); - expect(entity.billboard.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(10); - expect(entity.billboard.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(11); - expect(entity.billboard.scaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 2.0, 10000.0, 3.0)); - expect(entity.billboard.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 1.0, 10000.0, 0.0)); - expect(entity.billboard.pixelOffsetScaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 20.0, 10000.0, 30.0)); - expect(entity.billboard.imageSubRegion.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new BoundingRectangle(20, 30, 10, 11)); + expect(entity.billboard.image.getValue(Iso8601.MINIMUM_VALUE).url).toEqual(sourceUri + packet.billboard.image); + expect(entity.billboard.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.rotation); + expect(entity.billboard.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.scale); + expect(entity.billboard.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference[packet.billboard.heightReference]); + expect(entity.billboard.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin[packet.billboard.horizontalOrigin]); + expect(entity.billboard.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin[packet.billboard.verticalOrigin]); + expect(entity.billboard.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.billboard.color.rgbaf)); + expect(entity.billboard.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.billboard.eyeOffset.cartesian)); + expect(entity.billboard.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian2.unpack(packet.billboard.pixelOffset.cartesian2)); + expect(entity.billboard.alignedAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.billboard.alignedAxis.unitCartesian)); + expect(entity.billboard.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.show); + expect(entity.billboard.sizeInMeters.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.sizeInMeters); + expect(entity.billboard.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.width); + expect(entity.billboard.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.billboard.height); + expect(entity.billboard.scaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.billboard.scaleByDistance.nearFarScalar)); + expect(entity.billboard.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.billboard.translucencyByDistance.nearFarScalar)); + expect(entity.billboard.pixelOffsetScaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.billboard.pixelOffsetScaleByDistance.nearFarScalar)); + expect(entity.billboard.imageSubRegion.getValue(Iso8601.MINIMUM_VALUE)).toEqual(BoundingRectangle.unpack(packet.billboard.imageSubRegion.boundingRectangle)); }); }); it('can handle aligned axis expressed as a cartesian', function() { - // historically, CZML allowed alignedAxis to be defined as a cartesian, even though that implied it could be - // non-unit magnitude (it can't). + // historically, CZML allowed alignedAxis to be defined as a cartesian, + // even though that implied it could be non-unit magnitude (it can't). // but, we need to ensure that continues to work. - var billboardPacket = { + var packet = { billboard : { alignedAxis : { cartesian : [1.0, 0.0, 0.0] @@ -542,12 +551,11 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); - expect(entity.billboard.alignedAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 0.0, 0.0)); + expect(entity.billboard.alignedAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.billboard.alignedAxis.cartesian)); }); }); @@ -567,8 +575,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var property = entity.billboard.alignedAxis; @@ -600,8 +607,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var property = entity.billboard.alignedAxis; @@ -631,8 +637,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet), { + return CzmlDataSource.load(makeDocument(packet), { sourceUri: source }).then(function(dataSource) { var entity = dataSource.entities.values[0]; @@ -642,8 +647,8 @@ defineSuite([ }); }); - it('CZML adds data for constrained billboard.', function() { - var billboardPacket = { + it('can load interval data for billboard', function() { + var packet = { billboard : { interval : '2000-01-01/2001-01-01', image : 'http://someImage.invalid/image', @@ -664,24 +669,22 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : billboardPacket.billboard.interval + iso8601 : packet.billboard.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); - expect(entity.billboard.image.getValue(validTime).url).toEqual(billboardPacket.billboard.image); - expect(entity.billboard.scale.getValue(validTime)).toEqual(billboardPacket.billboard.scale); - expect(entity.billboard.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.CENTER); - expect(entity.billboard.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); - expect(entity.billboard.color.getValue(validTime)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); - expect(entity.billboard.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); - expect(entity.billboard.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(1.0, 2.0)); - - expect(entity.billboard.show.getValue(validTime)).toEqual(true); + expect(entity.billboard.image.getValue(validTime).url).toEqual(packet.billboard.image); + expect(entity.billboard.scale.getValue(validTime)).toEqual(packet.billboard.scale); + expect(entity.billboard.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin[packet.billboard.horizontalOrigin]); + expect(entity.billboard.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin[packet.billboard.verticalOrigin]); + expect(entity.billboard.color.getValue(validTime)).toEqual(Color.unpack(packet.billboard.color.rgbaf)); + expect(entity.billboard.eyeOffset.getValue(validTime)).toEqual(Cartesian3.unpack(packet.billboard.eyeOffset.cartesian)); + expect(entity.billboard.pixelOffset.getValue(validTime)).toEqual(Cartesian2.unpack(packet.billboard.pixelOffset.cartesian2)); + expect(entity.billboard.show.getValue(validTime)).toEqual(packet.billboard.show); expect(entity.billboard).toBeDefined(); expect(entity.billboard.image.getValue(invalidTime)).toBeUndefined(); @@ -695,21 +698,226 @@ defineSuite([ }); }); + it('can load interval data with further constrained intervals in subproperties', function() { + var packet = { + billboard : { + interval : '2010-01-01T00:00:00Z/2010-01-02T01:00:00Z', + scaleByDistance : [{ + interval : '2009-01-01T00:00:00Z/2010-01-01T00:30:00Z', + nearFarScalar : [1.0, 2.0, 10000.0, 3.0] + }, { + interval : '2010-01-01T00:30:00Z/2011-01-01T00:00:00Z', + nearFarScalar : [2.0, 3.0, 20000.0, 4.0] + }] + }, + ellipsoid : { + interval : '2010-01-01T00:00:00Z/2010-01-02T01:00:00Z', + material : [{ + interval : '2009-01-01T00:00:00Z/2010-01-01T00:30:00Z', + solidColor : { + color : { + rgbaf : [0.1, 0.2, 0.3, 0.4] + } + } + }, { + interval : '2010-01-01T00:30:00Z/2011-01-01T00:00:00Z', + solidColor : { + color : { + rgbaf : [0.5, 0.4, 0.3, 0.2] + } + } + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.billboard).toBeDefined(); + expect(entity.ellipsoid).toBeDefined(); + + // before billboard interval: not defined, even though the scaleByDistance includes the time in its intervals + var time = JulianDate.fromIso8601('2009-01-01T00:00:00Z'); + expect(entity.billboard.scaleByDistance.getValue(time)).toBeUndefined(); + expect(entity.ellipsoid.material.getValue(time)).toBeUndefined(); + + // within both billboard and scaleByDistance intervals + time = JulianDate.fromIso8601('2010-01-01T00:05:00Z'); + expect(entity.billboard.scaleByDistance.getValue(time)).toEqual(NearFarScalar.unpack(packet.billboard.scaleByDistance[0].nearFarScalar)); + expect(entity.ellipsoid.material.getValue(time).color).toEqual(Color.unpack(packet.ellipsoid.material[0].solidColor.color.rgbaf)); + + time = JulianDate.fromIso8601('2010-01-01T00:35:00Z'); + expect(entity.billboard.scaleByDistance.getValue(time)).toEqual(NearFarScalar.unpack(packet.billboard.scaleByDistance[1].nearFarScalar)); + expect(entity.ellipsoid.material.getValue(time).color).toEqual(Color.unpack(packet.ellipsoid.material[1].solidColor.color.rgbaf)); + + // after billboard interval: not defined, even though the scaleByDistance includes the time in its intervals + time = JulianDate.fromIso8601('2010-01-03T00:00:00Z'); + expect(entity.billboard.scaleByDistance.getValue(time)).toBeUndefined(); + expect(entity.ellipsoid.material.getValue(time)).toBeUndefined(); + }); + }); + + it('can constrain a constant property by sending an interval in a subsequent packet', function() { + var constantPacket = { + id: 'a', + billboard: { + scale: 1.0 + } + }; + + // loading a value with an interval makes the previously constant property into a composite. + var intervalPacket = { + id: 'a', + billboard: { + scale: { + interval: '2010-01-01T00:00:00Z/2010-01-02T01:00:00Z', + number: 2.0 + } + } + }; + + return CzmlDataSource.load(makeDocument(constantPacket)).then(function(dataSource) { + return dataSource.process(intervalPacket); + }).then(function(dataSource) { + var entity = dataSource.entities.getById('a'); + + expect(entity.billboard).toBeDefined(); + expect(entity.billboard.scale).toBeInstanceOf(CompositeProperty); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2009-01-01T00:00:00Z'))).toEqual(constantPacket.billboard.scale); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T00:00:00Z'))).toEqual(intervalPacket.billboard.scale.number); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2011-01-01T00:00:00Z'))).toEqual(constantPacket.billboard.scale); + }); + }); + + it('can constrain a constant position property by sending an interval in a subsequent packet', function() { + var constantPacket = { + id: 'a', + position: { + cartographicDegrees: [34, 117, 0] + } + }; + // loading a value with an interval makes the previously constant property into a composite. + var intervalPacket = { + id: 'a', + position: { + interval: '2010-01-01T00:00:00Z/2010-01-02T01:00:00Z', + cartographicDegrees: [40, 100, 0] + } + }; + + return CzmlDataSource.load(makeDocument(constantPacket)).then(function(dataSource) { + return dataSource.process(intervalPacket); + }).then(function(dataSource) { + var entity = dataSource.entities.getById('a'); + + expect(entity.position).toBeDefined(); + expect(entity.position).toBeInstanceOf(CompositePositionProperty); + expect(entity.position.getValue(JulianDate.fromIso8601('2009-01-01T00:00:00Z'))).toEqual(cartesianFromArrayDegrees(constantPacket.position.cartographicDegrees)); + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T00:00:00Z'))).toEqual(cartesianFromArrayDegrees(intervalPacket.position.cartographicDegrees)); + expect(entity.position.getValue(JulianDate.fromIso8601('2011-01-01T00:00:00Z'))).toEqual(cartesianFromArrayDegrees(constantPacket.position.cartographicDegrees)); + }); + }); + + it('can convert a sampled property to a composite by sending intervals in a subsequent packet', function() { + var sampledPacket = { + id: 'a', + billboard: { + scale: { + number: [ + '2010-01-01T00:00:00Z', 1, + '2010-01-01T01:00:00Z', 2, + '2010-01-01T02:00:00Z', 3 + ] + } + } + }; + // loading a value with an interval makes the property into a composite. + var intervalPacket = { + id: 'a', + billboard: { + scale: [{ + interval: '2010-01-01T00:20:00Z/2010-01-01T00:22:00Z', + number: [ + '2010-01-01T00:20:00Z', 10, + '2010-01-01T00:22:00Z', 20 + ] + }] + } + }; + + return CzmlDataSource.load(makeDocument(sampledPacket)).then(function(dataSource) { + return dataSource.process(intervalPacket); + }).then(function(dataSource) { + var entity = dataSource.entities.getById('a'); + + expect(entity.billboard).toBeDefined(); + expect(entity.billboard.scale).toBeInstanceOf(CompositeProperty); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T00:00:00Z'))).toEqual(1.0); + + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T00:20:00Z'))).toEqual(10.0); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T00:21:00Z'))).toEqual(15.0); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T00:22:00Z'))).toEqual(20.0); + + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T01:00:00Z'))).toEqual(2.0); + expect(entity.billboard.scale.getValue(JulianDate.fromIso8601('2010-01-01T02:00:00Z'))).toEqual(3.0); + }); + }); + + it('can convert a sampled position property to a composite by sending intervals in a subsequent packet', function() { + var sampledPacket = { + id: 'a', + position : { + cartographicDegrees : [ + '2010-01-01T00:00:00Z', 34, 117, 10000, + '2010-01-01T01:00:00Z', 34, 117, 20000 + ] + } + }; + // loading a value with an interval makes the property into a composite. + var intervalPacket = { + id: 'a', + position: [{ + interval: '2010-01-01T00:20:00Z/2010-01-01T00:22:00Z', + cartographicDegrees: [ + '2010-01-01T00:20:00Z', 40, 100, 10000, + '2010-01-01T00:22:00Z', 40, 100, 20000 + ] + }] + }; + + return CzmlDataSource.load(makeDocument(sampledPacket)).then(function(dataSource) { + return dataSource.process(intervalPacket); + }).then(function(dataSource) { + var entity = dataSource.entities.getById('a'); + + expect(entity.position).toBeDefined(); + expect(entity.position).toBeInstanceOf(CompositePositionProperty); + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T00:00:00Z'))).toEqual(Cartesian3.fromDegrees(34, 117, 10000)); + + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T00:20:00Z'))).toEqual(Cartesian3.fromDegrees(40, 100, 10000)); + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T00:21:00Z'))).toEqualEpsilon(Cartesian3.fromDegrees(40, 100, 15000), CesiumMath.EPSILON10); + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T00:22:00Z'))).toEqual(Cartesian3.fromDegrees(40, 100, 20000)); + + expect(entity.position.getValue(JulianDate.fromIso8601('2010-01-01T01:00:00Z'))).toEqual(Cartesian3.fromDegrees(34, 117, 20000)); + }); + }); + it('can handle sampled billboard pixelOffset.', function() { var epoch = JulianDate.now(); - var billboardPacket = { + var packet = { billboard : { pixelOffset : { epoch : JulianDate.toIso8601(epoch), - cartesian2 : [0.0, 1.0, 2.0, - 1.0, 3.0, 4.0] + cartesian2 : [ + 0.0, 1.0, 2.0, + 1.0, 3.0, 4.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); @@ -722,8 +930,8 @@ defineSuite([ }); }); - it('can handle interval billboard scaleByDistance.', function() { - var billboardPacket = { + it('can handle interval billboard scaleByDistance', function() { + var packet = { billboard : { scaleByDistance : [{ interval : '2013-01-01T00:00:00Z/2013-01-01T01:00:00Z', @@ -735,20 +943,19 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); - expect(entity.billboard.scaleByDistance.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toEqual(new NearFarScalar(1.0, 2.0, 10000.0, 3.0)); - expect(entity.billboard.scaleByDistance.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toEqual(new NearFarScalar(2.0, 3.0, 20000.0, 4.0)); + expect(entity.billboard.scaleByDistance.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toEqual(NearFarScalar.unpack(packet.billboard.scaleByDistance[0].nearFarScalar)); + expect(entity.billboard.scaleByDistance.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toEqual(NearFarScalar.unpack(packet.billboard.scaleByDistance[1].nearFarScalar)); }); }); - it('can handle sampled billboard scaleByDistance.', function() { + it('can handle sampled billboard scaleByDistance', function() { var epoch = JulianDate.now(); - var billboardPacket = { + var packet = { billboard : { scaleByDistance : { epoch : JulianDate.toIso8601(epoch), @@ -760,8 +967,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); @@ -777,18 +983,19 @@ defineSuite([ it('can handle sampled billboard color rgba.', function() { var epoch = JulianDate.now(); - var billboardPacket = { + var packet = { billboard : { color : { epoch : JulianDate.toIso8601(epoch), - rgba : [0, 200, 202, 204, 206, - 2, 0, 0, 0, 0] + rgba : [ + 0, 200, 202, 204, 206, + 2, 0, 0, 0, 0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(billboardPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.billboard).toBeDefined(); @@ -802,7 +1009,7 @@ defineSuite([ }); it('can handle clock data.', function() { - var clockPacket = { + var documentPacket = { id : 'document', version : '1.0', clock : { @@ -815,127 +1022,123 @@ defineSuite([ }; var interval = TimeInterval.fromIso8601({ - iso8601 : clockPacket.clock.interval + iso8601 : documentPacket.clock.interval }); - var currentTime = JulianDate.fromIso8601(clockPacket.clock.currentTime); - var multiplier = clockPacket.clock.multiplier; - var range = ClockRange[clockPacket.clock.range]; - var step = ClockStep[clockPacket.clock.step]; - - var dataSource = new CzmlDataSource(); - return dataSource.load(clockPacket).then(function(dataSource) { + return CzmlDataSource.load(documentPacket).then(function(dataSource) { + var clock = dataSource.clock; - expect(dataSource.clock).toBeDefined(); - expect(dataSource.clock.startTime).toEqual(interval.start); - expect(dataSource.clock.stopTime).toEqual(interval.stop); - expect(dataSource.clock.currentTime).toEqual(currentTime); - expect(dataSource.clock.clockRange).toEqual(range); - expect(dataSource.clock.clockStep).toEqual(step); - expect(dataSource.clock.multiplier).toEqual(multiplier); + expect(clock).toBeDefined(); + expect(clock.startTime).toEqual(interval.start); + expect(clock.stopTime).toEqual(interval.stop); + expect(clock.currentTime).toEqual(JulianDate.fromIso8601(documentPacket.clock.currentTime)); + expect(clock.clockRange).toEqual(ClockRange[documentPacket.clock.range]); + expect(clock.clockStep).toEqual(ClockStep[documentPacket.clock.step]); + expect(clock.multiplier).toEqual(documentPacket.clock.multiplier); }); }); - it('can handle position specified as constant cartographicsDegrees.', function() { - var czml = { - position : { - cartographicDegrees : [34, 117, 10000] + it('can handle position specified as constant cartographicsDegrees', function() { + var packet = { + position: { + cartographicDegrees: [34, 117, 10000] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.position.getValue(JulianDate.now()); - expect(resultCartesian).toEqual(Cartesian3.fromDegrees(34, 117, 10000)); + expect(resultCartesian).toEqual(cartesianFromArrayDegrees(packet.position.cartographicDegrees)); }); }); - it('can handle position specified as sampled cartographicsDegrees.', function() { + it('can handle position specified as sampled cartographicsDegrees', function() { var epoch = JulianDate.now(); - var czml = { + var packet = { position : { epoch : JulianDate.toIso8601(epoch), - cartographicDegrees : [0, 34, 117, 10000, - 1, 34, 117, 20000] + cartographicDegrees : [ + 0, 34, 117, 10000, + 1, 34, 117, 20000 + ] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.position.getValue(epoch); - expect(resultCartesian).toEqual(Cartesian3.fromDegrees(34, 117, 10000)); + expect(resultCartesian).toEqual(cartesianFromArrayDegrees(packet.position.cartographicDegrees, 1)); resultCartesian = entity.position.getValue(JulianDate.addSeconds(epoch, 1, new JulianDate())); - expect(resultCartesian).toEqual(Cartesian3.fromDegrees(34, 117, 20000)); + expect(resultCartesian).toEqual(cartesianFromArrayDegrees(packet.position.cartographicDegrees, 5)); }); }); - it('can handle position specified as sampled cartographicDegrees without epoch.', function() { + it('can handle position specified as sampled cartographicDegrees without epoch', function() { var lastDate = JulianDate.now(); var firstDate = new JulianDate(lastDate.dayNumber - 1, 0); - var czml = { + var packet = { position : { - cartographicDegrees : [JulianDate.toIso8601(firstDate), 34, 117, 10000, - JulianDate.toIso8601(lastDate), 34, 117, 20000] + cartographicDegrees : [ + JulianDate.toIso8601(firstDate), 34, 117, 10000, + JulianDate.toIso8601(lastDate), 34, 117, 20000 + ] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.position.getValue(firstDate); - expect(resultCartesian).toEqual(Cartesian3.fromDegrees(34, 117, 10000)); + expect(resultCartesian).toEqual(cartesianFromArrayDegrees(packet.position.cartographicDegrees, 1)); resultCartesian = entity.position.getValue(lastDate); - expect(resultCartesian).toEqual(Cartesian3.fromDegrees(34, 117, 20000)); + expect(resultCartesian).toEqual(cartesianFromArrayDegrees(packet.position.cartographicDegrees, 5)); }); }); - it('can handle position specified as constant cartographicRadians.', function() { - var czml = { + it('can handle position specified as constant cartographicRadians', function() { + var packet = { position : { cartographicRadians : [1, 2, 10000] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.position.getValue(JulianDate.now()); - expect(resultCartesian).toEqual(Cartesian3.fromRadians(1, 2, 10000)); + expect(resultCartesian).toEqual(cartesianFromArrayRadians(packet.position.cartographicRadians)); }); }); - it('can handle position specified as sampled cartographicRadians.', function() { + it('can handle position specified as sampled cartographicRadians', function() { var epoch = JulianDate.now(); - var czml = { + var packet = { position : { epoch : JulianDate.toIso8601(epoch), - cartographicRadians : [0, 2, 0.3, 10000, - 1, 0.2, 0.5, 20000] + cartographicRadians : [ + 0, 2, 0.3, 10000, + 1, 0.2, 0.5, 20000 + ] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.position.getValue(epoch); - expect(resultCartesian).toEqual(Cartesian3.fromRadians(2, 0.3, 10000)); + expect(resultCartesian).toEqual(cartesianFromArrayRadians(packet.position.cartographicRadians, 1)); resultCartesian = entity.position.getValue(JulianDate.addSeconds(epoch, 1, new JulianDate())); - expect(resultCartesian).toEqual(Cartesian3.fromRadians(0.2, 0.5, 20000)); + expect(resultCartesian).toEqual(cartesianFromArrayRadians(packet.position.cartographicRadians, 5)); }); }); - it('Can set reference frame', function() { + it('can set position reference frame', function() { var epoch = JulianDate.now(); var dataSource = new CzmlDataSource(); - var czml = { + var packet = { position : { referenceFrame : 'INERTIAL', epoch : JulianDate.toIso8601(epoch), @@ -943,11 +1146,11 @@ defineSuite([ } }; - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return dataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.referenceFrame).toBe(ReferenceFrame.INERTIAL); + expect(entity.position.referenceFrame).toEqual(ReferenceFrame.INERTIAL); - czml = { + packet = { position: { referenceFrame: 'FIXED', epoch: JulianDate.toIso8601(epoch), @@ -955,35 +1158,34 @@ defineSuite([ } }; - return dataSource.load(makePacket(czml)); + return dataSource.load(makeDocument(packet)); }).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.referenceFrame).toBe(ReferenceFrame.FIXED); + expect(entity.position.referenceFrame).toEqual(ReferenceFrame.FIXED); }); }); - it('uses FIXED as default if not specified in CZML', function() { + it('uses FIXED as default position reference frame if not specified in CZML', function() { var epoch = JulianDate.now(); - var dataSource = new CzmlDataSource(); - var czml = { + var packet = { position : { epoch : JulianDate.toIso8601(epoch), cartesian : [1.0, 2.0, 3.0] } }; - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.referenceFrame).toBe(ReferenceFrame.FIXED); + expect(entity.position.referenceFrame).toEqual(ReferenceFrame.FIXED); }); }); - it('Default reference frame on existing interval does not reset value to FIXED.', function() { + it('does not reset value to FIXED when omitting reference frame on subsequent packet', function() { var epoch = JulianDate.now(); var dataSource = new CzmlDataSource(); - var czml = { + var packet = { position : { referenceFrame : 'INERTIAL', epoch : JulianDate.toIso8601(epoch), @@ -991,39 +1193,40 @@ defineSuite([ } }; - return dataSource.process(makePacket(czml)).then(function(dataSource) { + return dataSource.process(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.referenceFrame).toBe(ReferenceFrame.INERTIAL); + expect(entity.position.referenceFrame).toEqual(ReferenceFrame.INERTIAL); - var czml2 = { + packet = { position: { epoch: JulianDate.toIso8601(epoch), cartesian: [1.0, 2.0, 3.0] } }; - return dataSource.process(czml2); + return dataSource.process(packet); }).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.referenceFrame).toBe(ReferenceFrame.INERTIAL); + expect(entity.position.referenceFrame).toEqual(ReferenceFrame.INERTIAL); }); }); - it('can handle a number specified as sampled values without epoch.', function() { + it('can load a number specified as sampled values without epoch.', function() { var firstDate = Iso8601.MINIMUM_VALUE; var midDate = JulianDate.addDays(firstDate, 1, new JulianDate()); var lastDate = JulianDate.addDays(firstDate, 2, new JulianDate()); - var ellipsePacket = { + var packet = { ellipse : { semiMajorAxis : { - number : [JulianDate.toIso8601(firstDate), 0, - JulianDate.toIso8601(lastDate), 10] + number : [ + JulianDate.toIso8601(firstDate), 0, + JulianDate.toIso8601(lastDate), 10 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(ellipsePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.ellipse).toBeDefined(); @@ -1033,8 +1236,8 @@ defineSuite([ }); }); - it('can handle a direction specified as constant unitSpherical', function() { - var czml = { + it('can load a direction specified as constant unitSpherical', function() { + var packet = { billboard : { alignedAxis : { unitSpherical : [1.0, 2.0] @@ -1042,29 +1245,29 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.billboard.alignedAxis.getValue(JulianDate.now()); expect(resultCartesian).toEqual(Cartesian3.fromSpherical(new Spherical(1.0, 2.0))); }); }); - it('can handle a direction specified as sampled unitSpherical.', function() { + it('can load a direction specified as sampled unitSpherical', function() { var epoch = JulianDate.now(); - var czml = { + var packet = { billboard : { alignedAxis : { epoch : JulianDate.toIso8601(epoch), - unitSpherical : [0, 1.0, 2.0, - 1, -1.0, -2.0] + unitSpherical : [ + 0, 1.0, 2.0, + 1, -1.0, -2.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.billboard.alignedAxis.getValue(epoch); expect(resultCartesian).toEqual(Cartesian3.fromSpherical(new Spherical(1.0, 2.0))); @@ -1074,8 +1277,8 @@ defineSuite([ }); }); - it('can handle a direction specified as constant spherical', function() { - var czml = { + it('can load a direction specified as constant spherical', function() { + var packet = { billboard : { alignedAxis : { spherical : [1.0, 2.0, 30.0] @@ -1083,8 +1286,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.billboard.alignedAxis.getValue(JulianDate.now()); var expected = Cartesian3.fromSpherical(new Spherical(1.0, 2.0, 30.0)); @@ -1093,21 +1295,22 @@ defineSuite([ }); }); - it('can handle a direction specified as sampled spherical.', function() { + it('can load a direction specified as sampled spherical', function() { var epoch = JulianDate.now(); - var czml = { + var packet = { billboard : { alignedAxis : { epoch : JulianDate.toIso8601(epoch), - spherical : [0, 1.0, 2.0, 30.0, - 1, -1.0, -2.0, 40.0] + spherical : [ + 0, 1.0, 2.0, 30.0, + 1, -1.0, -2.0, 40.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(czml)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var resultCartesian = entity.billboard.alignedAxis.getValue(epoch); var expected = Cartesian3.fromSpherical(new Spherical(1.0, 2.0, 30.0)); @@ -1121,8 +1324,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite ellipse.', function() { - var ellipsePacket = { + it('can load constant data for ellipse', function() { + var packet = { ellipse : { semiMajorAxis : 10, semiMinorAxis : 20, @@ -1138,25 +1341,24 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(ellipsePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.ellipse).toBeDefined(); - expect(entity.ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMajorAxis); - expect(entity.ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMinorAxis); - expect(entity.ellipse.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.rotation); - expect(entity.ellipse.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.ellipse.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.ellipse.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.ellipse.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.ellipse.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(8); - expect(entity.ellipse.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType.TERRAIN); + expect(entity.ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.semiMajorAxis); + expect(entity.ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.semiMinorAxis); + expect(entity.ellipse.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.rotation); + expect(entity.ellipse.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.outline); + expect(entity.ellipse.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.ellipse.outlineColor.rgbaf)); + expect(entity.ellipse.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.outlineWidth); + expect(entity.ellipse.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.ellipse.shadows]); + expect(entity.ellipse.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipse.zIndex); + expect(entity.ellipse.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType[packet.ellipse.classificationType]); }); }); - it('CZML adds data for constrained ellipse.', function() { - var ellipsePacketInterval = { + it('can load interval data for ellipse', function() { + var packet = { ellipse : { interval : '2000-01-01/2001-01-01', semiMajorAxis : 10, @@ -1166,20 +1368,19 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(ellipsePacketInterval)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var validTime = TimeInterval.fromIso8601({ - iso8601: ellipsePacketInterval.ellipse.interval + iso8601: packet.ellipse.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); expect(entity.ellipse).toBeDefined(); - expect(entity.ellipse.semiMajorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMajorAxis); - expect(entity.ellipse.semiMinorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMinorAxis); - expect(entity.ellipse.rotation.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.rotation); - expect(entity.ellipse.shadows.getValue(validTime)).toEqual(ShadowMode.ENABLED); + expect(entity.ellipse.semiMajorAxis.getValue(validTime)).toEqual(packet.ellipse.semiMajorAxis); + expect(entity.ellipse.semiMinorAxis.getValue(validTime)).toEqual(packet.ellipse.semiMinorAxis); + expect(entity.ellipse.rotation.getValue(validTime)).toEqual(packet.ellipse.rotation); + expect(entity.ellipse.shadows.getValue(validTime)).toEqual(ShadowMode[packet.ellipse.shadows]); expect(entity.ellipse.semiMajorAxis.getValue(invalidTime)).toBeUndefined(); expect(entity.ellipse.semiMinorAxis.getValue(invalidTime)).toBeUndefined(); @@ -1188,10 +1389,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite ellipsoid.', function() { - var expectedRadii = new Cartesian3(1.0, 2.0, 3.0); - - var ellipsoidPacket = { + it('can load constant data for ellipsoid', function() { + var packet = { ellipsoid : { radii : { cartesian : [1.0, 2.0, 3.0] @@ -1216,28 +1415,25 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(ellipsoidPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.ellipsoid).toBeDefined(); - expect(entity.ellipsoid.radii.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedRadii); - expect(entity.ellipsoid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsoidPacket.ellipsoid.show); - expect(entity.ellipsoid.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.ellipsoid.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.ellipsoid.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.ellipsoid.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.ellipsoid.stackPartitions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(25); - expect(entity.ellipsoid.slicePartitions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(26); - expect(entity.ellipsoid.subdivisions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(27); - expect(entity.ellipsoid.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); + expect(entity.ellipsoid.radii.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.ellipsoid.radii.cartesian)); + expect(entity.ellipsoid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.show); + expect(entity.ellipsoid.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.ellipsoid.material.solidColor.color.rgbaf)); + expect(entity.ellipsoid.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.outline); + expect(entity.ellipsoid.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.ellipsoid.outlineColor.rgbaf)); + expect(entity.ellipsoid.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.outlineWidth); + expect(entity.ellipsoid.stackPartitions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.stackPartitions); + expect(entity.ellipsoid.slicePartitions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.slicePartitions); + expect(entity.ellipsoid.subdivisions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.ellipsoid.subdivisions); + expect(entity.ellipsoid.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.ellipsoid.shadows]); }); }); - it('CZML adds data for constrained ellipsoid.', function() { - var expectedRadii = new Cartesian3(1.0, 2.0, 3.0); - - var ellipsoidPacketInterval = { + it('can load interval data for ellipsoid', function() { + var packet = { ellipsoid : { interval : '2000-01-01/2001-01-01', radii : { @@ -1256,19 +1452,18 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601: ellipsoidPacketInterval.ellipsoid.interval + iso8601: packet.ellipsoid.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(ellipsoidPacketInterval)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.ellipsoid).toBeDefined(); - expect(entity.ellipsoid.radii.getValue(validTime)).toEqual(expectedRadii); - expect(entity.ellipsoid.show.getValue(validTime)).toEqual(ellipsoidPacketInterval.ellipsoid.show); - expect(entity.ellipsoid.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.ellipsoid.shadows.getValue(validTime)).toEqual(ShadowMode.ENABLED); + expect(entity.ellipsoid.radii.getValue(validTime)).toEqual(Cartesian3.unpack(packet.ellipsoid.radii.cartesian)); + expect(entity.ellipsoid.show.getValue(validTime)).toEqual(packet.ellipsoid.show); + expect(entity.ellipsoid.material.getValue(validTime).color).toEqual(Color.unpack(packet.ellipsoid.material.solidColor.color.rgbaf)); + expect(entity.ellipsoid.shadows.getValue(validTime)).toEqual(ShadowMode[packet.ellipsoid.shadows]); expect(entity.ellipsoid.radii.getValue(invalidTime)).toBeUndefined(); expect(entity.ellipsoid.show.getValue(invalidTime)).toBeUndefined(); @@ -1277,8 +1472,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite label.', function() { - var labelPacket = { + it('can load constant data for label', function() { + var packet = { label : { text : 'TestFacility', font : '10pt "Open Sans"', @@ -1309,30 +1504,29 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(labelPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.label).toBeDefined(); - expect(entity.label.text.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.text); - expect(entity.label.font.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.font); - expect(entity.label.style.getValue(Iso8601.MINIMUM_VALUE)).toEqual(LabelStyle.FILL); - expect(entity.label.fillColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.label.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.label.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.outlineWidth); - expect(entity.label.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.LEFT); - expect(entity.label.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); - expect(entity.label.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(entity.label.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(4.0, 5.0)); - expect(entity.label.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.scale); - expect(entity.label.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.show); - expect(entity.label.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 1.0, 10000.0, 0.0)); - expect(entity.label.pixelOffsetScaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 20.0, 10000.0, 30.0)); - }); - }); - - it('CZML adds data for constrained label.', function() { - var labelPacket = { + expect(entity.label.text.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.label.text); + expect(entity.label.font.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.label.font); + expect(entity.label.style.getValue(Iso8601.MINIMUM_VALUE)).toEqual(LabelStyle[packet.label.style]); + expect(entity.label.fillColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.label.fillColor.rgbaf)); + expect(entity.label.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.label.outlineColor.rgbaf)); + expect(entity.label.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.label.outlineWidth); + expect(entity.label.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin[packet.label.horizontalOrigin]); + expect(entity.label.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin[packet.label.verticalOrigin]); + expect(entity.label.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.label.eyeOffset.cartesian)); + expect(entity.label.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian2.unpack(packet.label.pixelOffset.cartesian2)); + expect(entity.label.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.label.scale); + expect(entity.label.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.label.show); + expect(entity.label.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.label.translucencyByDistance.nearFarScalar)); + expect(entity.label.pixelOffsetScaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.label.pixelOffsetScaleByDistance.nearFarScalar)); + }); + }); + + it('can load interval data for label', function() { + var packet = { label : { interval : '2000-01-01/2001-01-01', text : 'TestFacility', @@ -1359,27 +1553,27 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601: labelPacket.label.interval + iso8601: packet.label.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(labelPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.label).toBeDefined(); - expect(entity.label.text.getValue(validTime)).toEqual(labelPacket.label.text); - expect(entity.label.font.getValue(validTime)).toEqual(labelPacket.label.font); - expect(entity.label.style.getValue(validTime)).toEqual(LabelStyle.FILL); - expect(entity.label.fillColor.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.label.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.label.outlineWidth.getValue(validTime)).toEqual(labelPacket.label.outlineWidth); - expect(entity.label.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.LEFT); - expect(entity.label.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); - expect(entity.label.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(entity.label.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(4.0, 5.0)); - expect(entity.label.scale.getValue(validTime)).toEqual(labelPacket.label.scale); - expect(entity.label.show.getValue(validTime)).toEqual(labelPacket.label.show); + expect(entity.label.text.getValue(validTime)).toEqual(packet.label.text); + expect(entity.label.font.getValue(validTime)).toEqual(packet.label.font); + expect(entity.label.style.getValue(validTime)).toEqual(LabelStyle[packet.label.style]); + expect(entity.label.fillColor.getValue(validTime)).toEqual(Color.unpack(packet.label.fillColor.rgbaf)); + expect(entity.label.outlineColor.getValue(validTime)).toEqual(Color.unpack(packet.label.outlineColor.rgbaf)); + expect(entity.label.outlineWidth.getValue(validTime)).toEqual(packet.label.outlineWidth); + expect(entity.label.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin[packet.label.horizontalOrigin]); + expect(entity.label.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin[packet.label.verticalOrigin]); + expect(entity.label.eyeOffset.getValue(validTime)).toEqual(Cartesian3.unpack(packet.label.eyeOffset.cartesian)); + expect(entity.label.pixelOffset.getValue(validTime)).toEqual(Cartesian2.unpack(packet.label.pixelOffset.cartesian2)); + expect(entity.label.scale.getValue(validTime)).toEqual(packet.label.scale); + expect(entity.label.show.getValue(validTime)).toEqual(packet.label.show); + expect(entity.label.text.getValue(invalidTime)).toBeUndefined(); expect(entity.label.font.getValue(invalidTime)).toBeUndefined(); expect(entity.label.style.getValue(invalidTime)).toBeUndefined(); @@ -1398,17 +1592,19 @@ defineSuite([ it('can handle sampled label pixelOffset.', function() { var epoch = JulianDate.now(); - var labelPacket = { + var packet = { label : { pixelOffset : { epoch : JulianDate.toIso8601(epoch), - cartesian2 : [0, 1, 2, 1, 3, 4] + cartesian2 : [ + 0, 1, 2, + 1, 3, 4 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(labelPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.label).toBeDefined(); @@ -1419,68 +1615,67 @@ defineSuite([ }); }); - it('CZML Position works.', function() { + it('can load position', function() { var packet = { position : { cartesian : [1.0, 2.0, 3.0] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.position.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + expect(entity.position.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.position.cartesian)); }); }); - it('CZML Orientation works.', function() { + it('can load orientation', function() { var packet = { orientation : { unitQuaternion : [0.0, 0.0, 0.0, 1.0] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.orientation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Quaternion(0.0, 0.0, 0.0, 1.0)); + expect(entity.orientation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Quaternion.unpack(packet.orientation.unitQuaternion)); }); }); - it('CZML Orientation is normalized on load.', function() { + it('normalizes constant orientation on load', function() { var packet = { orientation : { unitQuaternion : [0.0, 0.0, 0.7071067, 0.7071067] } }; - var expected = new Quaternion(0.0, 0.0, 0.7071067, 0.7071067); + var expected = Quaternion.unpack(packet.orientation.unitQuaternion); Quaternion.normalize(expected, expected); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.orientation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expected); }); }); - it('CZML Orientation is normalized on load.', function() { + it('normalizes sampled orientation on load', function() { var time1 = '2000-01-01T00:00:00Z'; var time2 = '2000-01-01T00:00:01Z'; var packet = { orientation : { - unitQuaternion : [time1, 0.0, 0.0, 0.7071067, 0.7071067, time2, 0.7071067, 0.7071067, 0.0, 0.0] + unitQuaternion : [ + time1, 0.0, 0.0, 0.7071067, 0.7071067, + time2, 0.7071067, 0.7071067, 0.0, 0.0 + ] } }; - var expected1 = new Quaternion(0.0, 0.0, 0.7071067, 0.7071067); + var expected1 = Quaternion.unpack(packet.orientation.unitQuaternion, 1); Quaternion.normalize(expected1, expected1); - var expected2 = new Quaternion(0.7071067, 0.7071067, 0.0, 0.0); + var expected2 = Quaternion.unpack(packet.orientation.unitQuaternion, 6); Quaternion.normalize(expected2, expected2); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.orientation.getValue(JulianDate.fromIso8601(time1))).toEqual(expected1); expect(entity.orientation.getValue(JulianDate.fromIso8601(time2))).toEqual(expected2); @@ -1491,16 +1686,17 @@ defineSuite([ var packet = { position: { epoch: '2016-06-17T12:00:00Z', - cartesian: [0, 1, 2, 3, - 60, 61, 122, 183] + cartesian: [ + 0, 1, 2, 3, + 60, 61, 122, 183 + ] }, orientation: { velocityReference: '#position' } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var property = entity.orientation; @@ -1516,91 +1712,85 @@ defineSuite([ }); }); - it('positions work with cartesians.', function() { - var expectedResult = [new Cartesian3(1.0, 2.0, 3.0), new Cartesian3(5.0, 6.0, 7.0)]; - + it('can load positions expressed as cartesians', function() { var packet = { polyline : { positions : { - cartesian : [expectedResult[0].x, expectedResult[0].y, expectedResult[0].z, expectedResult[1].x, expectedResult[1].y, expectedResult[1].z] + cartesian : [ + 1.0, 2.0, 3.0, + 5.0, 6.0, 7.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedResult); + expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpackArray(packet.polyline.positions.cartesian)); }); }); - it('positions work with cartographicRadians.', function() { - var input = [new Cartographic(1.0, 2.0, 4.0), new Cartographic(5.0, 6.0, 7.0)]; - var expectedResult = Ellipsoid.WGS84.cartographicArrayToCartesianArray(input); - + it('can load positions expressed as cartographicRadians', function() { var packet = { polyline : { positions : { - cartographicRadians : [input[0].longitude, input[0].latitude, input[0].height, input[1].longitude, input[1].latitude, input[1].height] + cartographicRadians : [ + 1.0, 2.0, 4.0, + 5.0, 6.0, 7.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedResult); + expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.fromRadiansArrayHeights(packet.polyline.positions.cartographicRadians)); }); }); - it('positions work with cartographicDegrees.', function() { - var expectedResult = Cartesian3.fromDegreesArrayHeights([ - 1.0, 2.0, 3.0, - 5.0, 6.0, 7.0 - ]); - + it('can load positions expressed as cartographicDegrees', function() { var packet = { polyline : { positions : { - cartographicDegrees : [1.0, 2.0, 3.0, 5.0, 6.0, 7.0] + cartographicDegrees : [ + 1.0, 2.0, 3.0, + 5.0, 6.0, 7.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedResult); + expect(entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polyline.positions.cartographicDegrees)); }); }); - it('CZML ViewFrom works.', function() { + it('can load viewFrom', function() { var packet = { viewFrom : { cartesian : [1.0, 2.0, 3.0] } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - expect(entity.viewFrom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + expect(entity.viewFrom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.viewFrom.cartesian)); }); }); - it('CZML description works.', function() { + it('can load description', function() { var packet = { description : 'this is a description' }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.description.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.description); }); }); - it('works with properties that are constant.', function() { + it('can load constant custom properties', function() { var testObject = { foo: 4, bar: { @@ -1608,6 +1798,7 @@ defineSuite([ } }; var testArray = [2, 4, 16, 'test']; + var packet = { properties: { constant_name: 'ABC', @@ -1621,8 +1812,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.properties.constant_name.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.properties.constant_name); expect(entity.properties.constant_height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.properties.constant_height); @@ -1631,7 +1821,7 @@ defineSuite([ }); }); - it('works with properties which are constant with specified type.', function() { + it('can load custom properties which are constant with specified type', function() { var testObject = { foo: 4, bar: { @@ -1656,8 +1846,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.properties.constant_name.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.properties.constant_name.string); expect(entity.properties.constant_height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.properties.constant_height.number); @@ -1666,7 +1855,7 @@ defineSuite([ }); }); - it('works with properties with one interval.', function() { + it('can load custom properties with one interval', function() { var packet = { properties: { changing_name: { @@ -1676,19 +1865,15 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - var time1 = JulianDate.fromIso8601('2013'); - var time2 = JulianDate.fromIso8601('2015'); - - expect(entity.properties.changing_name.getValue(time1)).toEqual('ABC'); - expect(entity.properties.changing_name.getValue(time2)).toBeUndefined(); + expect(entity.properties.changing_name.getValue(JulianDate.fromIso8601('2013'))).toEqual(packet.properties.changing_name.value); + expect(entity.properties.changing_name.getValue(JulianDate.fromIso8601('2015'))).toBeUndefined(); }); }); - it('works with properties with one interval with specified type.', function() { + it('can load custom properties with one interval with specified type', function() { var packet = { properties: { changing_name: { @@ -1698,19 +1883,15 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - var time1 = JulianDate.fromIso8601('2013'); - var time2 = JulianDate.fromIso8601('2015'); - - expect(entity.properties.changing_name.getValue(time1)).toEqual('ABC'); - expect(entity.properties.changing_name.getValue(time2)).toBeUndefined(); + expect(entity.properties.changing_name.getValue(JulianDate.fromIso8601('2013'))).toEqual(packet.properties.changing_name.string); + expect(entity.properties.changing_name.getValue(JulianDate.fromIso8601('2015'))).toBeUndefined(); }); }); - it('works with properties with multiple intervals.', function() { + it('can load custom properties with multiple intervals', function() { var array1 = [1, 2, 3]; var array2 = [4, 5, 6]; var packet = { @@ -1728,19 +1909,15 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - var time1 = JulianDate.fromIso8601('2012-06-01'); - var time2 = JulianDate.fromIso8601('2013-06-01'); - - expect(entity.properties.changing_array.getValue(time1)).toEqual(array1); - expect(entity.properties.changing_array.getValue(time2)).toEqual(array2); + expect(entity.properties.changing_array.getValue(JulianDate.fromIso8601('2012-06-01'))).toEqual(array1); + expect(entity.properties.changing_array.getValue(JulianDate.fromIso8601('2013-06-01'))).toEqual(array2); }); }); - it('handles boolean custom properties with intervals.', function() { + it('can load boolean custom properties with multiple intervals', function() { var packet = { id: 'MyID', properties: { @@ -1761,8 +1938,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('MyID'); expect(entity).toBeDefined(); expect(entity.properties).toBeDefined(); @@ -1774,7 +1950,7 @@ defineSuite([ }); }); - it('works with properties with multiple intervals with specified type.', function() { + it('can load custom properties with multiple intervals with specified type', function() { var array1 = [1, 2, 3]; var array2 = [4, 5, 6]; var packet = { @@ -1792,19 +1968,15 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; - var time1 = JulianDate.fromIso8601('2012-06-01'); - var time2 = JulianDate.fromIso8601('2013-06-01'); - - expect(entity.properties.changing_array.getValue(time1)).toEqual(array1); - expect(entity.properties.changing_array.getValue(time2)).toEqual(array2); + expect(entity.properties.changing_array.getValue(JulianDate.fromIso8601('2012-06-01'))).toEqual(array1); + expect(entity.properties.changing_array.getValue(JulianDate.fromIso8601('2013-06-01'))).toEqual(array2); }); }); - it('handles sampled custom properties.', function() { + it('can load sampled custom properties', function() { var packet = { id: 'MyID', properties: { @@ -1819,9 +1991,9 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('MyID'); + expect(entity).toBeDefined(); expect(entity.properties).toBeDefined(); expect(entity.properties.custom_cartesian).toBeDefined(); @@ -1835,7 +2007,7 @@ defineSuite([ }); }); - it('handles various types of custom properties.', function() { + it('can load various types of custom properties', function() { var interval1 = '2012/2013'; var interval2 = '2013/2014'; var packet = { @@ -1942,9 +2114,9 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('MyID'); + expect(entity).toBeDefined(); expect(entity.properties).toBeDefined(); @@ -2036,7 +2208,7 @@ defineSuite([ it('can delete an entire property', function() { function createDataSource() { - var packets = [{ + return CzmlDataSource.load([{ id: 'document', version: '1.0' }, { @@ -2056,12 +2228,12 @@ defineSuite([ id: 'test-sampled', billboard: { scale: { - number: ['2012-03-15T10:00:00Z', 1] + number: [ + '2012-03-15T10:00:00Z', 1 + ] } } - }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets); + }]); } var deletePackets = [{ @@ -2160,19 +2332,19 @@ defineSuite([ it('can delete a custom property', function() { function createDataSource() { - var packets = [{ + return CzmlDataSource.load([{ id: 'document', version: '1.0' }, { id: 'test', properties: { custom: { - number: ['2012-03-15T10:00:00Z', 1] + number: [ + '2012-03-15T10:00:00Z', 1 + ] } } - }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets); + }]); } var deletePackets = [{ @@ -2212,7 +2384,7 @@ defineSuite([ it('can delete an entire position property', function() { function createDataSource() { - var packets = [{ + return CzmlDataSource.load([{ id: 'document', version: '1.0' }, { @@ -2230,11 +2402,11 @@ defineSuite([ }, { id: 'test-sampled', position: { - cartographicDegrees: ['2012-03-15T10:00:00Z', 34, 117, 10000] + cartographicDegrees: [ + '2012-03-15T10:00:00Z', 34, 117, 10000 + ] } - }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets); + }]); } var deletePackets = [{ @@ -2276,25 +2448,25 @@ defineSuite([ function expectPropertiesToBeDefined(dataSource) { var entity = dataSource.entities.getById('test-constant'); - expect(entity.billboard.scale).toBeInstanceOf(ConstantProperty); + expect(entity.position).toBeInstanceOf(ConstantPositionProperty); entity = dataSource.entities.getById('test-interval'); - expect(entity.billboard.scale).toBeInstanceOf(TimeIntervalCollectionProperty); + expect(entity.position).toBeInstanceOf(TimeIntervalCollectionPositionProperty); entity = dataSource.entities.getById('test-sampled'); - expect(entity.billboard.scale).toBeInstanceOf(SampledProperty); + expect(entity.position).toBeInstanceOf(SampledPositionProperty); return dataSource; } function expectPropertiesToBeUndefined(dataSource) { var entity = dataSource.entities.getById('test-constant'); - expect(entity.billboard.scale).toBeUndefined(); + expect(entity.position).toBeUndefined(); entity = dataSource.entities.getById('test-interval'); - expect(entity.billboard.scale).toBeUndefined(); + expect(entity.position).toBeUndefined(); entity = dataSource.entities.getById('test-sampled'); - expect(entity.billboard.scale).toBeUndefined(); + expect(entity.position).toBeUndefined(); return dataSource; } - createDataSource() + return createDataSource() .then(expectPropertiesToBeDefined) .then(function(dataSource) { // delete with no interval specified should delete the properties entirely @@ -2333,7 +2505,7 @@ defineSuite([ } }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.billboard.scale).toBeInstanceOf(SampledProperty); @@ -2381,7 +2553,7 @@ defineSuite([ } }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.properties.custom).toBeInstanceOf(SampledProperty); @@ -2428,7 +2600,7 @@ defineSuite([ } }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.position).toBeInstanceOf(SampledPositionProperty); @@ -2474,7 +2646,7 @@ defineSuite([ } }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.billboard.scale).toBeInstanceOf(TimeIntervalCollectionProperty); @@ -2519,7 +2691,7 @@ defineSuite([ }] }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.position).toBeInstanceOf(TimeIntervalCollectionPositionProperty); @@ -2576,7 +2748,7 @@ defineSuite([ } }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.billboard.scale).toBeInstanceOf(CompositeProperty); @@ -2641,7 +2813,7 @@ defineSuite([ }] }; - return CzmlDataSource.load(makePacket(packet)) + return CzmlDataSource.load(makeDocument(packet)) .then(function(dataSource) { var entity = dataSource.entities.getById('id'); expect(entity.position).toBeInstanceOf(CompositePositionProperty); @@ -2680,7 +2852,7 @@ defineSuite([ }); }); - it('handles properties in a way that allows CompositeEntityCollection to work', function() { + it('can load custom properties in a way that allows CompositeEntityCollection to work', function() { var testObject1 = { foo: 4, bar: { @@ -2703,7 +2875,7 @@ defineSuite([ }; var dataSource1 = new CzmlDataSource(); - dataSource1.load(makePacket(packet1)); + dataSource1.load(makeDocument(packet1)); var dataSource2 = new CzmlDataSource(); var composite = new CompositeEntityCollection([dataSource1.entities, dataSource2.entities]); @@ -2723,7 +2895,7 @@ defineSuite([ } }; - dataSource2.load(makePacket(packet2)); + dataSource2.load(makeDocument(packet2)); entity = composite.values[0]; expect(entity.properties.constant_name.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet2.properties.constant_name); @@ -2758,7 +2930,7 @@ defineSuite([ expect(entity.properties.constant_array.getValue(Iso8601.MINIMUM_VALUE)).toEqual(testArray3); }); - it('CZML Availability works with a single interval.', function() { + it('can load and modify availability from a single interval', function() { var packet1 = { id : 'testObject', availability : '2000-01-01/2001-01-01' @@ -2770,7 +2942,7 @@ defineSuite([ }; var dataSource = new CzmlDataSource(); - return dataSource.process(makePacket(packet1)).then(function(dataSource) { + return dataSource.process(makeDocument(packet1)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var interval = TimeInterval.fromIso8601({ iso8601: packet1.availability @@ -2789,7 +2961,7 @@ defineSuite([ }); }); - it('CZML Availability works with multiple intervals.', function() { + it('can load and modify availability from multiple intervals', function() { var packet1 = { id : 'testObject', availability : ['2000-01-01/2001-01-01', '2002-01-01/2003-01-01'] @@ -2800,7 +2972,7 @@ defineSuite([ }; var dataSource = new CzmlDataSource(); - return dataSource.process(makePacket(packet1)).then(function(dataSource) { + return dataSource.process(makeDocument(packet1)).then(function(dataSource) { var entity = dataSource.entities.values[0]; var interval1 = TimeInterval.fromIso8601({ @@ -2828,8 +3000,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite path.', function() { - var pathPacket = { + it('can load constant data for path', function() { + var packet = { path : { material : { polylineOutline : { @@ -2850,24 +3022,23 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(pathPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.path).toBeDefined(); - expect(entity.path.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.width); - expect(entity.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.resolution); - expect(entity.path.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.path.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(1.0); - expect(entity.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.leadTime); - expect(entity.path.trailTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.trailTime); - expect(entity.path.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + expect(entity.path.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.path.material.polylineOutline.color.rgbaf)); + expect(entity.path.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.path.material.polylineOutline.outlineColor.rgbaf)); + expect(entity.path.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.material.polylineOutline.outlineWidth); + expect(entity.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.width); + expect(entity.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.resolution); + expect(entity.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.leadTime); + expect(entity.path.trailTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.trailTime); + expect(entity.path.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.path.show); }); }); - it('CZML adds data for constrained path.', function() { - var pathPacket = { + it('can load interval data for path', function() { + var packet = { path : { interval : '2000-01-01/2001-01-01', material : { @@ -2890,23 +3061,22 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : pathPacket.path.interval + iso8601 : packet.path.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(pathPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.path).toBeDefined(); - expect(entity.path.width.getValue(validTime)).toEqual(pathPacket.path.width); - expect(entity.path.resolution.getValue(validTime)).toEqual(pathPacket.path.resolution); - expect(entity.path.leadTime.getValue(validTime)).toEqual(pathPacket.path.leadTime); - expect(entity.path.trailTime.getValue(validTime)).toEqual(pathPacket.path.trailTime); - expect(entity.path.show.getValue(validTime)).toEqual(true); - expect(entity.path.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.path.material.getValue(validTime).outlineColor).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.path.material.getValue(validTime).outlineWidth).toEqual(1.0); + expect(entity.path.width.getValue(validTime)).toEqual(packet.path.width); + expect(entity.path.resolution.getValue(validTime)).toEqual(packet.path.resolution); + expect(entity.path.leadTime.getValue(validTime)).toEqual(packet.path.leadTime); + expect(entity.path.trailTime.getValue(validTime)).toEqual(packet.path.trailTime); + expect(entity.path.show.getValue(validTime)).toEqual(packet.path.show); + expect(entity.path.material.getValue(validTime).color).toEqual(Color.unpack(packet.path.material.polylineOutline.color.rgbaf)); + expect(entity.path.material.getValue(validTime).outlineColor).toEqual(Color.unpack(packet.path.material.polylineOutline.outlineColor.rgbaf)); + expect(entity.path.material.getValue(validTime).outlineWidth).toEqual(packet.path.material.polylineOutline.outlineWidth); expect(entity.path.material.getValue(invalidTime)).toBeUndefined(); expect(entity.path.width.getValue(invalidTime)).toBeUndefined(); @@ -2916,8 +3086,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite point.', function() { - var pointPacket = { + it('can load constant data for point', function() { + var packet = { point : { color : { rgbaf : [0.1, 0.1, 0.1, 0.1] @@ -2938,24 +3108,23 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(pointPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.point).toBeDefined(); - expect(entity.point.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.point.pixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.pixelSize); - expect(entity.point.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.point.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.outlineWidth); - expect(entity.point.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.point.scaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 2.0, 10000.0, 3.0)); - expect(entity.point.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new NearFarScalar(1.0, 1.0, 10000.0, 0.0)); - expect(entity.point.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference.CLAMP_TO_GROUND); + expect(entity.point.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.point.color.rgbaf)); + expect(entity.point.pixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.point.pixelSize); + expect(entity.point.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.point.outlineColor.rgbaf)); + expect(entity.point.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.point.outlineWidth); + expect(entity.point.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.point.show); + expect(entity.point.scaleByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.point.scaleByDistance.nearFarScalar)); + expect(entity.point.translucencyByDistance.getValue(Iso8601.MINIMUM_VALUE)).toEqual(NearFarScalar.unpack(packet.point.translucencyByDistance.nearFarScalar)); + expect(entity.point.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference[packet.point.heightReference]); }); }); - it('CZML adds data for constrained point.', function() { - var pointPacket = { + it('can load interval data for point', function() { + var packet = { point : { interval : '2000-01-01/2001-01-01', color : { @@ -2971,20 +3140,19 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : pointPacket.point.interval + iso8601 : packet.point.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(pointPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.point).toBeDefined(); - expect(entity.point.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.point.pixelSize.getValue(validTime)).toEqual(pointPacket.point.pixelSize); - expect(entity.point.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.point.outlineWidth.getValue(validTime)).toEqual(pointPacket.point.outlineWidth); - expect(entity.point.show.getValue(validTime)).toEqual(true); + expect(entity.point.color.getValue(validTime)).toEqual(Color.unpack(packet.point.color.rgbaf)); + expect(entity.point.pixelSize.getValue(validTime)).toEqual(packet.point.pixelSize); + expect(entity.point.outlineColor.getValue(validTime)).toEqual(Color.unpack(packet.point.outlineColor.rgbaf)); + expect(entity.point.outlineWidth.getValue(validTime)).toEqual(packet.point.outlineWidth); + expect(entity.point.show.getValue(validTime)).toEqual(packet.point.show); expect(entity.point.color.getValue(invalidTime)).toBeUndefined(); expect(entity.point.pixelSize.getValue(invalidTime)).toBeUndefined(); @@ -2994,8 +3162,8 @@ defineSuite([ }); }); - it('CZML adds data for infinite polygon.', function() { - var polygonPacket = { + it('can load constant data for polygon', function() { + var packet = { polygon : { material : { solidColor : { @@ -3022,31 +3190,30 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(polygonPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.polygon).toBeDefined(); - expect(entity.polygon.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.polygon.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.polygon.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(1); - expect(entity.polygon.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(2); - expect(entity.polygon.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(3); - expect(entity.polygon.stRotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(4); - expect(entity.polygon.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.polygon.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.polygon.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.polygon.closeTop.getValue(Iso8601.MINIMUM_VALUE)).toEqual(false); - expect(entity.polygon.closeBottom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(false); - expect(entity.polygon.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.polygon.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(3); - expect(entity.polygon.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType.TERRAIN); - }); - }); - - it('CZML adds data for constrained polygon.', function() { - var polygonPacket = { - polygon : { + expect(entity.polygon.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.polygon.material.solidColor.color.rgbaf)); + expect(entity.polygon.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.show); + expect(entity.polygon.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.height); + expect(entity.polygon.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.extrudedHeight); + expect(entity.polygon.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.granularity); + expect(entity.polygon.stRotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.stRotation); + expect(entity.polygon.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.outline); + expect(entity.polygon.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.polygon.outlineColor.rgbaf)); + expect(entity.polygon.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.outlineWidth); + expect(entity.polygon.closeTop.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.closeTop); + expect(entity.polygon.closeBottom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.closeBottom); + expect(entity.polygon.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.polygon.shadows]); + expect(entity.polygon.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polygon.zIndex); + expect(entity.polygon.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType[packet.polygon.classificationType]); + }); + }); + + it('can load interval data for polygon', function() { + var packet = { + polygon : { interval : '2000-01-01/2001-01-01', material : { solidColor : { @@ -3061,18 +3228,17 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : polygonPacket.polygon.interval + iso8601 : packet.polygon.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(polygonPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.polygon).toBeDefined(); - expect(entity.polygon.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.polygon.show.getValue(validTime)).toEqual(true); - expect(entity.polygon.shadows.getValue(validTime)).toEqual(ShadowMode.ENABLED); + expect(entity.polygon.material.getValue(validTime).color).toEqual(Color.unpack(packet.polygon.material.solidColor.color.rgbaf)); + expect(entity.polygon.show.getValue(validTime)).toEqual(packet.polygon.show); + expect(entity.polygon.shadows.getValue(validTime)).toEqual(ShadowMode[packet.polygon.shadows]); expect(entity.polygon.material.getValue(invalidTime)).toBeUndefined(); expect(entity.polygon.show.getValue(invalidTime)).toBeUndefined(); @@ -3080,8 +3246,439 @@ defineSuite([ }); }); - it('CZML adds data for infinite polyline.', function() { - var polylinePacket = { + it('can load constant polygon positions', function() { + var packet = { + polygon: { + positions: { + cartographicDegrees : [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + } + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(true); + + var hierarchy = entity.polygon.hierarchy.getValue(Iso8601.MINIMUM_VALUE); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions.cartographicDegrees)); + + hierarchy = entity.polygon.hierarchy.getValue(Iso8601.MINIMUM_VALUE, new PolygonHierarchy()); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions.cartographicDegrees)); + }); + }); + + function unpackPolygonHoleFromCartographicDegrees(holePositions) { + return new PolygonHierarchy(Cartesian3.fromDegreesArrayHeights(holePositions)); + } + + it('can load constant polygon positions with holes', function() { + var packet = { + polygon: { + positions: { + cartographicDegrees : [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + }, + holes: { + cartographicDegrees : [ + [ + -48.2, 39, 0, + -44.5, 37, 0, + -48.9, 33.1, 0, + -49, 36.6, 0 + ], + [ + -45.2, 21, 0, + -43.5, 27, 0, + -41.6, 21.1, 0 + ] + ] + } + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(true); + + var hierarchy = entity.polygon.hierarchy.getValue(Iso8601.MINIMUM_VALUE); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions.cartographicDegrees)); + expect(hierarchy.holes).toEqual(packet.polygon.holes.cartographicDegrees.map(unpackPolygonHoleFromCartographicDegrees)); + }); + }); + + it('can load interval polygon positions', function() { + var packet = { + polygon: { + positions: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicDegrees : [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + }, { + interval : '2012-08-04T16:20:00Z/2012-08-04T16:40:00Z', + cartographicDegrees: [ + -35, 50, 0, + -35, 10, 0, + -45, 30, 0 + ] + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + + var hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:10:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions[0].cartographicDegrees)); + + hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:20:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions[1].cartographicDegrees)); + }); + }); + + it('can load interval polygon positions with holes expressed as degrees', function() { + var packet = { + polygon: { + positions: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicDegrees : [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + }, { + interval : '2012-08-04T16:20:00Z/2012-08-04T16:40:00Z', + cartographicDegrees: [ + -35, 50, 0, + -35, 10, 0, + -45, 30, 0 + ] + }], + holes: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicDegrees : [ + [ + -48.2, 39, 0, + -44.5, 37, 0, + -48.9, 33.1, 0, + -49, 36.6, 0 + ], + [ + -45.2, 21, 0, + -43.5, 27, 0, + -41.6, 21.1, 0 + ] + ] + }, { + interval : '2012-08-04T16:20:00Z/2012-08-04T16:40:00Z', + cartographicDegrees: [ + [ + -40, 34, 0, + -37, 26, 0, + -41.2, 31, 0 + ] + ] + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + + var hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:10:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions[0].cartographicDegrees)); + expect(hierarchy.holes).toEqual(packet.polygon.holes[0].cartographicDegrees.map(unpackPolygonHoleFromCartographicDegrees)); + + hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:20:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromDegreesArrayHeights(packet.polygon.positions[1].cartographicDegrees)); + expect(hierarchy.holes).toEqual(packet.polygon.holes[1].cartographicDegrees.map(unpackPolygonHoleFromCartographicDegrees)); + }); + }); + + function unpackPolygonHoleFromCartographicRadians(holePositions) { + return new PolygonHierarchy(Cartesian3.fromRadiansArrayHeights(holePositions)); + } + + it('can load interval polygon positions with holes expressed as radians', function() { + var packet = { + polygon: { + positions: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicRadians : [ + -0.8726646259971648, 0.3490658503988659, 0, + -0.8726646259971648, 0.6981317007977318, 0, + -0.6981317007977318, 0.6981317007977318, 0, + -0.6981317007977318, 0.3490658503988659, 0 + ] + }], + holes: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicRadians : [ + [ + -0.8412486994612669, 0.6806784082777885, 0, + -0.7766715171374766, 0.6457718232379019, 0, + -0.8534660042252271, 0.5777039824101231, 0, + -0.8552113334772214, 0.6387905062299246, 0 + ] + ] + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + + var hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:10:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.fromRadiansArrayHeights(packet.polygon.positions[0].cartographicRadians)); + expect(hierarchy.holes).toEqual(packet.polygon.holes[0].cartographicRadians.map(unpackPolygonHoleFromCartographicRadians)); + }); + }); + + function unpackPolygonHoleFromCartesian(holePositions) { + return new PolygonHierarchy(Cartesian3.unpackArray(holePositions)); + } + + it('can load interval polygon positions with holes expressed as cartesian', function() { + var packet = { + polygon: { + positions: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartesian : [ + -35, 50, 0, + -35, 10, 0, + -45, 30, 0 + ] + }], + holes: [{ + interval : '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartesian : [ + [ + -40, 34, 0, + -37, 26, 0, + -41.2, 31, 0 + ] + ] + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + + var hierarchy = entity.polygon.hierarchy.getValue(JulianDate.fromIso8601('2012-08-04T16:10:00Z')); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(Cartesian3.unpackArray(packet.polygon.positions[0].cartesian)); + expect(hierarchy.holes).toEqual(packet.polygon.holes[0].cartesian.map(unpackPolygonHoleFromCartesian)); + }); + }); + + it('can load reference polygon positions with holes', function() { + var packets = [{ + id : 'document', + version : '1.0' + }, { + id : 'target1', + position : { + cartesian : [1.0, 2.0, 3.0] + } + }, { + id : 'target2', + position : { + cartesian : [4.0, 5.0, 6.0] + } + }, { + id : 'target3', + position : { + cartesian : [7.0, 8.0, 9.0] + } + }, { + id : 'target4', + position : { + cartesian : [1.5, 2.5, 3.5] + } + }, { + id : 'target5', + position : { + cartesian : [1.5, 2.6, 3.5] + } + }, { + id : 'target6', + position : { + cartesian : [1.6, 2.5, 3.5] + } + }, { + id : 'polygon', + polygon : { + positions : { + references : [ + 'target1#position', + 'target2#position', + 'target3#position' + ] + }, + holes: { + references : [ + [ + 'target4#position', + 'target5#position', + 'target6#position' + ] + ] + } + } + }]; + + return CzmlDataSource.load(packets).then(function(dataSource) { + var entity = dataSource.entities.getById('polygon'); + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(true); + + var time = JulianDate.fromIso8601('2012-08-04T16:10:00Z'); + var hierarchy = entity.polygon.hierarchy.getValue(time); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual([ + dataSource.entities.getById('target1').position.getValue(time), + dataSource.entities.getById('target2').position.getValue(time), + dataSource.entities.getById('target3').position.getValue(time) + ]); + expect(hierarchy.holes).toEqual([ + new PolygonHierarchy([ + dataSource.entities.getById('target4').position.getValue(time), + dataSource.entities.getById('target5').position.getValue(time), + dataSource.entities.getById('target6').position.getValue(time) + ]) + ]); + }); + }); + + it('reports correct value of isConstant for polygon hierarchy', function() { + var document = [{ + id: 'document', + version: '1.0' + }, { + id: 'constantPositionsTimeVaryingHoles', + polygon: { + positions: { + cartographicDegrees: [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + }, + holes: [{ + interval: '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicDegrees: [ + [ + -45.2, 21, 0, + -43.5, 27, 0, + -41.6, 21.1, 0 + ] + ] + }, { + interval: '2012-08-04T16:20:00Z/2012-08-04T16:40:00Z', + cartographicDegrees: [ + [ + -40, 34, 0, + -37, 26, 0, + -41.2, 31, 0 + ] + ] + }] + } + }, { + id: 'timeVaryingPositionsConstantHoles', + polygon: { + positions: [{ + interval: '2012-08-04T16:00:00Z/2012-08-04T16:20:00Z', + cartographicDegrees: [ + -50, 20, 0, + -50, 40, 0, + -40, 40, 0, + -40, 20, 0 + ] + }, { + interval: '2012-08-04T16:20:00Z/2012-08-04T16:40:00Z', + cartographicDegrees: [ + -35, 50, 0, + -35, 10, 0, + -45, 30, 0 + ] + }], + holes: { + cartographicDegrees: [ + [ + -45.2, 21, 0, + -43.5, 27, 0, + -41.6, 21.1, 0 + ] + ] + } + } + }]; + + return CzmlDataSource.load(document).then(function(dataSource) { + var entity = dataSource.entities.getById('constantPositionsTimeVaryingHoles'); + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + + entity = dataSource.entities.getById('timeVaryingPositionsConstantHoles'); + + expect(entity.polygon).toBeDefined(); + expect(entity.polygon.hierarchy).toBeDefined(); + expect(entity.polygon.hierarchy.isConstant).toEqual(false); + }); + }); + + it('can load constant data for polyline', function() { + var packet = { polyline : { material : { polylineOutline : { @@ -3101,23 +3698,22 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(polylinePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.polyline).toBeDefined(); - expect(entity.polyline.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.width); - expect(entity.polyline.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.polyline.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(1.0); - expect(entity.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.polyline.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.polyline.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType.CESIUM_3D_TILE); + expect(entity.polyline.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.polyline.material.polylineOutline.color.rgbaf)); + expect(entity.polyline.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.polyline.material.polylineOutline.outlineColor.rgbaf)); + expect(entity.polyline.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.material.polylineOutline.outlineWidth); + expect(entity.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.width); + expect(entity.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.show); + expect(entity.polyline.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.polyline.shadows]); + expect(entity.polyline.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType[packet.polyline.classificationType]); }); }); - it('CZML adds data for constrained polyline.', function() { - var polylinePacket = { + it('can load interval data for polyline', function() { + var packet = { polyline : { interval : '2000-01-01/2001-01-01', material : { @@ -3138,21 +3734,20 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : polylinePacket.polyline.interval + iso8601 : packet.polyline.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(polylinePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.polyline).toBeDefined(); - expect(entity.polyline.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.polyline.width.getValue(validTime)).toEqual(polylinePacket.polyline.width); - expect(entity.polyline.material.getValue(validTime).outlineColor).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.polyline.material.getValue(validTime).outlineWidth).toEqual(1.0); - expect(entity.polyline.show.getValue(validTime)).toEqual(true); - expect(entity.polyline.shadows.getValue(validTime)).toEqual(ShadowMode.ENABLED); + expect(entity.polyline.material.getValue(validTime).color).toEqual(Color.unpack(packet.polyline.material.polylineOutline.color.rgbaf)); + expect(entity.polyline.material.getValue(validTime).outlineColor).toEqual(Color.unpack(packet.polyline.material.polylineOutline.outlineColor.rgbaf)); + expect(entity.polyline.material.getValue(validTime).outlineWidth).toEqual(packet.polyline.material.polylineOutline.outlineWidth); + expect(entity.polyline.width.getValue(validTime)).toEqual(packet.polyline.width); + expect(entity.polyline.show.getValue(validTime)).toEqual(packet.polyline.show); + expect(entity.polyline.shadows.getValue(validTime)).toEqual(ShadowMode[packet.polyline.shadows]); expect(entity.polyline.material.getValue(invalidTime)).toBeUndefined(); expect(entity.polyline.width.getValue(invalidTime)).toBeUndefined(); @@ -3161,8 +3756,8 @@ defineSuite([ }); }); - it('CZML adds data for polyline clamped to terrain.', function() { - var polylinePacket = { + it('can load constant data for polyline clamped to terrain.', function() { + var packet = { polyline : { material : { polylineOutline : { @@ -3182,23 +3777,22 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(polylinePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.polyline).toBeDefined(); - expect(entity.polyline.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(entity.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.width); - expect(entity.polyline.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.polyline.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(1.0); - expect(entity.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.polyline.clampToGround.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.polyline.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(1); + expect(entity.polyline.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.polyline.material.polylineOutline.color.rgbaf)); + expect(entity.polyline.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.polyline.material.polylineOutline.outlineColor.rgbaf)); + expect(entity.polyline.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.material.polylineOutline.outlineWidth); + expect(entity.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.width); + expect(entity.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.show); + expect(entity.polyline.clampToGround.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.clampToGround); + expect(entity.polyline.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.polyline.zIndex); }); }); - it('CZML adds data for infinite model.', function() { - var modelPacket = { + it('can load constant data for model', function() { + var packet = { model : { show : true, scale : 3.0, @@ -3226,7 +3820,7 @@ defineSuite([ cartesian : [4.0, 5.0, 6.0] }, rotation : { - unitQuaternion : [0.0, 0.707, 0.0, 0.707] + unitQuaternion : [0.0, 0.7071, 0.0, 0.7071] } } }, @@ -3238,48 +3832,47 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(modelPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.model).toBeDefined(); - expect(entity.model.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.model.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(3.0); - expect(entity.model.minimumPixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(5.0); - expect(entity.model.maximumScale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(4.0); - expect(entity.model.uri.getValue(Iso8601.MINIMUM_VALUE).url).toEqual('./Data/Models/Box-Articulations/Box-Articulations.gltf'); - expect(entity.model.incrementallyLoadTextures.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.model.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.model.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference.CLAMP_TO_GROUND); - expect(entity.model.silhouetteColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(1.0, 0.0, 0.0, 1.0)); - expect(entity.model.silhouetteSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(2.0); - expect(entity.model.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.0, 1.0, 0.0, 0.2)); - expect(entity.model.colorBlendMode.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ColorBlendMode.HIGHLIGHT); - expect(entity.model.colorBlendAmount.getValue(Iso8601.MINIMUM_VALUE)).toEqual(0.5); + expect(entity.model.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.show); + expect(entity.model.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.scale); + expect(entity.model.minimumPixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.minimumPixelSize); + expect(entity.model.maximumScale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.maximumScale); + expect(entity.model.uri.getValue(Iso8601.MINIMUM_VALUE).url).toEqual(packet.model.gltf); + expect(entity.model.incrementallyLoadTextures.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.incrementallyLoadTextures); + expect(entity.model.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.model.shadows]); + expect(entity.model.heightReference.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HeightReference[packet.model.heightReference]); + expect(entity.model.silhouetteColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.model.silhouetteColor.rgbaf)); + expect(entity.model.silhouetteSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.silhouetteSize); + expect(entity.model.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.model.color.rgbaf)); + expect(entity.model.colorBlendMode.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ColorBlendMode[packet.model.colorBlendMode]); + expect(entity.model.colorBlendAmount.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.model.colorBlendAmount); var nodeTransform = entity.model.nodeTransformations.getValue(Iso8601.MINIMUM_VALUE).Mesh; expect(nodeTransform).toBeDefined(); - expect(nodeTransform.scale).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(nodeTransform.translation).toEqual(new Cartesian3(4.0, 5.0, 6.0)); + expect(nodeTransform.scale).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.scale.cartesian)); + expect(nodeTransform.translation).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.translation.cartesian)); - var expectedRotation = new Quaternion(0.0, 0.707, 0.0, 0.707); + var expectedRotation = Quaternion.unpack(packet.model.nodeTransformations.Mesh.rotation.unitQuaternion); Quaternion.normalize(expectedRotation, expectedRotation); expect(nodeTransform.rotation).toEqual(expectedRotation); - expect(entity.model.nodeTransformations.Mesh.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(entity.model.nodeTransformations.Mesh.translation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(4.0, 5.0, 6.0)); + expect(entity.model.nodeTransformations.Mesh.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.scale.cartesian)); + expect(entity.model.nodeTransformations.Mesh.translation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.translation.cartesian)); expect(entity.model.nodeTransformations.Mesh.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedRotation); var articulations = entity.model.articulations.getValue(Iso8601.MINIMUM_VALUE); expect(articulations).toBeDefined(); - expect(articulations['SampleArticulation Yaw']).toEqual(30); - expect(articulations['SampleArticulation Pitch']).toEqual(45); - expect(articulations['SampleArticulation Roll']).toEqual(60); + expect(articulations['SampleArticulation Yaw']).toEqual(packet.model.articulations['SampleArticulation Yaw']); + expect(articulations['SampleArticulation Pitch']).toEqual(packet.model.articulations['SampleArticulation Pitch']); + expect(articulations['SampleArticulation Roll']).toEqual(packet.model.articulations['SampleArticulation Roll']); }); }); - it('CZML adds data for constrained model.', function() { - var modelPacket = { + it('can load interval data for model', function() { + var packet = { model : { interval : '2000-01-01/2001-01-01', show : true, @@ -3307,7 +3900,7 @@ defineSuite([ cartesian : [4.0, 5.0, 6.0] }, rotation : { - unitQuaternion : [0.0, 0.707, 0.0, 0.707] + unitQuaternion : [0.0, 0.7071, 0.0, 0.7071] } } }, @@ -3320,46 +3913,45 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601({ - iso8601 : modelPacket.model.interval + iso8601 : packet.model.interval }).start; var invalidTime = JulianDate.addSeconds(validTime, -1, new JulianDate()); - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(modelPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.model).toBeDefined(); - expect(entity.model.show.getValue(validTime)).toEqual(true); - expect(entity.model.scale.getValue(validTime)).toEqual(3.0); - expect(entity.model.minimumPixelSize.getValue(validTime)).toEqual(5.0); - expect(entity.model.uri.getValue(validTime).url).toEqual('./Data/Models/Box-Articulations/Box-Articulations.gltf'); - expect(entity.model.incrementallyLoadTextures.getValue(validTime)).toEqual(true); - expect(entity.model.shadows.getValue(validTime)).toEqual(ShadowMode.ENABLED); - expect(entity.model.heightReference.getValue(validTime)).toEqual(HeightReference.CLAMP_TO_GROUND); - expect(entity.model.silhouetteColor.getValue(validTime)).toEqual(new Color(1.0, 0.0, 0.0, 1.0)); - expect(entity.model.silhouetteSize.getValue(validTime)).toEqual(2.0); - expect(entity.model.color.getValue(validTime)).toEqual(new Color(0.0, 1.0, 0.0, 0.2)); - expect(entity.model.colorBlendMode.getValue(validTime)).toEqual(ColorBlendMode.HIGHLIGHT); - expect(entity.model.colorBlendAmount.getValue(validTime)).toEqual(0.5); + expect(entity.model.show.getValue(validTime)).toEqual(packet.model.show); + expect(entity.model.scale.getValue(validTime)).toEqual(packet.model.scale); + expect(entity.model.minimumPixelSize.getValue(validTime)).toEqual(packet.model.minimumPixelSize); + expect(entity.model.uri.getValue(validTime).url).toEqual(packet.model.gltf); + expect(entity.model.incrementallyLoadTextures.getValue(validTime)).toEqual(packet.model.incrementallyLoadTextures); + expect(entity.model.shadows.getValue(validTime)).toEqual(ShadowMode[packet.model.shadows]); + expect(entity.model.heightReference.getValue(validTime)).toEqual(HeightReference[packet.model.heightReference]); + expect(entity.model.silhouetteColor.getValue(validTime)).toEqual(Color.unpack(packet.model.silhouetteColor.rgbaf)); + expect(entity.model.silhouetteSize.getValue(validTime)).toEqual(packet.model.silhouetteSize); + expect(entity.model.color.getValue(validTime)).toEqual(Color.unpack(packet.model.color.rgbaf)); + expect(entity.model.colorBlendMode.getValue(validTime)).toEqual(ColorBlendMode[packet.model.colorBlendMode]); + expect(entity.model.colorBlendAmount.getValue(validTime)).toEqual(packet.model.colorBlendAmount); var nodeTransform = entity.model.nodeTransformations.getValue(validTime).Mesh; expect(nodeTransform).toBeDefined(); - expect(nodeTransform.scale).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(nodeTransform.translation).toEqual(new Cartesian3(4.0, 5.0, 6.0)); + expect(nodeTransform.scale).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.scale.cartesian)); + expect(nodeTransform.translation).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.translation.cartesian)); - var expectedRotation = new Quaternion(0.0, 0.707, 0.0, 0.707); + var expectedRotation = Quaternion.unpack(packet.model.nodeTransformations.Mesh.rotation.unitQuaternion); Quaternion.normalize(expectedRotation, expectedRotation); expect(nodeTransform.rotation).toEqual(expectedRotation); - expect(entity.model.nodeTransformations.Mesh.scale.getValue(validTime)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(entity.model.nodeTransformations.Mesh.translation.getValue(validTime)).toEqual(new Cartesian3(4.0, 5.0, 6.0)); + expect(entity.model.nodeTransformations.Mesh.scale.getValue(validTime)).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.scale.cartesian)); + expect(entity.model.nodeTransformations.Mesh.translation.getValue(validTime)).toEqual(Cartesian3.unpack(packet.model.nodeTransformations.Mesh.translation.cartesian)); expect(entity.model.nodeTransformations.Mesh.rotation.getValue(validTime)).toEqual(expectedRotation); var articulations = entity.model.articulations.getValue(validTime); expect(articulations).toBeDefined(); - expect(articulations['SampleArticulation Yaw']).toEqual(30); - expect(articulations['SampleArticulation Pitch']).toEqual(45); - expect(articulations['SampleArticulation Roll']).toEqual(60); + expect(articulations['SampleArticulation Yaw']).toEqual(packet.model.articulations['SampleArticulation Yaw']); + expect(articulations['SampleArticulation Pitch']).toEqual(packet.model.articulations['SampleArticulation Pitch']); + expect(articulations['SampleArticulation Roll']).toEqual(packet.model.articulations['SampleArticulation Roll']); expect(entity.model.show.getValue(invalidTime)).toBeUndefined(); expect(entity.model.scale.getValue(invalidTime)).toBeUndefined(); @@ -3387,20 +3979,118 @@ defineSuite([ }); }); - it('processCzml deletes an existing object.', function() { + it('can load node transformations expressed as intervals', function() { + var packet = { + model : { + interval: '2012-04-02T12:00:00Z/2012-04-02T13:00:00Z', + nodeTransformations : [{ + interval: '2012-04-02T12:00:00Z/2012-04-02T12:00:01Z', + Mesh : { + scale : { + cartesian : [1.0, 2.0, 3.0] + }, + translation : { + cartesian : [4.0, 5.0, 6.0] + }, + rotation : { + unitQuaternion : [0.0, 0.7071, 0.0, 0.0] + } + } + }, { + interval: '2012-04-02T12:00:01Z/2012-04-02T12:00:02Z', + Mesh : { + scale : { + cartesian : [10.0, 20.0, 30.0] + }, + translation : { + cartesian : [40.0, 50.0, 60.0] + }, + rotation : { + unitQuaternion : [0.0, 0.0, 0.0, 0.7071] + } + } + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.model).toBeDefined(); + + var time = JulianDate.fromIso8601('2012-04-02T12:00:00Z'); + var nodeTransform = entity.model.nodeTransformations.getValue(time).Mesh; + expect(nodeTransform).toBeDefined(); + expect(nodeTransform.scale).toEqual(Cartesian3.unpack(packet.model.nodeTransformations[0].Mesh.scale.cartesian)); + expect(nodeTransform.translation).toEqual(Cartesian3.unpack(packet.model.nodeTransformations[0].Mesh.translation.cartesian)); + + var expectedRotation = Quaternion.unpack(packet.model.nodeTransformations[0].Mesh.rotation.unitQuaternion); + Quaternion.normalize(expectedRotation, expectedRotation); + expect(nodeTransform.rotation).toEqual(expectedRotation); + + time = JulianDate.fromIso8601('2012-04-02T12:00:01Z'); + nodeTransform = entity.model.nodeTransformations.getValue(time).Mesh; + expect(nodeTransform).toBeDefined(); + expect(nodeTransform.scale).toEqual(Cartesian3.unpack(packet.model.nodeTransformations[1].Mesh.scale.cartesian)); + expect(nodeTransform.translation).toEqual(Cartesian3.unpack(packet.model.nodeTransformations[1].Mesh.translation.cartesian)); + + expectedRotation = Quaternion.unpack(packet.model.nodeTransformations[1].Mesh.rotation.unitQuaternion); + Quaternion.normalize(expectedRotation, expectedRotation); + expect(nodeTransform.rotation).toEqual(expectedRotation); + }); + }); + + it('can load articulations expressed as intervals', function() { + var packet = { + model : { + interval: '2012-04-02T12:00:00Z/2012-04-02T13:00:00Z', + articulations : [{ + interval: '2012-04-02T12:00:00Z/2012-04-02T12:00:01Z', + 'SampleArticulation Yaw' : 30, + 'SampleArticulation Pitch' : 45, + 'SampleArticulation Roll' : 60 + }, { + interval: '2012-04-02T12:00:01Z/2012-04-02T12:00:02Z', + 'SampleArticulation Yaw' : 20, + 'SampleArticulation Pitch' : 25, + 'SampleArticulation Roll' : 30 + }] + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.model).toBeDefined(); + + var time = JulianDate.fromIso8601('2012-04-02T12:00:00Z'); + var articulations = entity.model.articulations.getValue(time); + expect(articulations).toBeDefined(); + expect(articulations['SampleArticulation Yaw']).toEqual(packet.model.articulations[0]['SampleArticulation Yaw']); + expect(articulations['SampleArticulation Pitch']).toEqual(packet.model.articulations[0]['SampleArticulation Pitch']); + expect(articulations['SampleArticulation Roll']).toEqual(packet.model.articulations[0]['SampleArticulation Roll']); + + time = JulianDate.fromIso8601('2012-04-02T12:00:01Z'); + articulations = entity.model.articulations.getValue(time); + expect(articulations).toBeDefined(); + expect(articulations['SampleArticulation Yaw']).toEqual(packet.model.articulations[1]['SampleArticulation Yaw']); + expect(articulations['SampleArticulation Pitch']).toEqual(packet.model.articulations[1]['SampleArticulation Pitch']); + expect(articulations['SampleArticulation Roll']).toEqual(packet.model.articulations[1]['SampleArticulation Roll']); + }); + }); + + it('can delete an existing object', function() { var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(staticCzml)).then(function(dataSource) { - var objects = dataSource.entities.values; - expect(objects.length).toEqual(1); - return dataSource.load(makePacket(czmlDelete)); + return dataSource.load(makeDocument(staticCzml)).then(function(dataSource) { + expect(dataSource.entities.values.length).toEqual(1); + return dataSource.load(makeDocument(czmlDelete)); }).then(function(dataSource) { - var objects = dataSource.entities.values; - expect(objects.length).toEqual(0); + expect(dataSource.entities.values.length).toEqual(0); }); }); - it('Processes parent property.', function() { - var parentChildCzml = [{ + it('loads parent', function() { + var document = [{ id : 'document', version : '1.0' }, { @@ -3410,20 +4100,17 @@ defineSuite([ 'parent' : 'parent' }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(parentChildCzml).then(function(dataSource) { - var objects = dataSource.entities; - - var parent = objects.getById('parent'); + return CzmlDataSource.load(document).then(function(dataSource) { + var parent = dataSource.entities.getById('parent'); expect(parent.parent).toBeUndefined(); - var child = objects.getById('child'); + var child = dataSource.entities.getById('child'); expect(child.parent).toBe(parent); }); }); - it('Processes parent property out of order.', function() { - var parentChildCzml = [{ + it('loads parent specified out of order', function() { + var document = [{ id : 'document', version : '1.0' }, { @@ -3444,31 +4131,28 @@ defineSuite([ parent : 'grandparent' }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(parentChildCzml).then(function(dataSource) { - var objects = dataSource.entities; - - var grandparent = objects.getById('grandparent'); + return CzmlDataSource.load(document).then(function(dataSource) { + var grandparent = dataSource.entities.getById('grandparent'); expect(grandparent.parent).toBeUndefined(); - var grandparent2 = objects.getById('grandparent'); + var grandparent2 = dataSource.entities.getById('grandparent'); expect(grandparent2.parent).toBeUndefined(); - var parent = objects.getById('parent'); + var parent = dataSource.entities.getById('parent'); expect(parent.parent).toBe(grandparent); - var parent2 = objects.getById('parent2'); + var parent2 = dataSource.entities.getById('parent2'); expect(parent2.parent).toBe(grandparent); - var child = objects.getById('child'); + var child = dataSource.entities.getById('child'); expect(child.parent).toBe(parent); - var child2 = objects.getById('child2'); + var child2 = dataSource.entities.getById('child2'); expect(child2.parent).toBe(parent); }); }); - it('Processes JulianDate packets.', function() { + it('can process JulianDate data in packets', function() { var date = JulianDate.fromIso8601('2000-01-01'); var object = {}; @@ -3485,20 +4169,20 @@ defineSuite([ expect(object.objDate.getValue()).toEqual(date); }); - it('Processes array packets.', function() { - var arrayPacket = { + it('can process array data in packets', function() { + var packet = { array : [1, 2, 3, 4, 5] }; var object = {}; - CzmlDataSource.processPacketData(Array, object, 'arrayData', arrayPacket); + CzmlDataSource.processPacketData(Array, object, 'arrayData', packet); expect(object.arrayData).toBeDefined(); - expect(object.arrayData.getValue()).toEqual(arrayPacket.array); + expect(object.arrayData.getValue()).toEqual(packet.array); }); - it('CZML load suspends events.', function() { - var packets = [{ + it('loading CZML suspends events.', function() { + var document = [{ id : 'document', version : '1.0' }, { @@ -3521,35 +4205,37 @@ defineSuite([ var dataSource = new CzmlDataSource(); dataSource.entities.collectionChanged.addEventListener(spy); - return dataSource.load(packets).then(function(dataSource) { + return dataSource.load(document).then(function(dataSource) { expect(spy.calls.count()).toEqual(1); }); }); - it('CZML materials work with composite interval', function() { - var before = JulianDate.fromIso8601('2012-03-15T09:23:59Z'); - var solid = JulianDate.fromIso8601('2012-03-15T10:00:00Z'); - var grid1 = JulianDate.fromIso8601('2012-03-15T11:00:00Z'); - var grid2 = JulianDate.fromIso8601('2012-03-15T12:00:00Z'); - var after = JulianDate.fromIso8601('2012-03-15T12:00:01Z'); + function printInterval(startTime, stopTime) { + return TimeInterval.toIso8601(new TimeInterval({ + start: startTime, + stop: stopTime + })); + } + + it('can load materials specified with composite interval', function() { + var beforeTime = JulianDate.fromIso8601('2012-03-15T09:23:59Z'); + var solidTime = JulianDate.fromIso8601('2012-03-15T10:00:00Z'); + var gridTime1 = JulianDate.fromIso8601('2012-03-15T11:00:00Z'); + var gridTime2 = JulianDate.fromIso8601('2012-03-15T12:00:00Z'); + var afterTime = JulianDate.fromIso8601('2012-03-15T12:00:01Z'); var packet = { + id: 'obj', polygon : { material : [{ - interval : '2012-03-15T10:00:00Z/2012-03-15T11:00:00Z', - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1, - epoch : '2012-03-15T10:00:00Z', + interval : printInterval(solidTime, gridTime1), solidColor : { color : { rgba : [240, 0, 0, 0] } } }, { - interval : '2012-03-15T11:00:00Z/2012-03-15T12:00:00Z', - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1, - epoch : '2012-03-15T11:00:00Z', + interval : printInterval(gridTime1, gridTime2), grid : { color : { rgba : [240, 255, 255, 255] @@ -3568,20 +4254,60 @@ defineSuite([ }] } }; + var secondPacket; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { - var entity = dataSource.entities.values[0]; - expect(entity.polygon.material.getType(solid)).toBe('Color'); - expect(entity.polygon.material.getType(grid1)).toBe('Grid'); - expect(entity.polygon.material.getType(grid2)).toBe('Grid'); - expect(entity.polygon.material.getType(before)).toBeUndefined(); - expect(entity.polygon.material.getType(after)).toBeUndefined(); + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.getById('obj'); + + expect(entity.polygon.material).toBeInstanceOf(CompositeMaterialProperty); + + expect(entity.polygon.material.getType(solidTime)).toEqual('Color'); + expect(entity.polygon.material.getValue(solidTime).color).toEqual(Color.unpack(packet.polygon.material[0].solidColor.color.rgba.map(Color.byteToFloat))); + + function assertValuesForGridMaterial(time) { + expect(entity.polygon.material.getValue(time).color).toEqual(Color.unpack(packet.polygon.material[1].grid.color.rgba.map(Color.byteToFloat))); + expect(entity.polygon.material.getValue(time).cellAlpha).toEqual(packet.polygon.material[1].grid.cellAlpha); + expect(entity.polygon.material.getValue(time).lineCount).toEqual(Cartesian2.unpack(packet.polygon.material[1].grid.lineCount.cartesian2)); + expect(entity.polygon.material.getValue(time).lineThickness).toEqual(Cartesian2.unpack(packet.polygon.material[1].grid.lineThickness.cartesian2)); + expect(entity.polygon.material.getValue(time).lineOffset).toEqual(Cartesian2.unpack(packet.polygon.material[1].grid.lineOffset.cartesian2)); + } + + expect(entity.polygon.material.getType(gridTime1)).toEqual('Grid'); + assertValuesForGridMaterial(gridTime1); + + expect(entity.polygon.material.getType(gridTime2)).toEqual('Grid'); + assertValuesForGridMaterial(gridTime2); + + expect(entity.polygon.material.getType(beforeTime)).toBeUndefined(); + expect(entity.polygon.material.getType(afterTime)).toBeUndefined(); + return dataSource; + }).then(function(dataSource) { + // processing new data into an existing interval updates the existing material property + secondPacket = { + id: 'obj', + polygon: { + material: [{ + interval : printInterval(solidTime, gridTime1), + solidColor: { + color: { + rgba: [200, 100, 50, 255] + } + } + }] + } + }; + return dataSource.process(secondPacket); + }).then(function(dataSource) { + var entity = dataSource.entities.getById('obj'); + + expect(entity.polygon.material).toBeInstanceOf(CompositeMaterialProperty); + expect(entity.polygon.material.getType(solidTime)).toEqual('Color'); + expect(entity.polygon.material.getValue(solidTime).color).toEqual(Color.unpack(secondPacket.polygon.material[0].solidColor.color.rgba.map(Color.byteToFloat))); }); }); - it('CZML adds data for rectangle.', function() { - var rectanglePacket = { + it('can load constant data for rectangle', function() { + var packet = { rectangle : { material : { solidColor : { @@ -3610,32 +4336,29 @@ defineSuite([ } }; - var czmlRectangle = rectanglePacket.rectangle; - - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(rectanglePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.rectangle).toBeDefined(); - expect(entity.rectangle.coordinates.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Rectangle(0, 1, 2, 3)); - expect(entity.rectangle.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.rectangle.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.show); - expect(entity.rectangle.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.height); - expect(entity.rectangle.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.extrudedHeight); - expect(entity.rectangle.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.granularity); - expect(entity.rectangle.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.rotation); - expect(entity.rectangle.stRotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.stRotation); - expect(entity.rectangle.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.rectangle.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.rectangle.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.rectangle.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.rectangle.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.rectangle.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType.TERRAIN); + expect(entity.rectangle.coordinates.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Rectangle.unpack(packet.rectangle.coordinates.wsen)); + expect(entity.rectangle.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.rectangle.material.solidColor.color.rgbaf)); + expect(entity.rectangle.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.show); + expect(entity.rectangle.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.height); + expect(entity.rectangle.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.extrudedHeight); + expect(entity.rectangle.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.granularity); + expect(entity.rectangle.rotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.rotation); + expect(entity.rectangle.stRotation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.stRotation); + expect(entity.rectangle.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.outline); + expect(entity.rectangle.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.rectangle.outlineColor.rgbaf)); + expect(entity.rectangle.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.outlineWidth); + expect(entity.rectangle.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.rectangle.shadows]); + expect(entity.rectangle.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.rectangle.zIndex); + expect(entity.rectangle.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType[packet.rectangle.classificationType]); }); }); it('can handle constant rectangle coordinates in degrees.', function() { - var rectanglePacket = { + var packet = { rectangle : { coordinates : { wsenDegrees : [0, 1, 2, 3] @@ -3643,8 +4366,7 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(rectanglePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.rectangle.coordinates.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Rectangle.fromDegrees(0, 1, 2, 3)); }); @@ -3653,18 +4375,19 @@ defineSuite([ it('can handle sampled rectangle coordinates.', function() { var epoch = JulianDate.now(); - var rectanglePacket = { + var packet = { rectangle : { coordinates : { epoch : JulianDate.toIso8601(epoch), - wsen : [0.0, 1.0, 2.0, 3.0, 4.0, - 1.0, 3.0, 4.0, 5.0, 6.0] + wsen : [ + 0.0, 1.0, 2.0, 3.0, 4.0, + 1.0, 3.0, 4.0, 5.0, 6.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(rectanglePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.rectangle).toBeDefined(); @@ -3680,18 +4403,19 @@ defineSuite([ it('can handle sampled rectangle coordinates in degrees.', function() { var epoch = JulianDate.now(); - var rectanglePacket = { + var packet = { rectangle : { coordinates : { epoch : JulianDate.toIso8601(epoch), - wsenDegrees : [0.0, 1.0, 2.0, 3.0, 4.0, - 1.0, 3.0, 4.0, 5.0, 6.0] + wsenDegrees : [ + 0.0, 1.0, 2.0, 3.0, 4.0, + 1.0, 3.0, 4.0, 5.0, 6.0 + ] } } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(rectanglePacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.rectangle).toBeDefined(); @@ -3704,8 +4428,8 @@ defineSuite([ }); }); - it('CZML adds data for wall.', function() { - var wallPacket = { + it('can load constant data for wall', function() { + var packet = { wall : { material : { solidColor : { @@ -3731,26 +4455,23 @@ defineSuite([ } }; - var czmlRectangle = wallPacket.wall; - - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(wallPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.wall).toBeDefined(); - expect(entity.wall.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.wall.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.show); - expect(entity.wall.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.granularity); - expect(entity.wall.minimumHeights.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.minimumHeights.array); - expect(entity.wall.maximumHeights.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlRectangle.maximumHeights.array); - expect(entity.wall.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + expect(entity.wall.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.wall.material.solidColor.color.rgbaf)); + expect(entity.wall.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.show); + expect(entity.wall.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.granularity); + expect(entity.wall.minimumHeights.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.minimumHeights.array); + expect(entity.wall.maximumHeights.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.maximumHeights.array); + expect(entity.wall.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.outline); expect(entity.wall.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.wall.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.wall.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); + expect(entity.wall.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.wall.outlineWidth); + expect(entity.wall.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.wall.shadows]); }); }); - it('CZML adds data for wall with minimumHeights as references.', function() { + it('can load data for wall with minimumHeights as references.', function() { var packets = [{ id : 'document', version : '1.0' @@ -3776,8 +4497,7 @@ defineSuite([ } }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var entity = dataSource.entities.getById('wall'); expect(entity.wall).toBeDefined(); @@ -3786,8 +4506,51 @@ defineSuite([ }); }); - it('CZML adds data for box.', function() { - var boxPacket = { + it('can load array of references expressed using intervals', function() { + var packets = [{ + id : 'document', + version : '1.0' + }, { + id : 'obj1', + billboard : { + scale : 1.0 + } + }, { + id : 'obj2', + billboard : { + scale : 4.0 + } + }, { + id : 'obj3', + billboard : { + scale : 6.0 + } + }, { + id : 'wall', + wall : { + minimumHeights : [{ + interval : '2010-01-01T00:00:00Z/2010-01-01T01:00:00Z', + references : ['obj1#billboard.scale', 'obj2#billboard.scale'] + }, { + interval : '2010-01-01T01:00:00Z/2010-01-01T02:00:00Z', + references : ['obj2#billboard.scale', 'obj3#billboard.scale'] + }] + } + }]; + + return CzmlDataSource.load(packets).then(function(dataSource) { + var entity = dataSource.entities.getById('wall'); + + expect(entity.wall).toBeDefined(); + expect(entity.wall.minimumHeights).toBeInstanceOf(CompositeProperty); + expect(entity.wall.minimumHeights.getValue(JulianDate.fromIso8601('2009-01-01T00:00:00Z'))).toBeUndefined(); + expect(entity.wall.minimumHeights.getValue(JulianDate.fromIso8601('2010-01-01T00:00:00Z'))).toEqual([packets[1].billboard.scale, packets[2].billboard.scale]); + expect(entity.wall.minimumHeights.getValue(JulianDate.fromIso8601('2010-01-01T01:00:00Z'))).toEqual([packets[2].billboard.scale, packets[3].billboard.scale]); + }); + }); + + it('can load constant data for box', function() { + var packet = { box : { material : { solidColor : { @@ -3809,23 +4572,22 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(boxPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.box).toBeDefined(); - expect(entity.box.dimensions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1, 2, 3)); - expect(entity.box.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.box.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.box.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.box.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.box.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.box.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); + expect(entity.box.dimensions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpack(packet.box.dimensions.cartesian)); + expect(entity.box.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.box.material.solidColor.color.rgbaf)); + expect(entity.box.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.box.show); + expect(entity.box.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.box.outline); + expect(entity.box.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.box.outlineColor.rgbaf)); + expect(entity.box.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.box.outlineWidth); + expect(entity.box.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.box.shadows]); }); }); - it('CZML adds data for cylinder.', function() { - var cylinderPacket = { + it('can load constant data for cylinder', function() { + var packet = { cylinder : { material : { solidColor : { @@ -3849,29 +4611,26 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(cylinderPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.cylinder).toBeDefined(); - expect(entity.cylinder.length.getValue(Iso8601.MINIMUM_VALUE)).toEqual(5); - expect(entity.cylinder.topRadius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.cylinder.bottomRadius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(7); - expect(entity.cylinder.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.cylinder.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.cylinder.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.cylinder.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.cylinder.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.cylinder.numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE)).toEqual(15); - expect(entity.cylinder.slices.getValue(Iso8601.MINIMUM_VALUE)).toEqual(100); - expect(entity.cylinder.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); + expect(entity.cylinder.length.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.length); + expect(entity.cylinder.topRadius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.topRadius); + expect(entity.cylinder.bottomRadius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.bottomRadius); + expect(entity.cylinder.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.cylinder.material.solidColor.color.rgbaf)); + expect(entity.cylinder.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.show); + expect(entity.cylinder.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.outline); + expect(entity.cylinder.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.cylinder.outlineColor.rgbaf)); + expect(entity.cylinder.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.outlineWidth); + expect(entity.cylinder.numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.numberOfVerticalLines); + expect(entity.cylinder.slices.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.cylinder.slices); + expect(entity.cylinder.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.cylinder.shadows]); }); }); - it('CZML adds data for corridor.', function() { - var expectedResult = [new Cartesian3(1.0, 2.0, 3.0), new Cartesian3(5.0, 6.0, 7.0)]; - - var corridorPacket = { + it('can load constant data for corridor', function() { + var packet = { corridor : { material : { solidColor : { @@ -3881,7 +4640,10 @@ defineSuite([ } }, positions : { - cartesian : [expectedResult[0].x, expectedResult[0].y, expectedResult[0].z, expectedResult[1].x, expectedResult[1].y, expectedResult[1].z] + cartesian : [ + 1.0, 2.0, 3.0, + 5.0, 6.0, 7.0 + ] }, cornerType : 'MITERED', extrudedHeight : 2, @@ -3900,48 +4662,41 @@ defineSuite([ } }; - var czmlCorridor = corridorPacket.corridor; - - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(corridorPacket)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.values[0]; expect(entity.corridor).toBeDefined(); - expect(entity.corridor.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedResult); - expect(entity.corridor.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.corridor.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlCorridor.show); - expect(entity.corridor.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlCorridor.height); - expect(entity.corridor.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlCorridor.width); - expect(entity.corridor.cornerType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(CornerType.MITERED); - expect(entity.corridor.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlCorridor.extrudedHeight); - expect(entity.corridor.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(czmlCorridor.granularity); - expect(entity.corridor.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - expect(entity.corridor.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(entity.corridor.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6); - expect(entity.corridor.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode.ENABLED); - expect(entity.corridor.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(5); - expect(entity.corridor.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType.TERRAIN); - }); - }); - - it('Has entity collection with link to data source', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(nameCzml).then(function(dataSource) { - var entityCollection = dataSource.entities; - expect(entityCollection.owner).toEqual(dataSource); + expect(entity.corridor.positions.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Cartesian3.unpackArray(packet.corridor.positions.cartesian)); + expect(entity.corridor.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(Color.unpack(packet.corridor.material.solidColor.color.rgbaf)); + expect(entity.corridor.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.show); + expect(entity.corridor.height.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.height); + expect(entity.corridor.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.width); + expect(entity.corridor.cornerType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(CornerType[packet.corridor.cornerType]); + expect(entity.corridor.extrudedHeight.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.extrudedHeight); + expect(entity.corridor.granularity.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.granularity); + expect(entity.corridor.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.outline); + expect(entity.corridor.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(Color.unpack(packet.corridor.outlineColor.rgbaf)); + expect(entity.corridor.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.outlineWidth); + expect(entity.corridor.shadows.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ShadowMode[packet.corridor.shadows]); + expect(entity.corridor.zIndex.getValue(Iso8601.MINIMUM_VALUE)).toEqual(packet.corridor.zIndex); + expect(entity.corridor.classificationType.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ClassificationType[packet.corridor.classificationType]); }); }); - it('Has entity with link to entity collection', function() { - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(staticCzml)).then(function(dataSource) { - var entityCollection = dataSource.entities; - var entity = entityCollection.values[0]; - expect(entity.entityCollection).toEqual(entityCollection); + it('has entity collection with link to data source', function() { + return CzmlDataSource.load(nameCzml).then(function(dataSource) { + expect(dataSource.entities.owner).toEqual(dataSource); + }); + }); + + it('has entity with link to entity collection', function() { + return CzmlDataSource.load(makeDocument(staticCzml)).then(function(dataSource) { + var entities = dataSource.entities; + expect(entities.values[0].entityCollection).toEqual(entities); }); }); - it('Can use constant reference properties', function() { + it('can use constant reference properties', function() { var time = JulianDate.now(); var packets = [{ id : 'document', @@ -3960,8 +4715,7 @@ defineSuite([ } }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var targetEntity = dataSource.entities.getById('targetId'); var referenceObject = dataSource.entities.getById('referenceId'); @@ -3970,7 +4724,7 @@ defineSuite([ }); }); - it('Can use interval reference properties', function() { + it('can use interval reference properties', function() { var packets = [{ id : 'document', version : '1.0' @@ -4000,8 +4754,7 @@ defineSuite([ var time1 = JulianDate.fromIso8601('2012'); var time2 = JulianDate.fromIso8601('2014'); - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var targetEntity = dataSource.entities.getById('targetId'); var targetEntity2 = dataSource.entities.getById('targetId2'); var referenceObject = dataSource.entities.getById('referenceId'); @@ -4011,7 +4764,7 @@ defineSuite([ }); }); - it('Can use constant reference properties for position', function() { + it('can use constant reference properties for position', function() { var time = JulianDate.now(); var packets = [{ @@ -4029,8 +4782,7 @@ defineSuite([ } }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var targetEntity = dataSource.entities.getById('targetId'); var referenceObject = dataSource.entities.getById('referenceId'); @@ -4039,7 +4791,7 @@ defineSuite([ }); }); - it('Can use interval reference properties for positions', function() { + it('can use interval reference properties for positions', function() { var packets = [{ id : 'document', version : '1.0' @@ -4067,8 +4819,7 @@ defineSuite([ var time1 = JulianDate.fromIso8601('2012'); var time2 = JulianDate.fromIso8601('2014'); - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var targetEntity = dataSource.entities.getById('targetId'); var targetEntity2 = dataSource.entities.getById('targetId2'); var referenceObject = dataSource.entities.getById('referenceId'); @@ -4078,7 +4829,7 @@ defineSuite([ }); }); - it('Can reference properties before they exist.', function() { + it('can reference properties before they exist.', function() { var time = JulianDate.now(); var packets = [{ id : 'document', @@ -4097,8 +4848,7 @@ defineSuite([ } }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packets).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var targetEntity = dataSource.entities.getById('targetId'); var referenceObject = dataSource.entities.getById('referenceId'); @@ -4107,7 +4857,7 @@ defineSuite([ }); }); - it('Can reference local properties.', function() { + it('can reference local properties.', function() { var time = JulianDate.now(); var packet = { id : 'testObject', @@ -4119,15 +4869,14 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var targetEntity = dataSource.entities.getById('testObject'); expect(targetEntity.point.outlineWidth).toBeInstanceOf(ReferenceProperty); expect(targetEntity.point.outlineWidth.getValue(time)).toEqual(targetEntity.point.pixelSize.getValue(time)); }); }); - it('Polyline glow.', function() { + it('can load a polyline with polyline glow material', function() { var packet = { id : 'polylineGlow', polyline : { @@ -4143,16 +4892,16 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('polylineGlow'); - expect(entity.polyline.material.color.getValue()).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.polyline.material.glowPower.getValue()).toEqual(0.75); - expect(entity.polyline.material.taperPower.getValue()).toEqual(0.55); + + expect(entity.polyline.material.color.getValue()).toEqual(Color.unpack(packet.polyline.material.polylineGlow.color.rgbaf)); + expect(entity.polyline.material.glowPower.getValue()).toEqual(packet.polyline.material.polylineGlow.glowPower); + expect(entity.polyline.material.taperPower.getValue()).toEqual(packet.polyline.material.polylineGlow.taperPower); }); }); - it('Polyline arrow.', function() { + it('can load a polyline with polyline arrow material', function() { var packet = { id : 'polylineArrow', polyline : { @@ -4166,14 +4915,14 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('polylineArrow'); - expect(entity.polyline.material.color.getValue()).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); + + expect(entity.polyline.material.color.getValue()).toEqual(Color.unpack(packet.polyline.material.polylineArrow.color.rgbaf)); }); }); - it('Polyline dash.', function() { + it('can load a polyline with polyline dash material', function() { var packet = { id : 'polylineDash', polyline : { @@ -4189,16 +4938,16 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('polylineDash'); - expect(entity.polyline.material.color.getValue()).toEqual(new Color(0.1, 0.2, 0.3, 0.4)); - expect(entity.polyline.material.dashLength.getValue()).toEqual(16.0); - expect(entity.polyline.material.dashPattern.getValue()).toEqual(7.0); + + expect(entity.polyline.material.color.getValue()).toEqual(Color.unpack(packet.polyline.material.polylineDash.color.rgbaf)); + expect(entity.polyline.material.dashLength.getValue()).toEqual(packet.polyline.material.polylineDash.dashLength); + expect(entity.polyline.material.dashPattern.getValue()).toEqual(packet.polyline.material.polylineDash.dashPattern); }); }); - it('Processes extrapolation options', function() { + it('loads extrapolation options', function() { var packet = { id : 'point', position : { @@ -4219,20 +4968,19 @@ defineSuite([ } }; - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet)).then(function(dataSource) { + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { var entity = dataSource.entities.getById('point'); var color = entity.point.color; - expect(color.forwardExtrapolationType).toEqual(ExtrapolationType.NONE); - expect(color.forwardExtrapolationDuration).toEqual(1.0); - expect(color.backwardExtrapolationType).toEqual(ExtrapolationType.HOLD); - expect(color.backwardExtrapolationDuration).toEqual(2.0); + expect(color.forwardExtrapolationType).toEqual(ExtrapolationType[packet.point.color.forwardExtrapolationType]); + expect(color.forwardExtrapolationDuration).toEqual(packet.point.color.forwardExtrapolationDuration); + expect(color.backwardExtrapolationType).toEqual(ExtrapolationType[packet.point.color.backwardExtrapolationType]); + expect(color.backwardExtrapolationDuration).toEqual(packet.point.color.backwardExtrapolationDuration); var position = entity.position; - expect(position.forwardExtrapolationType).toEqual(ExtrapolationType.HOLD); - expect(position.forwardExtrapolationDuration).toEqual(2.0); - expect(position.backwardExtrapolationType).toEqual(ExtrapolationType.NONE); - expect(position.backwardExtrapolationDuration).toEqual(1.0); + expect(position.forwardExtrapolationType).toEqual(ExtrapolationType[packet.position.forwardExtrapolationType]); + expect(position.forwardExtrapolationDuration).toEqual(packet.position.forwardExtrapolationDuration); + expect(position.backwardExtrapolationType).toEqual(ExtrapolationType[packet.position.backwardExtrapolationType]); + expect(position.backwardExtrapolationDuration).toEqual(packet.position.backwardExtrapolationDuration); }); }); @@ -4269,8 +5017,42 @@ defineSuite([ }); }); + it('ignores color values not expressed as a known type', function() { + var packet = { + billboard: { + color: { + invalidType: 'someValue' + } + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.billboard).toBeDefined(); + expect(entity.billboard.color).toBeUndefined(); + }); + }); + + it('ignores rectangle values not expressed as a known type', function() { + var packet = { + rectangle: { + coordinates: { + invalidType: 'someValue' + } + } + }; + + return CzmlDataSource.load(makeDocument(packet)).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + expect(entity.rectangle).toBeDefined(); + expect(entity.rectangle.coordinates).toBeUndefined(); + }); + }); + it('converts followSurface to arcType for backwards compatibility', function() { - var packet = [{ + var packets = [{ id : 'document', version : '1.0' }, { @@ -4302,26 +5084,25 @@ defineSuite([ } }]; - var dataSource = new CzmlDataSource(); - return dataSource.load(packet).then(function(dataSource) { + return CzmlDataSource.load(packets).then(function(dataSource) { var date = JulianDate.now(); var entity = dataSource.entities.getById('followSurface-false'); - expect(entity.polyline.arcType.isConstant).toBe(true); - expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.NONE); + expect(entity.polyline.arcType.isConstant).toEqual(true); + expect(entity.polyline.arcType.getValue(date)).toEqual(ArcType.NONE); entity = dataSource.entities.getById('followSurface-true'); - expect(entity.polyline.arcType.isConstant).toBe(true); - expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.GEODESIC); + expect(entity.polyline.arcType.isConstant).toEqual(true); + expect(entity.polyline.arcType.getValue(date)).toEqual(ArcType.GEODESIC); entity = dataSource.entities.getById('followSurface-time-varying'); - expect(entity.polyline.arcType.isConstant).toBe(false); - expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toBe(ArcType.GEODESIC); - expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toBe(ArcType.NONE); + expect(entity.polyline.arcType.isConstant).toEqual(false); + expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toEqual(ArcType.GEODESIC); + expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toEqual(ArcType.NONE); entity = dataSource.entities.getById('arcType-overrides-followSurface'); - expect(entity.polyline.arcType.isConstant).toBe(true); - expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.RHUMB); + expect(entity.polyline.arcType.isConstant).toEqual(true); + expect(entity.polyline.arcType.getValue(date)).toEqual(ArcType.RHUMB); }); }); @@ -4505,7 +5286,8 @@ defineSuite([ expect(e.point.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(29646, 52915)); expect(e.point.disableDepthTestDistance.getValue(date)).toEqual(9675.0); expect(e.polygon.show.getValue(date)).toEqual(true); - expect(e.polygon.hierarchy.getValue(date)).toEqual([ new Cartesian3(39143, 2200, 6408), new Cartesian3(27161, 33386, 62338) ]); + expect(e.polygon.hierarchy.getValue(date).positions).toEqual([ new Cartesian3(39143, 2200, 6408), new Cartesian3(27161, 33386, 62338) ]); + expect(e.polygon.hierarchy.getValue(date).holes).toEqual([ new PolygonHierarchy([ new Cartesian3(47462, 20409, 3151), new Cartesian3(58636, 39653, 53914), new Cartesian3(31954, 4988, 47462) ]), new PolygonHierarchy([ new Cartesian3(20409, 3151, 58636), new Cartesian3(39653, 53914, 31954), new Cartesian3(4988, 47462, 20409), new Cartesian3(3151, 58636, 39653) ]) ]); expect(e.polygon.arcType.getValue(date)).toEqual(ArcType.RHUMB); expect(e.polygon.height.getValue(date)).toEqual(26391.0); expect(e.polygon.heightReference.getValue(date)).toEqual(HeightReference.CLAMP_TO_GROUND); @@ -4646,7 +5428,7 @@ defineSuite([ expect(e = dataSource.entities.getById('constant_corridor_material_grid_color')).toBeDefined(); expect(e.corridor.material.color.getValue(date)).toEqualEpsilon(new Color(0.576470588235294, 0.76078431372549, 0.152941176470588, 0.00392156862745098), 1e-14); expect(e = dataSource.entities.getById('constant_corridor_material_stripe_evenColor')).toBeDefined(); - expect(e.corridor.material.evenColor.getValue(date)).toEqualEpsilon(new Color(0.913725490196078, 0.63921568627451, 0.631372549019608, 0.890196078431373), 1e-14); + expect(e.corridor.material.evenColor.getValue(date)).toEqualEpsilon(new Color(0.913725490196078, 0.63921568627451, 0.631372549019608, 0.890196078431372), 1e-14); expect(e = dataSource.entities.getById('constant_corridor_material_stripe_oddColor')).toBeDefined(); expect(e.corridor.material.oddColor.getValue(date)).toEqualEpsilon(new Color(0.2, 0.137254901960784, 0.792156862745098, 0.301960784313725), 1e-14); expect(e = dataSource.entities.getById('constant_corridor_material_checkerboard_evenColor')).toBeDefined(); @@ -4842,10 +5624,14 @@ defineSuite([ expect(e.point.color.getValue(date)).toEqualEpsilon(new Color(0.662745098039216, 0.317647058823529, 0.643137254901961, 0.705882352941177), 1e-14); expect(e = dataSource.entities.getById('constant_point_outlineColor_rgbaf')).toBeDefined(); expect(e.point.outlineColor.getValue(date)).toEqualEpsilon(new Color(0.00392156862745098, 0.388235294117647, 0.101960784313725, 0.16078431372549), 1e-14); - expect(e = dataSource.entities.getById('constant_polygon_hierarchy_cartographicRadians')).toBeDefined(); - expect(e.polygon.hierarchy.getValue(date)).toEqual([ Cartesian3.fromRadians(0.612948853926511, 1.3346715688367, 54401), Cartesian3.fromRadians(1.1867596160592, 0.345663242797974, 35811) ]); - expect(e = dataSource.entities.getById('constant_polygon_hierarchy_cartographicDegrees')).toBeDefined(); - expect(e.polygon.hierarchy.getValue(date)).toEqual([ Cartesian3.fromDegrees(19, 41, 50907), Cartesian3.fromDegrees(28, 40, 24937) ]); + expect(e = dataSource.entities.getById('constant_polygon_positions_cartographicRadians')).toBeDefined(); + expect(e.polygon.hierarchy.getValue(date).positions).toEqual([ Cartesian3.fromRadians(0.278819883450618, 1.34192534297912, 13112), Cartesian3.fromRadians(1.08460649779701, 1.26665808721843, 9013) ]); + expect(e = dataSource.entities.getById('constant_polygon_positions_cartographicDegrees')).toBeDefined(); + expect(e.polygon.hierarchy.getValue(date).positions).toEqual([ Cartesian3.fromDegrees(20, 42, 343), Cartesian3.fromDegrees(21, 14, 24042) ]); + expect(e = dataSource.entities.getById('constant_polygon_holes_cartographicRadians')).toBeDefined(); + expect(e.polygon.hierarchy.getValue(date).holes).toEqual([ new PolygonHierarchy([ Cartesian3.fromRadians(0.799220652820836, 1.50366253893541, 4776), Cartesian3.fromRadians(0.179862066646486, 1.42489853818289, 42245), Cartesian3.fromRadians(0.0636782022426772, 0.558333087028927, 32510) ]), new PolygonHierarchy([ Cartesian3.fromRadians(1.50366253893541, 0.779166543514464, 33810), Cartesian3.fromRadians(1.42489853818289, 0.00358717805196918, 20389), Cartesian3.fromRadians(0.558333087028927, 0.799220652820836, 43134), Cartesian3.fromRadians(0.779166543514464, 0.179862066646486, 1412) ]) ]); + expect(e = dataSource.entities.getById('constant_polygon_holes_cartographicDegrees')).toBeDefined(); + expect(e.polygon.hierarchy.getValue(date).holes).toEqual([ new PolygonHierarchy([ Cartesian3.fromDegrees(38, 39, 52122), Cartesian3.fromDegrees(30, 41, 40406), Cartesian3.fromDegrees(9, 42, 55073) ]), new PolygonHierarchy([ Cartesian3.fromDegrees(39, 12, 5835), Cartesian3.fromDegrees(41, 41, 39069), Cartesian3.fromDegrees(42, 38, 39639), Cartesian3.fromDegrees(12, 30, 54806) ]) ]); expect(e = dataSource.entities.getById('constant_polygon_material_solidColor_color')).toBeDefined(); expect(e.polygon.material.color.getValue(date)).toEqualEpsilon(new Color(0.980392156862745, 0.905882352941176, 0.274509803921569, 0.972549019607843), 1e-14); expect(e = dataSource.entities.getById('material_polygon_material_image')).toBeDefined(); @@ -4926,7 +5712,7 @@ defineSuite([ expect(e.polyline.material.oddColor.getValue(date)).toEqual(Color.fromBytes(189, 110, 12, 32)); expect(e.polyline.material.repeat.getValue(date)).toEqual(new Cartesian2(22832, 11097)); expect(e = dataSource.entities.getById('constant_polyline_material_polylineOutline_color')).toBeDefined(); - expect(e.polyline.material.color.getValue(date)).toEqualEpsilon(new Color(0.450980392156863, 0.890196078431373, 0.403921568627451, 0.16078431372549), 1e-14); + expect(e.polyline.material.color.getValue(date)).toEqualEpsilon(new Color(0.450980392156863, 0.890196078431372, 0.403921568627451, 0.16078431372549), 1e-14); expect(e = dataSource.entities.getById('constant_polyline_material_polylineOutline_outlineColor')).toBeDefined(); expect(e.polyline.material.outlineColor.getValue(date)).toEqualEpsilon(new Color(0.815686274509804, 0.545098039215686, 0.529411764705882, 0.317647058823529), 1e-14); expect(e = dataSource.entities.getById('constant_polyline_material_polylineArrow_color')).toBeDefined(); @@ -5319,6 +6105,10 @@ defineSuite([ expect(e.position.getValue(date)).toEqual(new Cartesian3(2599, 10, 39168)); expect(e = dataSource.entities.getById('ConstantDouble2')).toBeDefined(); expect(e.billboard.scale.getValue(date)).toEqual(16451.0); + expect(e = dataSource.entities.getById('ConstantPosition3')).toBeDefined(); + expect(e.position.getValue(date)).toEqual(new Cartesian3(1758, 45062, 8624)); + expect(e = dataSource.entities.getById('ConstantDouble3')).toBeDefined(); + expect(e.billboard.scale.getValue(date)).toEqual(50938.0); expect(e = dataSource.entities.getById('Reference')).toBeDefined(); expect(e.description.getValue(date)).toEqual(constant.description.getValue(date)); expect(e.position.getValue(date)).toEqual(constant.position.getValue(date)); @@ -5477,7 +6267,8 @@ defineSuite([ expect(e.point.distanceDisplayCondition.getValue(date)).toEqual(constant.point.distanceDisplayCondition.getValue(date)); expect(e.point.disableDepthTestDistance.getValue(date)).toEqual(constant.point.disableDepthTestDistance.getValue(date)); expect(e.polygon.show.getValue(date)).toEqual(constant.polygon.show.getValue(date)); - expect(e.polygon.hierarchy.getValue(date)).toEqual([dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date)]); + expect(e.polygon.hierarchy.getValue(date).positions).toEqual([dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date)]); + expect(e.polygon.hierarchy.getValue(date).holes).toEqual([ new PolygonHierarchy([ dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date), dataSource.entities.getById('ConstantPosition3').position.getValue(date) ])]); expect(e.polygon.arcType.getValue(date)).toEqual(constant.polygon.arcType.getValue(date)); expect(e.polygon.height.getValue(date)).toEqual(constant.polygon.height.getValue(date)); expect(e.polygon.heightReference.getValue(date)).toEqual(constant.polygon.heightReference.getValue(date)); @@ -6191,10 +6982,10 @@ defineSuite([ expect(e.box.material.repeat.getValue(documentStopDate)).toEqual(new Cartesian2(34685, 17543)); expect(e = dataSource.entities.getById('sampled_box_material_image_color')).toBeDefined(); expect(e.box.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.149019607843137, 0.929411764705882, 0.462745098039216, 0.764705882352941), 1e-14); - expect(e.box.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.890196078431373, 0.262745098039216, 0.866666666666667, 0.792156862745098), 1e-14); + expect(e.box.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.890196078431372, 0.262745098039216, 0.866666666666667, 0.792156862745098), 1e-14); expect(e = dataSource.entities.getById('sampled_box_material_grid_color')).toBeDefined(); expect(e.box.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.501960784313725, 0.447058823529412, 0.72156862745098, 0.392156862745098), 1e-14); - expect(e.box.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.890196078431373, 0.505882352941176, 0.56078431372549, 0.674509803921569), 1e-14); + expect(e.box.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.890196078431372, 0.505882352941176, 0.56078431372549, 0.674509803921569), 1e-14); expect(e = dataSource.entities.getById('sampled_box_material_stripe_evenColor')).toBeDefined(); expect(e.box.material.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.980392156862745, 0.345098039215686, 0.929411764705882, 0.533333333333333), 1e-14); expect(e.box.material.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.988235294117647, 0.372549019607843, 0.713725490196078, 0.466666666666667), 1e-14); @@ -6373,7 +7164,7 @@ defineSuite([ expect(e.ellipse.material.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.207843137254902, 0.156862745098039, 0.952941176470588, 0.717647058823529), 1e-14); expect(e.ellipse.material.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.635294117647059, 0.835294117647059, 0.76078431372549, 0.235294117647059), 1e-14); expect(e = dataSource.entities.getById('sampled_ellipse_material_checkerboard_oddColor')).toBeDefined(); - expect(e.ellipse.material.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431373, 0.141176470588235, 0.231372549019608, 0.623529411764706), 1e-14); + expect(e.ellipse.material.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431372, 0.141176470588235, 0.231372549019608, 0.623529411764706), 1e-14); expect(e.ellipse.material.oddColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.192156862745098, 0.294117647058824, 0.741176470588235, 0.0274509803921569), 1e-14); expect(e = dataSource.entities.getById('sampled_ellipse_outlineColor_rgbaf')).toBeDefined(); expect(e.ellipse.outlineColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.76078431372549, 0.36078431372549, 0.223529411764706, 0.611764705882353), 1e-14); @@ -6429,7 +7220,7 @@ defineSuite([ expect(e.ellipsoid.material.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.819607843137255, 0.282352941176471, 0.929411764705882, 0.501960784313725), 1e-14); expect(e.ellipsoid.material.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.850980392156863, 0.294117647058824, 0.498039215686275, 0.956862745098039), 1e-14); expect(e = dataSource.entities.getById('sampled_ellipsoid_material_checkerboard_oddColor')).toBeDefined(); - expect(e.ellipsoid.material.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.227450980392157, 0.862745098039216, 0.890196078431373, 0.207843137254902), 1e-14); + expect(e.ellipsoid.material.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.227450980392157, 0.862745098039216, 0.890196078431372, 0.207843137254902), 1e-14); expect(e.ellipsoid.material.oddColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.796078431372549, 0.0470588235294118, 0.843137254901961, 0.388235294117647), 1e-14); expect(e = dataSource.entities.getById('sampled_ellipsoid_outlineColor_rgbaf')).toBeDefined(); expect(e.ellipsoid.outlineColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.552941176470588, 0.549019607843137, 0.431372549019608, 0.568627450980392), 1e-14); @@ -6451,7 +7242,7 @@ defineSuite([ expect(e.model.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.435294117647059, 0.945098039215686, 0.431372549019608, 0.619607843137255), 1e-14); expect(e = dataSource.entities.getById('sampled_path_material_solidColor_color')).toBeDefined(); expect(e.path.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.517647058823529, 0.56078431372549, 0.254901960784314, 0.494117647058824), 1e-14); - expect(e.path.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.905882352941176, 0.152941176470588, 0.854901960784314, 0.890196078431373), 1e-14); + expect(e.path.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.905882352941176, 0.152941176470588, 0.854901960784314, 0.890196078431372), 1e-14); expect(e = dataSource.entities.getById('sampled_path_material_polylineOutline')).toBeDefined(); expect(e.path.material.color.getValue(documentStartDate)).toEqual(Color.fromBytes(209, 154, 35, 76)); expect(e.path.material.color.getValue(documentStopDate)).toEqual(Color.fromBytes(186, 25, 242, 140)); @@ -6532,7 +7323,7 @@ defineSuite([ expect(e.path.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.898039215686275, 0.772549019607843, 0.294117647058824, 0.0431372549019608), 1e-14); expect(e.path.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.815686274509804, 0.0901960784313725, 0.898039215686275, 0.309803921568627), 1e-14); expect(e = dataSource.entities.getById('sampled_path_material_grid_color')).toBeDefined(); - expect(e.path.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431373, 0, 0.717647058823529, 0.329411764705882), 1e-14); + expect(e.path.material.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431372, 0, 0.717647058823529, 0.329411764705882), 1e-14); expect(e.path.material.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.474509803921569, 0.690196078431373, 0.0431372549019608, 0.258823529411765), 1e-14); expect(e = dataSource.entities.getById('sampled_path_material_stripe_evenColor')).toBeDefined(); expect(e.path.material.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.368627450980392, 0.584313725490196, 0.831372549019608, 0.541176470588235), 1e-14); @@ -6777,7 +7568,7 @@ defineSuite([ expect(e.polyline.depthFailMaterial.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.729411764705882, 0.533333333333333, 0.411764705882353, 0.454901960784314), 1e-14); expect(e = dataSource.entities.getById('sampled_polyline_depthFailMaterial_polylineDash_color')).toBeDefined(); expect(e.polyline.depthFailMaterial.color.getValue(documentStartDate)).toEqualEpsilon(new Color(0.776470588235294, 0.0823529411764706, 0.96078431372549, 0.776470588235294), 1e-14); - expect(e.polyline.depthFailMaterial.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.0941176470588235, 0.643137254901961, 0.717647058823529, 0.890196078431373), 1e-14); + expect(e.polyline.depthFailMaterial.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.0941176470588235, 0.643137254901961, 0.717647058823529, 0.890196078431372), 1e-14); expect(e = dataSource.entities.getById('sampled_polyline_depthFailMaterial_polylineDash_gapColor')).toBeDefined(); expect(e.polyline.depthFailMaterial.gapColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.219607843137255, 0.403921568627451, 0.815686274509804, 0.803921568627451), 1e-14); expect(e.polyline.depthFailMaterial.gapColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.294117647058824, 0.615686274509804, 0.172549019607843, 0.0235294117647059), 1e-14); @@ -6792,7 +7583,7 @@ defineSuite([ expect(e.polyline.depthFailMaterial.color.getValue(documentStopDate)).toEqualEpsilon(new Color(0.423529411764706, 0.968627450980392, 0.815686274509804, 0.968627450980392), 1e-14); expect(e = dataSource.entities.getById('sampled_polyline_depthFailMaterial_stripe_evenColor')).toBeDefined(); expect(e.polyline.depthFailMaterial.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.854901960784314, 0.843137254901961, 0.701960784313725, 0.113725490196078), 1e-14); - expect(e.polyline.depthFailMaterial.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.941176470588235, 0.890196078431373, 0.933333333333333, 0.588235294117647), 1e-14); + expect(e.polyline.depthFailMaterial.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.941176470588235, 0.890196078431372, 0.933333333333333, 0.588235294117647), 1e-14); expect(e = dataSource.entities.getById('sampled_polyline_depthFailMaterial_stripe_oddColor')).toBeDefined(); expect(e.polyline.depthFailMaterial.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.427450980392157, 0.870588235294118, 0.96078431372549, 0.219607843137255), 1e-14); expect(e.polyline.depthFailMaterial.oddColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.219607843137255, 0.847058823529412, 0.752941176470588, 0.172549019607843), 1e-14); @@ -6907,7 +7698,7 @@ defineSuite([ expect(e.wall.material.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.388235294117647, 0.847058823529412, 0.258823529411765, 0.113725490196078), 1e-14); expect(e = dataSource.entities.getById('sampled_wall_material_stripe_oddColor')).toBeDefined(); expect(e.wall.material.oddColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.345098039215686, 0.0196078431372549, 0.0549019607843137, 0.662745098039216), 1e-14); - expect(e.wall.material.oddColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.694117647058824, 0.890196078431373, 0.380392156862745, 0.317647058823529), 1e-14); + expect(e.wall.material.oddColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.694117647058824, 0.890196078431372, 0.380392156862745, 0.317647058823529), 1e-14); expect(e = dataSource.entities.getById('sampled_wall_material_checkerboard_evenColor')).toBeDefined(); expect(e.wall.material.evenColor.getValue(documentStartDate)).toEqualEpsilon(new Color(0.670588235294118, 0.462745098039216, 0.443137254901961, 0.23921568627451), 1e-14); expect(e.wall.material.evenColor.getValue(documentStopDate)).toEqualEpsilon(new Color(0.313725490196078, 0.0901960784313725, 0.623529411764706, 0.933333333333333), 1e-14); @@ -7123,7 +7914,7 @@ defineSuite([ expect(e.properties.custom_unitSpherical.getValue(documentStopDate)).toEqualEpsilon(Cartesian3.fromSpherical(new Spherical(44800, 8111)), 1e-14); expect(e.properties.custom_rgba.getValue(documentStartDate)).toEqual(Color.fromBytes(179, 175, 115, 46)); expect(e.properties.custom_rgba.getValue(documentStopDate)).toEqual(Color.fromBytes(136, 187, 237, 156)); - expect(e.properties.custom_rgbaf.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431373, 0.450980392156863, 0.588235294117647, 0.72156862745098), 1e-14); + expect(e.properties.custom_rgbaf.getValue(documentStartDate)).toEqualEpsilon(new Color(0.890196078431372, 0.450980392156863, 0.588235294117647, 0.72156862745098), 1e-14); expect(e.properties.custom_rgbaf.getValue(documentStopDate)).toEqualEpsilon(new Color(0.419607843137255, 0.843137254901961, 0.36078431372549, 0.423529411764706), 1e-14); expect(e.properties.custom_number.getValue(documentStartDate)).toEqual(24561.0); expect(e.properties.custom_number.getValue(documentStopDate)).toEqual(45446.0); diff --git a/Specs/DataSources/PolygonGraphicsSpec.js b/Specs/DataSources/PolygonGraphicsSpec.js index 615556dbdfb7..85772a99de9b 100644 --- a/Specs/DataSources/PolygonGraphicsSpec.js +++ b/Specs/DataSources/PolygonGraphicsSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'DataSources/PolygonGraphics', 'Core/ArcType', + 'Core/Cartesian3', 'Core/Color', 'Core/DistanceDisplayCondition', 'Core/PolygonHierarchy', @@ -13,6 +14,7 @@ defineSuite([ ], function( PolygonGraphics, ArcType, + Cartesian3, Color, DistanceDisplayCondition, PolygonHierarchy, @@ -275,4 +277,29 @@ defineSuite([ testDefinitionChanged(property, 'arcType', ArcType.GEODESIC, ArcType.RHUMB); testDefinitionChanged(property, 'zIndex', 54, 3); }); + + it('converts an array of positions to a PolygonHierarchy', function() { + var positions = [ + new Cartesian3(1, 2, 3), + new Cartesian3(4, 5, 6), + new Cartesian3(7, 8, 9) + ]; + + var graphics = new PolygonGraphics({ + hierarchy: positions + }); + + expect(graphics.hierarchy).toBeInstanceOf(ConstantProperty); + var hierarchy = graphics.hierarchy.getValue(); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(positions); + + graphics = new PolygonGraphics(); + graphics.hierarchy = positions; + + expect(graphics.hierarchy).toBeInstanceOf(ConstantProperty); + hierarchy = graphics.hierarchy.getValue(); + expect(hierarchy).toBeInstanceOf(PolygonHierarchy); + expect(hierarchy.positions).toEqual(positions); + }); });