Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use polylines on terrain for CZML, KML, and GeoJson #6706

Merged
merged 4 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Apps/Sandcastle/gallery/CZML Polyline.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"version" : "1.0"
}, {
"id" : "redLine",
"name" : "Red line on the surface",
"name" : "Red line clamped to terain",
"polyline" : {
"positions" : {
"cartographicDegrees" : [
Expand All @@ -49,7 +49,8 @@
}
}
},
"width" : 5
"width" : 5,
"clampToGround" : true
}
}, {
"id" : "blueLine",
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log
##### Breaking Changes :mega:
* glTF 2.0 models corrected to face +Z forwards per specification. Internally Cesium uses +X as forward, so a new +Z to +X rotation was added for 2.0 models only. [#6632](https://github.com/AnalyticalGraphicsInc/cesium/pull/6632)
* Dropped support for directory URLs when loading tilesets to match the updated [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/issues/272). [#6502](https://github.com/AnalyticalGraphicsInc/cesium/issues/6502)
* KML and GeoJSON now use `PolylineGraphics` instead of `CorridorGraphics` for polylines on terrain. [#6706](https://github.com/AnalyticalGraphicsInc/cesium/pull/6706)

##### Additions :tada:
* Added support for Polylines on Terrain via the `Entity` API [#6689](https://github.com/AnalyticalGraphicsInc/cesium/pull/6689)
Expand All @@ -15,6 +16,7 @@ Change Log
* Added `GroundPolylinePrimitive` and `GroundPolylineGeometry` for rendering polylines on terrain via the `Primitive` API. [#6615](https://github.com/AnalyticalGraphicsInc/cesium/pull/6615)
* Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`).
* Use `GroundPolylinePrimitive.isSupported` to check for support.
* CZML now supports `clampToGround` and `zIndex` properties for polylines. [#6706](https://github.com/AnalyticalGraphicsInc/cesium/pull/6706)
* `PostProcessStage` has a `selected` property which is an array of primitives used for selectively applying a post-process stage. [#6476](https://github.com/AnalyticalGraphicsInc/cesium/pull/6476)
* The `PostProcessStageLibrary.createBlackAndWhiteStage` and `PostProcessStageLibrary.createSilhouetteStage` have per-feature support.

Expand Down
2 changes: 2 additions & 0 deletions Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 6 additions & 13 deletions Source/DataSources/GeoJsonDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define([
'./ColorMaterialProperty',
'./ConstantPositionProperty',
'./ConstantProperty',
'./CorridorGraphics',
'./DataSource',
'./EntityCluster',
'./EntityCollection',
Expand Down Expand Up @@ -50,7 +49,6 @@ define([
ColorMaterialProperty,
ConstantPositionProperty,
ConstantProperty,
CorridorGraphics,
DataSource,
EntityCluster,
EntityCollection,
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 9 additions & 10 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ define([
'../ThirdParty/zip',
'./BillboardGraphics',
'./CompositePositionProperty',
'./CorridorGraphics',
'./DataSource',
'./DataSourceClock',
'./Entity',
Expand Down Expand Up @@ -108,7 +107,6 @@ define([
zip,
BillboardGraphics,
CompositePositionProperty,
CorridorGraphics,
DataSource,
DataSourceClock,
Entity,
Expand Down Expand Up @@ -1268,17 +1266,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;
polylineGraphics.zIndex = zIndex;
} else {
if (defined(zIndex)) {
oneTimeWarning('kml-gx:drawOrder', 'KML - gx:drawOrder is not supported in LineStrings when clampToGround is false');
Expand Down
36 changes: 36 additions & 0 deletions Specs/DataSources/CzmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand Down
14 changes: 8 additions & 6 deletions Specs/DataSources/GeoJsonDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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);
}
});
});
Expand Down
16 changes: 8 additions & 8 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ defineSuite([
'Core/ClockStep',
'Core/Color',
'Core/combine',
'Core/DefaultProxy',
'Core/Ellipsoid',
'Core/Event',
'Core/HeadingPitchRange',
Expand Down Expand Up @@ -46,7 +45,6 @@ defineSuite([
ClockStep,
Color,
combine,
DefaultProxy,
Ellipsoid,
Event,
HeadingPitchRange,
Expand Down Expand Up @@ -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 = '<?xml version="1.0" encoding="UTF-8"?>\
<Placemark>\
<Style>\
Expand All @@ -4441,12 +4439,13 @@ defineSuite([
var clampToGroundOptions = combine(options, { clampToGround : true });
return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), clampToGroundOptions).then(function(dataSource) {
var entity = dataSource.entities.values[0];
expect(entity.corridor).toBeDefined();
expect(entity.corridor.material).toBeInstanceOf(ColorMaterialProperty);
expect(entity.polyline).toBeDefined();
expect(entity.polyline.clampToGround.getValue()).toEqual(true);
expect(entity.polyline.material).toBeInstanceOf(ColorMaterialProperty);
});
});

it('when a LineString is clamped to ground and tesselated with z draworder, entity has a corridor geometry and ColorProperty', function() {
it('when a LineString is clamped to ground and tesselated with z draworder, entity has a polyline geometry and ColorProperty', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Document xmlns="http://www.opengis.net/kml/2.2"\
xmlns:gx="http://www.google.com/kml/ext/2.2">\
Expand All @@ -4469,8 +4468,9 @@ defineSuite([
var clampToGroundOptions = combine(options, { clampToGround : true });
return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), clampToGroundOptions).then(function(dataSource) {
var entity = dataSource.entities.values[0];
expect(entity.corridor).toBeDefined();
expect(entity.corridor.zIndex.getValue()).toBe(2);
expect(entity.polyline).toBeDefined();
expect(entity.polyline.clampToGround.getValue()).toEqual(true);
expect(entity.polyline.zIndex.getValue()).toBe(2);
});
});

Expand Down