From e8e07959f09e52a1a3766b0570b8d8bd0b8b3e90 Mon Sep 17 00:00:00 2001 From: Kangning Li Date: Tue, 19 Jun 2018 16:18:31 -0400 Subject: [PATCH 1/3] use polylines on terrain for CZML, KML, and GeoJson --- Apps/Sandcastle/gallery/CZML Polyline.html | 5 +-- Source/DataSources/CzmlDataSource.js | 2 ++ Source/DataSources/GeoJsonDataSource.js | 19 ++++-------- Source/DataSources/KmlDataSource.js | 19 ++++++------ Specs/DataSources/CzmlDataSourceSpec.js | 36 ++++++++++++++++++++++ Specs/DataSources/GeoJsonDataSourceSpec.js | 14 +++++---- Specs/DataSources/KmlDataSourceSpec.js | 16 +++++----- 7 files changed, 72 insertions(+), 39 deletions(-) diff --git a/Apps/Sandcastle/gallery/CZML Polyline.html b/Apps/Sandcastle/gallery/CZML Polyline.html index cbbd05015e99..4b39e7c0f5f3 100644 --- a/Apps/Sandcastle/gallery/CZML Polyline.html +++ b/Apps/Sandcastle/gallery/CZML Polyline.html @@ -34,7 +34,7 @@ "version" : "1.0" }, { "id" : "redLine", - "name" : "Red line on the surface", + "name" : "Red line clamped to terain", "polyline" : { "positions" : { "cartographicDegrees" : [ @@ -49,7 +49,8 @@ } } }, - "width" : 5 + "width" : 5, + "clampToGround" : true } }, { "id" : "blueLine", diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 4a521272b462..e82cfa485d30 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1792,8 +1792,10 @@ define([ processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'depthFailMaterial', polylineData.depthFailMaterial, interval, sourceUri, entityCollection); processPacketData(Boolean, polyline, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection); + processPacketData(Boolean, polyline, 'clampToGround', polylineData.clampToGround, interval, sourceUri, entityCollection); processPacketData(ShadowMode, polyline, 'shadows', polylineData.shadows, interval, sourceUri, entityCollection); processPacketData(DistanceDisplayCondition, polyline, 'distanceDisplayCondition', polylineData.distanceDisplayCondition, interval, sourceUri, entityCollection); + processPacketData(Number, polyline, 'zIndex', polylineData.zIndex, interval, sourceUri, entityCollection); } function processRectangle(entity, packet, entityCollection, sourceUri) { diff --git a/Source/DataSources/GeoJsonDataSource.js b/Source/DataSources/GeoJsonDataSource.js index 8522c3fb45eb..57137e6ae287 100644 --- a/Source/DataSources/GeoJsonDataSource.js +++ b/Source/DataSources/GeoJsonDataSource.js @@ -21,7 +21,6 @@ define([ './ColorMaterialProperty', './ConstantPositionProperty', './ConstantProperty', - './CorridorGraphics', './DataSource', './EntityCluster', './EntityCollection', @@ -50,7 +49,6 @@ define([ ColorMaterialProperty, ConstantPositionProperty, ConstantProperty, - CorridorGraphics, DataSource, EntityCluster, EntityCollection, @@ -360,18 +358,13 @@ define([ } var entity = createObject(geoJson, dataSource._entityCollection, options.describe); - var graphics; - if (options.clampToGround) { - graphics = new CorridorGraphics(); - entity.corridor = graphics; - } else { - graphics = new PolylineGraphics(); - entity.polyline = graphics; - } + var polylineGraphics = new PolylineGraphics(); + entity.polyline = polylineGraphics; - graphics.material = material; - graphics.width = widthProperty; - graphics.positions = new ConstantProperty(coordinatesArrayToCartesianArray(coordinates, crsFunction)); + polylineGraphics.clampToGround = options.clampToGround; + polylineGraphics.material = material; + polylineGraphics.width = widthProperty; + polylineGraphics.positions = new ConstantProperty(coordinatesArrayToCartesianArray(coordinates, crsFunction)); } function processLineString(dataSource, geoJson, geometry, crsFunction, options) { diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index f51d5d25a904..c1154d45d2fc 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -42,7 +42,6 @@ define([ '../ThirdParty/zip', './BillboardGraphics', './CompositePositionProperty', - './CorridorGraphics', './DataSource', './DataSourceClock', './Entity', @@ -108,7 +107,6 @@ define([ zip, BillboardGraphics, CompositePositionProperty, - CorridorGraphics, DataSource, DataSourceClock, Entity, @@ -1255,17 +1253,18 @@ define([ wall.outlineColor = defined(polygon.material) ? polygon.material.color : Color.WHITE; } } else if (dataSource._clampToGround && !canExtrude && tessellate) { - var corridor = new CorridorGraphics(); - entity.corridor = corridor; - corridor.positions = coordinates; + var polylineGraphics = new PolylineGraphics(); + polylineGraphics.clampToGround = true; + entity.polyline = polylineGraphics; + polylineGraphics.positions = coordinates; if (defined(polyline)) { - corridor.material = defined(polyline.material) ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE) : Color.WHITE; - corridor.width = defaultValue(polyline.width, 1.0); + polylineGraphics.material = defined(polyline.material) ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE) : Color.WHITE; + polylineGraphics.width = defaultValue(polyline.width, 1.0); } else { - corridor.material = Color.WHITE; - corridor.width = 1.0; + polylineGraphics.material = Color.WHITE; + polylineGraphics.width = 1.0; } - corridor.zIndex = zIndex; + polyline.zIndex = zIndex; } else { if (defined(zIndex)) { oneTimeWarning('kml-gx:drawOrder', 'KML - gx:drawOrder is not supported in LineStrings when clampToGround is false'); diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index fe019bcaf18f..6c5084a358aa 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -2509,6 +2509,42 @@ defineSuite([ }); }); + it('CZML adds data for polyline clamped to terrain.', function() { + var polylinePacket = { + polyline : { + material : { + polylineOutline : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0 + } + }, + width : 1.0, + show : true, + clampToGround : true, + zIndex : 1 + } + }; + + var dataSource = new CzmlDataSource(); + return dataSource.load(makePacket(polylinePacket)).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); + }); + }); + it('CZML adds data for infinite model.', function() { var modelPacket = { model : { diff --git a/Specs/DataSources/GeoJsonDataSourceSpec.js b/Specs/DataSources/GeoJsonDataSourceSpec.js index 18fd511998bd..135e6a4d0279 100644 --- a/Specs/DataSources/GeoJsonDataSourceSpec.js +++ b/Specs/DataSources/GeoJsonDataSourceSpec.js @@ -688,9 +688,10 @@ defineSuite([ var entityCollection = dataSource.entities; var entity = entityCollection.values[0]; expect(entity.properties).toBe(lineString.properties); - expect(entity.corridor.positions.getValue(time)).toEqual(coordinatesArrayToCartesian(lineString.coordinates)); - expect(entity.corridor.material.color.getValue(time)).toEqual(GeoJsonDataSource.stroke); - expect(entity.corridor.width.getValue(time)).toEqual(2); + expect(entity.polyline.positions.getValue(time)).toEqual(coordinatesArrayToCartesian(lineString.coordinates)); + expect(entity.polyline.material.color.getValue(time)).toEqual(GeoJsonDataSource.stroke); + expect(entity.polyline.width.getValue(time)).toEqual(2); + expect(entity.polyline.clampToGround.getValue(time)).toEqual(true); }); }); @@ -721,9 +722,10 @@ defineSuite([ for (var i = 0; i < multiLineString.coordinates.length; i++) { var entity = entities[i]; expect(entity.properties).toBe(multiLineString.properties); - expect(entity.corridor.positions.getValue(time)).toEqual(lines[i]); - expect(entity.corridor.material.color.getValue(time)).toEqual(Color.YELLOW); - expect(entity.corridor.width.getValue(time)).toEqual(2); + expect(entity.polyline.positions.getValue(time)).toEqual(lines[i]); + expect(entity.polyline.material.color.getValue(time)).toEqual(Color.YELLOW); + expect(entity.polyline.width.getValue(time)).toEqual(2); + expect(entity.polyline.clampToGround.getValue(time)).toEqual(true); } }); }); diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js index f0cca59b327a..f91728707c53 100644 --- a/Specs/DataSources/KmlDataSourceSpec.js +++ b/Specs/DataSources/KmlDataSourceSpec.js @@ -7,7 +7,6 @@ defineSuite([ 'Core/ClockStep', 'Core/Color', 'Core/combine', - 'Core/DefaultProxy', 'Core/Ellipsoid', 'Core/Event', 'Core/HeadingPitchRange', @@ -46,7 +45,6 @@ defineSuite([ ClockStep, Color, combine, - DefaultProxy, Ellipsoid, Event, HeadingPitchRange, @@ -4422,7 +4420,7 @@ defineSuite([ }); }); - it('when a LineString is clamped to ground and tesselated, entity has a corridor geometry and ColorProperty', function() { + it('when a LineString is clamped to ground and tesselated, entity has a polyline geometry and ColorProperty', function() { var kml = '\ \