『Cesium 基础』Entity 样式设置
webgis 2020-01-02
cesium
三维
# material 材质
颜色 通过给 material 赋值 color 对象值既可以
//内置颜色 polygon.material: Cesium.Color.RED.withAlpha(0.5), //css颜色 //cssColor:值可以是 #ffccdd, rgb(255,255,255),rgb(255,0,255,0.5) polygon.material: Cesium.Color.fromCssColorString(cssColor, result)1
2
3
4
5
6通过 ColorMaterialProperty设置动态的颜色

// 创建 colorProperty var colorProperty = new Cesium.SampledProperty(Cesium.Color);1
2polygon.material: new Cesium.ColorMaterialProperty(colorProperty),
1贴图:直接设置贴图图片路径即可
polygon.material:'../img/cesium/c1_3.jpg'1
# 填充和边框
fill:false,//默认true
outline:true,//默认false,如果需要设置边框颜色需要开启设置为true
outlineColor: Cesium.Color.fromCssColorString("rgba(0,0,255,.5)"),
outlineWidth:100
1
2
3
4
2
3
4
# 高度和实体垂直拉伸
height: 200000.0,//离地高度
extrudedHeight: 400000.0, //实体高度 = extrudedHeight - height
1
2
2
# 完整代码
var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(...lnglat),
polygon: {
hierarchy: {
positions: Cesium.Cartesian3.fromDegreesArray([
103.842575,
30.795808,
104.394638,
30.728545,
104.394638,
30.728545,
103.626969,
30.584419,
]),
},
material: Cesium.Color.RED.withAlpha(0.5),
// material: new Cesium.ColorMaterialProperty(colorProperty),
// material:'..//images/cesium/cesium/c1_3.jpg',
height: 2000.0, //离地高度
extrudedHeight: 4000.0, //实体高度 = extrudedHeight - height
// fill:false,
// outline:true,
// outlineColor: Cesium.Color.fromCssColorString("rgba(0,0,255,.5)"),
// outlineWidth:100
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 初始化补充
# 设置初始化范围
//Rectangle(west, south, east, north)
//设置初始化中国范围
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(...[100, 10, 120, 70]);
1
2
3
2
3