diff --git a/CHANGES.md b/CHANGES.md index 4b693172482e..368541f6aa82 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,12 +7,17 @@ Change Log * `Rectangle.intersectWith` was deprecated in Cesium 1.5. Use `Rectangle.intersection`, which is the same but returns `undefined` when two rectangles do not intersect. * `Rectangle.isEmpty` was deprecated in Cesium 1.5. * The `sourceUri` parameter to `GeoJsonDatasource.load` was deprecated in Cesium 1.4 and has been removed. Use options.sourceUri instead. + * `PolygonGraphics.positions` created by `GeoJSONDataSource` now evaluate to a `PolygonHierarchy` object instead of an array of positions. * Deprecated - * + * `PolygonGraphics.positions` was deprecated and replaced with `PolygonGraphics.hierarchy`, whose value is a `PolygonHierarchy` instead of an array of positions. `PolygonGraphics.positions` will be removed in Cesium 1.8. * Improved performance of asynchronous geometry creation (as much as 20% faster in some use cases). [#2342](https://github.com/AnalyticalGraphicsInc/cesium/issues/2342) * Added `PolylineVolumeGraphics` and `Entity.polylineVolume` * Added `BillboardGraphics.imageSubRegion`, to enable custom texture atlas use for `Entity` instances. * Added `CheckerboardMaterialProperty` to enable use of the checkerboard material with the entity API. +* Added `PolygonHierarchy` to make defining polygons with holes clearer. +* Added `PolygonGraphics.hierarchy` for supporting polygons with holes via data sources. +* `GeoJsonDataSource` now supports polygons with holes. +* `ConstantProperty` can now hold any value; previously it was limited to values that implemented `equals` and `clones` functions, as well as a few special cases. ### 1.5 - 2015-01-05 diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index 25aea1ac76a5..e57f3c5b523f 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -522,7 +522,7 @@ define([ * @constructor * * @param {Object} options Object with the following properties: - * @param {Object} options.polygonHierarchy A polygon hierarchy that can include holes. + * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes. * @param {Number} [options.height=0.0] The height of the polygon. * @param {Number} [options.extrudedHeight] The height of the polygon. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed. diff --git a/Source/Core/PolygonHierarchy.js b/Source/Core/PolygonHierarchy.js new file mode 100644 index 000000000000..fb9887c73433 --- /dev/null +++ b/Source/Core/PolygonHierarchy.js @@ -0,0 +1,29 @@ +/*global define*/ +define(['./defined'], function(defined) { + "use strict"; + + /** + * An hierarchy of linear rings which define a polygon and its holes. + * The holes themselves may also have holes which nest inner polygons. + * @alias PolygonHierarchy + * @constructor + * + * @param {Cartesian3[]} [positions] A linear ring defining the outer boundary of the polygon or hole. + * @param {PolygonHierarchy[]} [holes] An array of polygon hierarchies defining holes in the polygon. + */ + var PolygonHierarchy = function(positions, holes) { + /** + * A linear ring defining the outer boundary of the polygon or hole. + * @type {Cartesian3[]} + */ + this.positions = defined(positions) ? positions : []; + + /** + * An array of polygon hierarchies defining holes in the polygon. + * @type {PolygonHierarchy[]} + */ + this.holes = defined(holes) ? holes : []; + }; + + return PolygonHierarchy; +}); diff --git a/Source/DataSources/ConstantProperty.js b/Source/DataSources/ConstantProperty.js index 1275ced733ca..cb236321878d 100644 --- a/Source/DataSources/ConstantProperty.js +++ b/Source/DataSources/ConstantProperty.js @@ -1,21 +1,20 @@ /*global define*/ define([ '../Core/defaultValue', + '../Core/defined', '../Core/defineProperties', '../Core/DeveloperError', - '../Core/Event', - '../Core/isArray' + '../Core/Event' ], function( defaultValue, + defined, defineProperties, DeveloperError, - Event, - isArray) { + Event) { "use strict"; /** * A {@link Property} whose value does not change with respect to simulation time. - * If the value is not a number, string, array, or HTMLElement then it must provide clone and equals functions. * * @alias ConstantProperty * @constructor @@ -29,7 +28,8 @@ define([ */ var ConstantProperty = function(value) { this._value = undefined; - this._simple = true; + this._hasClone = false; + this._hasEquals = false; this._definitionChanged = new Event(); this.setValue(value); }; @@ -70,12 +70,11 @@ define([ * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. */ ConstantProperty.prototype.getValue = function(time, result) { - return this._simple ? this._value : this._value.clone(result); + return this._hasClone ? this._value.clone(result) : this._value; }; /** * Sets the value of the property. - * If the value is not a number, string, array, or HTMLElement then it must provide clone and equals functions. * * @param {Object} value The property value. * @@ -84,24 +83,19 @@ define([ */ ConstantProperty.prototype.setValue = function(value) { var oldValue = this._value; - var simple = this._simple; - if ((simple && oldValue !== value) || (!simple && !oldValue.equals(value))) { - simple = typeof value !== 'object' || value instanceof HTMLElement || isArray(value); + if (oldValue !== value) { + var isDefined = defined(value); + var hasClone = isDefined && typeof value.clone === 'function'; + var hasEquals = isDefined && typeof value.equals === 'function'; - //>>includeStart('debug', pragmas.debug); - if (!simple) { - if (typeof value.clone !== 'function') { - throw new DeveloperError('clone is a required function.'); - } - if (typeof value.equals !== 'function') { - throw new DeveloperError('equals is a required function.'); - } - } - //>>includeEnd('debug'); + this._hasClone = hasClone; + this._hasEquals = hasEquals; - this._value = simple ? value : value.clone(); - this._simple = simple; - this._definitionChanged.raiseEvent(this); + var changed = !hasEquals || !value.equals(oldValue); + if (changed) { + this._value = !hasClone ? value : value.clone(); + this._definitionChanged.raiseEvent(this); + } } }; @@ -115,8 +109,8 @@ define([ ConstantProperty.prototype.equals = function(other) { return this === other || // (other instanceof ConstantProperty && // - ((this._simple && (this._value === other._value)) || // - (!this._simple && this._value.equals(other._value)))); + ((!this._hasEquals && (this._value === other._value)) || // + (this._hasEquals && this._value.equals(other._value)))); }; return ConstantProperty; diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 0cb50e6f4c91..b68e3364ed76 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -850,7 +850,7 @@ define([ } } - function processVertexData(object, positionsData, entityCollection) { + function processVertexData(object, propertyName, positionsData, entityCollection) { var i; var len; var references = positionsData.references; @@ -863,13 +863,14 @@ define([ var iso8601Interval = positionsData.interval; if (defined(iso8601Interval)) { iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - if (!(object.positions instanceof CompositePositionProperty)) { - object.positions = new CompositePositionProperty(); + if (!(object[propertyName] instanceof CompositePositionProperty)) { iso8601Interval.data = new PositionPropertyArray(properties); - object.positions.intervals.addInterval(iso8601Interval); + var property = new CompositePositionProperty(); + property.intervals.addInterval(iso8601Interval); + object[propertyName] = property; } } else { - object.positions = new PositionPropertyArray(properties); + object[propertyName] = new PositionPropertyArray(properties); } } else { var values = []; @@ -900,12 +901,12 @@ define([ } } if (defined(positionsData.array)) { - processPacketData(Array, object, 'positions', positionsData, undefined, undefined, entityCollection); + processPacketData(Array, object, propertyName, positionsData, undefined, undefined, entityCollection); } } } - function processPositions(object, positionsData, entityCollection) { + function processPositions(object, propertyName, positionsData, entityCollection) { if (!defined(positionsData)) { return; } @@ -913,10 +914,10 @@ define([ if (isArray(positionsData)) { var length = positionsData.length; for (var i = 0; i < length; i++) { - processVertexData(object, positionsData[i], entityCollection); + processVertexData(object, propertyName, positionsData[i], entityCollection); } } else { - processVertexData(object, positionsData, entityCollection); + processVertexData(object, propertyName, positionsData, entityCollection); } } @@ -1223,7 +1224,7 @@ define([ processPacketData(Color, polygon, 'outlineColor', polygonData.outlineColor, interval, sourceUri, entityCollection); processPacketData(Number, polygon, 'outlineWidth', polygonData.outlineWidth, interval, sourceUri, entityCollection); processPacketData(Boolean, polygon, 'perPositionHeight', polygonData.perPositionHeight, interval, sourceUri, entityCollection); - processPositions(polygon, polygonData.positions, entityCollection); + processPositions(polygon, 'hierarchy', polygonData.positions, entityCollection); } function processRectangle(entity, packet, entityCollection, sourceUri) { @@ -1287,7 +1288,7 @@ define([ processPacketData(Boolean, wall, 'outline', wallData.outline, interval, sourceUri, entityCollection); processPacketData(Color, wall, 'outlineColor', wallData.outlineColor, interval, sourceUri, entityCollection); processPacketData(Number, wall, 'outlineWidth', wallData.outlineWidth, interval, sourceUri, entityCollection); - processPositions(wall, wallData.positions, entityCollection); + processPositions(wall, 'positions', wallData.positions, entityCollection); } function processPolyline(entity, packet, entityCollection, sourceUri) { @@ -1313,7 +1314,7 @@ define([ processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); processPacketData(Boolean, polyline, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection); processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection); - processPositions(polyline, polylineData.positions, entityCollection); + processPositions(polyline, 'positions', polylineData.positions, entityCollection); } function processCzmlPacket(packet, entityCollection, updaterFunctions, sourceUri, dataSource) { diff --git a/Source/DataSources/GeoJsonDataSource.js b/Source/DataSources/GeoJsonDataSource.js index aae4727cdb9a..e89c45131a47 100644 --- a/Source/DataSources/GeoJsonDataSource.js +++ b/Source/DataSources/GeoJsonDataSource.js @@ -11,6 +11,7 @@ define([ '../Core/getFilenameFromUri', '../Core/loadJson', '../Core/PinBuilder', + '../Core/PolygonHierarchy', '../Core/RuntimeError', '../Scene/VerticalOrigin', '../ThirdParty/topojson', @@ -36,6 +37,7 @@ define([ getFilenameFromUri, loadJson, PinBuilder, + PolygonHierarchy, RuntimeError, VerticalOrigin, topojson, @@ -346,6 +348,10 @@ define([ } function createPolygon(dataSource, geoJson, crsFunction, coordinates, options) { + if (coordinates.length === 0 || coordinates[0].length === 0) { + return; + } + var outlineColorProperty = options.strokeMaterialProperty.color; var material = options.fillMaterialProperty; var widthProperty = options.strokeWidthProperty; @@ -397,8 +403,15 @@ define([ polygon.outlineColor = outlineColorProperty; polygon.outlineWidth = widthProperty; polygon.material = material; - polygon.positions = new ConstantProperty(coordinatesArrayToCartesianArray(coordinates, crsFunction)); - if (coordinates.length > 0 && coordinates[0].length > 2) { + + var holes = []; + for (var i = 1, len = coordinates.length; i < len; i++) { + holes.push(new PolygonHierarchy(coordinatesArrayToCartesianArray(coordinates[i], crsFunction))); + } + + var positions = coordinates[0]; + polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(coordinatesArrayToCartesianArray(positions, crsFunction), holes)); + if (positions[0].length > 2) { polygon.perPositionHeight = new ConstantProperty(true); } @@ -407,13 +420,13 @@ define([ } function processPolygon(dataSource, geoJson, geometry, crsFunction, options) { - createPolygon(dataSource, geoJson, crsFunction, geometry.coordinates[0], options); + createPolygon(dataSource, geoJson, crsFunction, geometry.coordinates, options); } function processMultiPolygon(dataSource, geoJson, geometry, crsFunction, options) { var polygons = geometry.coordinates; for (var i = 0; i < polygons.length; i++) { - createPolygon(dataSource, geoJson, crsFunction, polygons[i][0], options); + createPolygon(dataSource, geoJson, crsFunction, polygons[i], options); } } diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index 9fc0d13d6546..c35b3523f4d1 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -8,9 +8,11 @@ define([ '../Core/destroyObject', '../Core/DeveloperError', '../Core/Event', + '../Core/isArray', '../Core/GeometryInstance', '../Core/Iso8601', '../Core/PolygonGeometry', + '../Core/PolygonHierarchy', '../Core/PolygonOutlineGeometry', '../Core/ShowGeometryInstanceAttribute', '../Scene/MaterialAppearance', @@ -29,9 +31,11 @@ define([ destroyObject, DeveloperError, Event, + isArray, GeometryInstance, Iso8601, PolygonGeometry, + PolygonHierarchy, PolygonOutlineGeometry, ShowGeometryInstanceAttribute, MaterialAppearance, @@ -53,9 +57,7 @@ define([ var GeometryOptions = function(entity) { this.id = entity; this.vertexFormat = undefined; - this.polygonHierarchy = { - positions : undefined - }; + this.polygonHierarchy = undefined; this.perPositionHeight = undefined; this.height = undefined; this.extrudedHeight = undefined; @@ -422,11 +424,11 @@ define([ return; } - var positions = polygon.positions; + var hierarchy = polygon.hierarchy; var show = polygon.show; if ((defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)) || // - (!defined(positions))) { + (!defined(hierarchy))) { if (this._fillEnabled || this._outlineEnabled) { this._fillEnabled = false; this._outlineEnabled = false; @@ -454,7 +456,7 @@ define([ this._fillEnabled = fillEnabled; this._outlineEnabled = outlineEnabled; - if (!positions.isConstant || // + if (!hierarchy.isConstant || // !Property.isConstant(height) || // !Property.isConstant(extrudedHeight) || // !Property.isConstant(granularity) || // @@ -468,7 +470,12 @@ define([ } else { var options = this._options; options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; - options.polygonHierarchy.positions = positions.getValue(Iso8601.MINIMUM_VALUE, options.polygonHierarchy.positions); + var hierarchyValue = hierarchy.getValue(Iso8601.MINIMUM_VALUE); + if (isArray(hierarchyValue)) { + options.polygonHierarchy = new PolygonHierarchy(hierarchyValue); + } else { + options.polygonHierarchy = hierarchyValue; + } options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; @@ -532,12 +539,17 @@ define([ } var options = this._options; - var positions = Property.getValueOrUndefined(polygon.positions, time, options.polygonHierarchy.positions); - if (!defined(positions)) { + var hierarchy = Property.getValueOrUndefined(polygon.hierarchy, time); + if (!defined(hierarchy)) { return; } - options.polygonHierarchy.positions = positions; + if (isArray(hierarchy)) { + options.polygonHierarchy = new PolygonHierarchy(hierarchy); + } else { + options.polygonHierarchy = hierarchy; + } + options.height = Property.getValueOrUndefined(polygon.height, time); options.extrudedHeight = Property.getValueOrUndefined(polygon.extrudedHeight, time); options.granularity = Property.getValueOrUndefined(polygon.granularity, time); diff --git a/Source/DataSources/PolygonGraphics.js b/Source/DataSources/PolygonGraphics.js index 1bd31e48697c..b83aa27233be 100644 --- a/Source/DataSources/PolygonGraphics.js +++ b/Source/DataSources/PolygonGraphics.js @@ -3,6 +3,7 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', './createPropertyDescriptor' @@ -10,6 +11,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, DeveloperError, Event, createPropertyDescriptor) { @@ -26,8 +28,8 @@ define([ this._showSubscription = undefined; this._material = undefined; this._materialSubscription = undefined; - this._positions = undefined; - this._positionsSubscription = undefined; + this._hierarchy = undefined; + this._hierarchySubscription = undefined; this._height = undefined; this._heightSubscription = undefined; this._extrudedHeight = undefined; @@ -78,11 +80,27 @@ define([ material : createPropertyDescriptor('material'), /** - * Gets or sets the vertex positions. + * Gets or sets the positions that define the polygon. * @memberof PolygonGraphics.prototype * @type {Property} */ - positions : createPropertyDescriptor('positions'), + positions : { + get : function() { + deprecationWarning('PolygonGraphics.positions', 'PolygonGraphics.positions was deprecated in Cesium 1.6, use PolygonGraphics.hierarchy instead. This property will be removed in Cesium 1.9.'); + return this.hierarchy; + }, + set : function(value) { + deprecationWarning('PolygonGraphics.positions', 'PolygonGraphics.positions was deprecated in Cesium 1.6, use PolygonGraphics.hierarchy instead. This property will be removed in Cesium 1.9.'); + this.hierarchy = value; + } + }, + + /** + * Gets or sets the property specifying the {@link PolygonHierarchy}. + * @memberof PolygonGraphics.prototype + * @type {Property} + */ + hierarchy : createPropertyDescriptor('hierarchy'), /** * Gets or sets the Number {@link Property} specifying the height of the polygon. @@ -165,7 +183,7 @@ define([ } result.show = this.show; result.material = this.material; - result.positions = this.positions; + result.hierarchy = this.hierarchy; result.height = this.height; result.extrudedHeight = this.extrudedHeight; result.granularity = this.granularity; @@ -193,7 +211,7 @@ define([ this.show = defaultValue(this.show, source.show); this.material = defaultValue(this.material, source.material); - this.positions = defaultValue(this.positions, source.positions); + this.hierarchy = defaultValue(this.hierarchy, source.hierarchy); this.height = defaultValue(this.height, source.height); this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight); this.granularity = defaultValue(this.granularity, source.granularity); diff --git a/Source/DataSources/PositionPropertyArray.js b/Source/DataSources/PositionPropertyArray.js index 2ddf7dc376d2..15b772084f89 100644 --- a/Source/DataSources/PositionPropertyArray.js +++ b/Source/DataSources/PositionPropertyArray.js @@ -143,7 +143,6 @@ define([ /** * Sets the value of the property. - * If the value is an object, the object must provide clone and equals functions. * * @param {Property[]} value An array of Property instances. */ diff --git a/Source/DataSources/TimeIntervalCollectionProperty.js b/Source/DataSources/TimeIntervalCollectionProperty.js index e912f07c97f8..04992dc78eb9 100644 --- a/Source/DataSources/TimeIntervalCollectionProperty.js +++ b/Source/DataSources/TimeIntervalCollectionProperty.js @@ -4,7 +4,6 @@ define([ '../Core/defineProperties', '../Core/DeveloperError', '../Core/Event', - '../Core/isArray', '../Core/TimeIntervalCollection', './Property' ], function( @@ -12,7 +11,6 @@ define([ defineProperties, DeveloperError, Event, - isArray, TimeIntervalCollection, Property) { "use strict"; @@ -106,8 +104,6 @@ define([ * @param {JulianDate} time The time for which to retrieve the value. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. - * - * @exception {DeveloperError} This value requires a clone function be specified for the TimeIntervalCollectionProperty constructor. */ TimeIntervalCollectionProperty.prototype.getValue = function(time, result) { //>>includeStart('debug', pragmas.debug); @@ -117,7 +113,7 @@ define([ //>>includeEnd('debug'); var value = this._intervals.findDataForIntervalContainingDate(time); - if (defined(value) && (typeof value === 'object' && !isArray(value))) { + if (defined(value) && (typeof value.clone === 'function')) { return value.clone(result); } return value; diff --git a/Specs/DataSources/ConstantPropertySpec.js b/Specs/DataSources/ConstantPropertySpec.js index 06ce997b9653..facaa3f6aa0f 100644 --- a/Specs/DataSources/ConstantPropertySpec.js +++ b/Specs/DataSources/ConstantPropertySpec.js @@ -27,6 +27,15 @@ defineSuite([ expect(result).toEqual(value); }); + it('works with objects without clone', function() { + var value = {}; + var property = new ConstantProperty(value); + + var result = property.getValue(time); + expect(result).toBe(value); + expect(result).toEqual(value); + }); + it('setValue raises definitionChanged event', function() { var property = new ConstantProperty(); var listener = jasmine.createSpy('listener'); @@ -58,27 +67,7 @@ defineSuite([ expect(property.getValue()).toBeUndefined(); }); - it('constructor throws with undefined clone function on non-basic type', function() { - expect(function() { - return new ConstantProperty({ - equals : function() { - return true; - } - }); - }).toThrowDeveloperError(); - }); - - it('constructor throws with undefined equals function on non-basic type', function() { - expect(function() { - return new ConstantProperty({ - clone : function() { - return {}; - } - }); - }).toThrowDeveloperError(); - }); - - it('equals works for object types', function() { + it('equals works for object types with "equals" function', function() { var left = new ConstantProperty(new Cartesian3(1, 2, 3)); var right = new ConstantProperty(new Cartesian3(1, 2, 3)); @@ -88,6 +77,17 @@ defineSuite([ expect(left.equals(right)).toEqual(false); }); + it('equals works for object types without "equals" function', function() { + var value = {}; + var left = new ConstantProperty(value); + var right = new ConstantProperty(value); + + expect(left.equals(right)).toEqual(true); + + right = new ConstantProperty({}); + expect(left.equals(right)).toEqual(false); + }); + it('equals works for simple types', function() { var left = new ConstantProperty(1); var right = new ConstantProperty(1); diff --git a/Specs/DataSources/GeoJsonDataSourceSpec.js b/Specs/DataSources/GeoJsonDataSourceSpec.js index 99ed9092f196..5dc3126cb0e8 100644 --- a/Specs/DataSources/GeoJsonDataSourceSpec.js +++ b/Specs/DataSources/GeoJsonDataSourceSpec.js @@ -5,6 +5,7 @@ defineSuite([ 'Core/Color', 'Core/Event', 'Core/JulianDate', + 'Core/PolygonHierarchy', 'DataSources/EntityCollection', 'Specs/waitsForPromise', 'ThirdParty/when' @@ -14,6 +15,7 @@ defineSuite([ Color, Event, JulianDate, + PolygonHierarchy, EntityCollection, waitsForPromise, when) { @@ -69,7 +71,7 @@ defineSuite([ } function polygonCoordinatesToCartesian(coordinates) { - return coordinatesArrayToCartesian(coordinates[0]); + return coordinatesArrayToCartesian(coordinates); } function multiPolygonCoordinatesToCartesian(coordinates) { @@ -150,7 +152,7 @@ defineSuite([ var multiPolygon = { type : 'MultiPolygon', - coordinates : [[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]] + coordinates : [[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]] }; var geometryCollection = { @@ -400,7 +402,7 @@ defineSuite([ var entityCollection = dataSource.entities; var entity = entityCollection.entities[0]; expect(entity.properties).toBe(polygon.properties); - expect(entity.polygon.positions.getValue(time)).toEqual(polygonCoordinatesToCartesian(polygon.coordinates)); + expect(entity.polygon.hierarchy.getValue(time)).toEqual(new PolygonHierarchy(polygonCoordinatesToCartesian(polygon.coordinates[0]))); expect(entity.polygon.perPositionHeight).toBeUndefined(); expect(entity.polygon.material.color.getValue(time)).toEqual(GeoJsonDataSource.fill); expect(entity.polygon.outline.getValue(time)).toEqual(true); @@ -415,7 +417,7 @@ defineSuite([ var entityCollection = dataSource.entities; var entity = entityCollection.entities[0]; expect(entity.properties).toBe(polygonWithHeights.properties); - expect(entity.polygon.positions.getValue(time)).toEqual(polygonCoordinatesToCartesian(polygonWithHeights.coordinates)); + expect(entity.polygon.hierarchy.getValue(time)).toEqual(new PolygonHierarchy(polygonCoordinatesToCartesian(polygonWithHeights.coordinates[0]))); expect(entity.polygon.perPositionHeight.getValue(time)).toBe(true); expect(entity.polygon.material.color.getValue(time)).toEqual(GeoJsonDataSource.fill); expect(entity.polygon.outline.getValue(time)).toEqual(true); @@ -430,7 +432,7 @@ defineSuite([ var entityCollection = dataSource.entities; var entity = entityCollection.entities[0]; expect(entity.properties).toBe(polygonWithHoles.properties); - expect(entity.polygon.positions.getValue(time)).toEqual(polygonCoordinatesToCartesian(polygonWithHoles.coordinates)); + expect(entity.polygon.hierarchy.getValue(time)).toEqual(new PolygonHierarchy(polygonCoordinatesToCartesian(polygonWithHoles.coordinates[0]), [new PolygonHierarchy(polygonCoordinatesToCartesian(polygonWithHoles.coordinates[1]))])); }); }); @@ -443,7 +445,7 @@ defineSuite([ for (var i = 0; i < multiPolygon.coordinates.length; i++) { var entity = entities[i]; expect(entity.properties).toBe(multiPolygon.properties); - expect(entity.polygon.positions.getValue(time)).toEqual(positions[i]); + expect(entity.polygon.hierarchy.getValue(time)).toEqual(new PolygonHierarchy(positions[i])); } }); }); @@ -456,7 +458,7 @@ defineSuite([ var polygon = entities[0]; expect(polygon.properties).toBe(topoJson.objects.polygon.properties); - expect(polygon.polygon.positions).toBeDefined(); + expect(polygon.polygon.hierarchy).toBeDefined(); var lineString = entities[1]; expect(lineString.properties).toBe(topoJson.objects.lineString.properties); diff --git a/Specs/DataSources/PolygonGeometryUpdaterSpec.js b/Specs/DataSources/PolygonGeometryUpdaterSpec.js index fd0c9e7811f5..d43a93c0f2bc 100644 --- a/Specs/DataSources/PolygonGeometryUpdaterSpec.js +++ b/Specs/DataSources/PolygonGeometryUpdaterSpec.js @@ -5,6 +5,7 @@ defineSuite([ 'Core/Color', 'Core/ColorGeometryInstanceAttribute', 'Core/JulianDate', + 'Core/PolygonHierarchy', 'Core/ShowGeometryInstanceAttribute', 'Core/TimeInterval', 'Core/TimeIntervalCollection', @@ -27,6 +28,7 @@ defineSuite([ Color, ColorGeometryInstanceAttribute, JulianDate, + PolygonHierarchy, ShowGeometryInstanceAttribute, TimeInterval, TimeIntervalCollection, @@ -60,12 +62,12 @@ defineSuite([ function createBasicPolygon() { var polygon = new PolygonGraphics(); - polygon.positions = new ConstantProperty(Cartesian3.fromRadiansArray([ + polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(Cartesian3.fromRadiansArray([ 0, 0, 1, 0, 1, 1, 0, 1 - ])); + ]))); var entity = new Entity(); entity.polygon = polygon; return entity; @@ -160,8 +162,8 @@ defineSuite([ var point3 = new SampledPositionProperty(); point3.addSample(time, new Cartesian3()); - entity.polygon.positions = new PropertyArray(); - entity.polygon.positions.setValue([point1, point2, point3]); + entity.polygon.hierarchy = new PropertyArray(); + entity.polygon.hierarchy.setValue([point1, point2, point3]); expect(updater.isDynamic).toBe(true); }); @@ -357,12 +359,12 @@ defineSuite([ it('dynamic updater sets properties', function() { var polygon = new PolygonGraphics(); - polygon.positions = createDynamicProperty(Cartesian3.fromRadiansArray([ + polygon.hierarchy = createDynamicProperty(new PolygonHierarchy(Cartesian3.fromRadiansArray([ 0, 0, 1, 0, 1, 1, 0, 1 - ])); + ]))); polygon.show = createDynamicProperty(true); polygon.height = createDynamicProperty(3); polygon.extrudedHeight = createDynamicProperty(2); @@ -386,7 +388,7 @@ defineSuite([ var options = dynamicUpdater._options; expect(options.id).toEqual(entity); - expect(options.polygonHierarchy.positions).toEqual(polygon.positions.getValue()); + expect(options.polygonHierarchy).toEqual(polygon.hierarchy.getValue()); expect(options.height).toEqual(polygon.height.getValue()); expect(options.extrudedHeight).toEqual(polygon.extrudedHeight.getValue()); expect(options.perPositionHeight).toEqual(polygon.perPositionHeight.getValue()); @@ -403,7 +405,7 @@ defineSuite([ expect(primitives.length).toBe(2); //If a dynamic position returns undefined, the primitive should go away. - polygon.positions.setValue(undefined); + polygon.hierarchy.setValue(undefined); dynamicUpdater.update(time); expect(primitives.length).toBe(0); @@ -417,7 +419,7 @@ defineSuite([ var listener = jasmine.createSpy('listener'); updater.geometryChanged.addEventListener(listener); - entity.polygon.positions = new ConstantProperty([]); + entity.polygon.hierarchy = new ConstantProperty([]); expect(listener.callCount).toEqual(1); entity.polygon.height = new ConstantProperty(82); @@ -426,7 +428,7 @@ defineSuite([ entity.availability = new TimeIntervalCollection(); expect(listener.callCount).toEqual(3); - entity.polygon.positions = undefined; + entity.polygon.hierarchy = undefined; expect(listener.callCount).toEqual(4); //Since there's no valid geometry, changing another property should not raise the event. diff --git a/Specs/DataSources/PolygonGraphicsSpec.js b/Specs/DataSources/PolygonGraphicsSpec.js index 10237f9e70b2..cb7b8c63ef9c 100644 --- a/Specs/DataSources/PolygonGraphicsSpec.js +++ b/Specs/DataSources/PolygonGraphicsSpec.js @@ -19,7 +19,7 @@ defineSuite([ it('merge assigns unassigned properties', function() { var source = new PolygonGraphics(); source.material = new ColorMaterialProperty(); - source.positions = new ConstantProperty(); + source.hierarchy = new ConstantProperty(); source.show = new ConstantProperty(); source.height = new ConstantProperty(); source.extrudedHeight = new ConstantProperty(); @@ -35,7 +35,7 @@ defineSuite([ target.merge(source); expect(target.material).toBe(source.material); - expect(target.positions).toBe(source.positions); + expect(target.hierarchy).toBe(source.hierarchy); expect(target.show).toBe(source.show); expect(target.height).toBe(source.height); expect(target.extrudedHeight).toBe(source.extrudedHeight); @@ -66,7 +66,7 @@ defineSuite([ var target = new PolygonGraphics(); target.material = material; - target.positions = positions; + target.hierarchy = positions; target.show = show; target.height = height; target.extrudedHeight = extrudedHeight; @@ -81,7 +81,7 @@ defineSuite([ target.merge(source); expect(target.material).toBe(material); - expect(target.positions).toBe(positions); + expect(target.hierarchy).toBe(positions); expect(target.show).toBe(show); expect(target.height).toBe(height); expect(target.extrudedHeight).toBe(extrudedHeight); @@ -97,7 +97,7 @@ defineSuite([ it('clone works', function() { var source = new PolygonGraphics(); source.material = new ColorMaterialProperty(); - source.positions = new ConstantProperty(); + source.hierarchy = new ConstantProperty(); source.show = new ConstantProperty(); source.height = new ConstantProperty(); source.extrudedHeight = new ConstantProperty(); @@ -111,7 +111,7 @@ defineSuite([ var result = source.clone(); expect(result.material).toBe(source.material); - expect(result.positions).toBe(source.positions); + expect(result.hierarchy).toBe(source.hierarchy); expect(result.show).toBe(source.show); expect(result.height).toBe(source.height); expect(result.extrudedHeight).toBe(source.extrudedHeight); @@ -134,7 +134,7 @@ defineSuite([ it('raises definitionChanged when a property is assigned or modified', function() { var property = new PolygonGraphics(); testMaterialDefinitionChanged(property, 'material', Color.RED, Color.BLUE); - testDefinitionChanged(property, 'positions', [], []); + testDefinitionChanged(property, 'hierarchy', [], []); testDefinitionChanged(property, 'show', true, false); testDefinitionChanged(property, 'height', 3, 4); testDefinitionChanged(property, 'extrudedHeight', 4, 3);