Skip to content

Commit 6d55550

Browse files
authored
Merge pull request #6689 from likangning93/polylinesOnTerrain-entity
support for polylines on terrain via entity API
2 parents 6f66dbf + 16c2f0c commit 6d55550

17 files changed

+1468
-88
lines changed

Apps/Sandcastle/gallery/Ground Clamping.html

+30
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,36 @@
218218
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
219219
});
220220
}
221+
}, {
222+
text : 'Draw polyline on terrain',
223+
onselect : function() {
224+
225+
if (!Cesium.Entity.supportsPolylinesOnTerrain(viewer.scene)) {
226+
console.log('Polylines on terrain are not supported on this platform');
227+
}
228+
229+
viewer.entities.add({
230+
polyline : {
231+
positions : Cesium.Cartesian3.fromDegreesArray([
232+
86.953793, 27.928257,
233+
86.953793, 27.988257,
234+
86.896497, 27.988257
235+
]),
236+
clampToGround : true,
237+
width : 5,
238+
material : new Cesium.PolylineOutlineMaterialProperty({
239+
color : Cesium.Color.ORANGE,
240+
outlineWidth : 2,
241+
outlineColor : Cesium.Color.BLACK
242+
})
243+
}
244+
});
245+
246+
var target = new Cesium.Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
247+
var offset = new Cesium.Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
248+
viewer.camera.lookAt(target, offset);
249+
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
250+
}
221251
}], 'zoomButtons');
222252

223253
Sandcastle.reset = function () {

Apps/Sandcastle/gallery/Polyline.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
var viewer = new Cesium.Viewer('cesiumContainer');
3131

3232
var redLine = viewer.entities.add({
33-
name : 'Red line on the surface',
33+
name : 'Red line on terrain',
3434
polyline : {
3535
positions : Cesium.Cartesian3.fromDegreesArray([-75, 35,
3636
-125, 35]),
3737
width : 5,
38-
material : Cesium.Color.RED
38+
material : Cesium.Color.RED,
39+
clampToGround : true
3940
}
4041
});
4142

Apps/Sandcastle/gallery/Z-Indexing Geometry.html

+31
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
var viewer = new Cesium.Viewer('cesiumContainer');
3333

3434
viewer.entities.add({
35+
id : 'Red rectangle, zIndex 1',
3536
rectangle : {
3637
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 20.0, -100.5, 30.0),
3738
material : Cesium.Color.RED,
@@ -40,6 +41,7 @@
4041
});
4142

4243
viewer.entities.add({
44+
id : 'Textured rectangle, zIndex 2',
4345
rectangle : {
4446
coordinates : Cesium.Rectangle.fromDegrees(-112.0, 25.0, -102.5, 35.0),
4547
material : '../images/Cesium_Logo_Color.jpg',
@@ -48,6 +50,7 @@
4850
});
4951

5052
viewer.entities.add({
53+
id : 'Blue rectangle, zIndex 3',
5154
rectangle : {
5255
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 31.0, -100.5, 41.0),
5356
material : Cesium.Color.BLUE,
@@ -56,6 +59,7 @@
5659
});
5760

5861
viewer.entities.add({
62+
id : 'Textured rectangle, zIndex 3',
5963
rectangle : {
6064
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 20.0, -90.0, 30.0),
6165
material : '../images/Cesium_Logo_Color.jpg',
@@ -64,6 +68,7 @@
6468
});
6569

6670
viewer.entities.add({
71+
id : 'Green rectangle, zIndex 2',
6772
rectangle : {
6873
coordinates : Cesium.Rectangle.fromDegrees(-97.5, 25.0, -88.0, 35.0),
6974
material : Cesium.Color.GREEN,
@@ -72,13 +77,39 @@
7277
});
7378

7479
viewer.entities.add({
80+
id : 'Blue rectangle, zIndex 1',
7581
rectangle : {
7682
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 31.0, -90.0, 41.0),
7783
material : Cesium.Color.BLUE,
7884
zIndex: 1
7985
}
8086
});
8187

88+
if (!Cesium.Entity.supportsPolylinesOnTerrain(viewer.scene)) {
89+
console.log('Polylines on terrain are not supported on this platform, Z-index will be ignored');
90+
}
91+
92+
if (!Cesium.Entity.supportsMaterialsforEntitiesOnTerrain(viewer.scene)) {
93+
console.log('Textured materials on terrain polygons are not supported on this platform, Z-index will be ignored');
94+
}
95+
96+
viewer.entities.add({
97+
id : 'Polyline, zIndex 2',
98+
polyline : {
99+
positions : Cesium.Cartesian3.fromDegreesArray([
100+
-120.0, 22.0,
101+
-80.0, 22.0
102+
]),
103+
width : 8.0,
104+
material : new Cesium.PolylineGlowMaterialProperty({
105+
glowPower : 0.2,
106+
color : Cesium.Color.BLUE
107+
}),
108+
zIndex: 2,
109+
clampToGround : true
110+
}
111+
});
112+
82113
viewer.zoomTo(viewer.entities);
83114
//Sandcastle_End
84115
Sandcastle.finishedLoading();
2.29 KB
Loading

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ Change Log
1010
##### Additions :tada:
1111
* `PostProcessStage` has a `selectedFeatures` property which is an array of primitives used for selectively applying a post-process stage. In the fragment shader, use the function `bool czm_selected(vec2 textureCoordinates` to determine whether or not the stage should be applied at that fragment.
1212
* The black-and-white and silhouette stages have per-feature support.
13+
* Added support for Polylines on Terrain via the `Entity` API [#6689](https://github.com/AnalyticalGraphicsInc/cesium/pull/6689)
14+
* Use the `clampToGround` option for `PolylineGraphics`.
15+
* Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`), otherwise `clampToGround` will be ignored.
16+
* Added `Entity.supportsPolylinesOnTerrain` for checking if the current platform supports `clampToGround`.
1317
* Added `GroundPolylinePrimitive` and `GroundPolylineGeometry` for rendering polylines on terrain via the `Primitive` API. [#6615](https://github.com/AnalyticalGraphicsInc/cesium/pull/6615)
18+
* Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`).
19+
* Use `GroundPolylinePrimitive.isSupported` to check for support.
1420

1521
##### Fixes :wrench:
1622
* Fixed a bug causing crashes with custom vertex attributes on `Geometry` crossing the IDL. Attributes will be barycentrically interpolated. [#6644](https://github.com/AnalyticalGraphicsInc/cesium/pull/6644)

Source/DataSources/DataSourceDisplay.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ define([
130130
new ModelVisualizer(scene, entities),
131131
new PointVisualizer(entityCluster, entities),
132132
new PathVisualizer(scene, entities),
133-
new PolylineVisualizer(scene, entities)];
133+
new PolylineVisualizer(scene, entities, dataSource._groundPrimitives)];
134134
};
135135

136136
defineProperties(DataSourceDisplay.prototype, {

Source/DataSources/Entity.js

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ define([
1212
'../Core/Quaternion',
1313
'../Core/Transforms',
1414
'../Scene/GroundPrimitive',
15+
'../Scene/GroundPolylinePrimitive',
1516
'./BillboardGraphics',
1617
'./BoxGraphics',
1718
'./ConstantPositionProperty',
@@ -47,6 +48,7 @@ define([
4748
Quaternion,
4849
Transforms,
4950
GroundPrimitive,
51+
GroundPolylinePrimitive,
5052
BillboardGraphics,
5153
BoxGraphics,
5254
ConstantPositionProperty,
@@ -631,5 +633,17 @@ define([
631633
return GroundPrimitive.supportsMaterials(scene);
632634
};
633635

636+
/**
637+
* Checks if the given Scene supports polylines clamped to the ground..
638+
* If this feature is not supported, Entities with PolylineGraphics will be rendered with vertices at
639+
* the provided heights and using the `followSurface` parameter instead of clamped to the ground.
640+
*
641+
* @param {Scene} scene The current scene.
642+
* @returns {Boolean} Whether or not the current scene supports Polylines on Terrain.
643+
*/
644+
Entity.supportsPolylinesOnTerrain = function(scene) {
645+
return GroundPolylinePrimitive.isSupported(scene);
646+
};
647+
634648
return Entity;
635649
});

0 commit comments

Comments
 (0)