实体常用的属性主要有如下:
id : 对象的唯一标识符。如果没有提供,则生成GUID。
name : 向用户显示的可读名称,名称可不必唯一。
show : 是否显示实体对象及其子项。
description : 实体的HTML描述。
position : 实体的位置。
billboard : 与此实体关联的广告牌。
label : 与实体关联的标签对象。
point : 与实体关联的点对象。
polygon : 与实体关联的多边形对象。
polyline : 与实体关联的折线对象。
目录
一、点point实体
const point = viewer.entities.add({ // 点
position: Cesium.Cartesian3.fromDegrees(117,32,5000),
name: "point",
point: {
color:Cesium.Color.RED,
pixelSize:30
}
});
二、线实体
const line = viewer.entities.add({ // 线
name: "line",
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([-75, 35, -125, 35]),
width: 5,
material: Cesium.Color.RED,
clampToGround: true,
},
});
三、面实体
const polygon = viewer.entities.add({ // 面
name: "polygon",
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
-115.0,
37.0,
-115.0,
32.0,
-107.0,
33.0,
-102.0,
31.0,
-102.0,
35.0,
]),
material: Cesium.Color.RED,
},
});
四、文字label实体(渲染文字注记)
在实体上添加一个label属性即可。
// 添加广告牌实体
var enetity = viewer.entities.add({
name: '标点',
position: Cesium.Cartesian3.fromDegrees(113.122717,23.028762,10),
label: { //文字标签
text : '测试名称',
font : '14pt Source Han Sans CN', //字体样式
fillColor:Cesium.Color.BLACK, //字体颜色
backgroundColor:Cesium.Color.AQUA, //背景颜色
showBackground:true, //是否显示背景颜色
style: Cesium.LabelStyle.FILL, //label样式
outlineWidth : 2,
verticalOrigin : Cesium.VerticalOrigin.CENTER,//垂直位置
horizontalOrigin :Cesium.HorizontalOrigin.LEFT,//水平位置
pixelOffset:new Cesium.Cartesian2(10,0) //偏移
},
billboard:{
image: '/images/normal_point_128.png',
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
scale: 0.5,
}
})
五、广告墙billboard实体(渲染图片)
// 添加广告牌实体
var enetity = viewer.entities.add({
name: '标点',
position: Cesium.Cartesian3.fromDegrees(113.122717,23.028762,10),
billboard:{
image: '/images/normal_point_128.png',
// 图像地址,URI或Canvas的属性
// 设置颜色和透明度
color: Cesium.Color.WHITE.withAlpha(0.8),
// 高度(以像素为单位)
height: 25,
// 宽度(以像素为单位)
width: 20,
// 逆时针旋转
rotation: 0,
// 大小是否以米为单位
sizeInMeters: false,
// 相对于坐标的垂直位置
verticalOrigin: Cesium.VerticalOrigin.CENTER,
// 相对于坐标的水平位置
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// 该属性指定标签在屏幕空间中距此标签原点的像素偏移量
pixelOffset: new Cesium.Cartesian2(0, -10),
// 应用于图像的统一比例。比例大于会1.0放大标签,而比例小于会1.0缩小标签。
scale: 1.0,
// 是否显示
show: true
}
})
六、description描述信息
1、简单的描述信息
var wyoming=viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-75.1647, 39.9522),
name:'我是infobox的标题',
description:'我是infobox的内容',
label: {
text: "我是标签",
font: "24px Helvetica",
fillColor: Cesium.Color.SKYBLUE,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
backgroundColor:Cesium.Color.PINK,
showBackground:true,
},
});
2、复杂的描述信息,带HTML设置样式的
wyoming.description = '\
<img\
width="50%"\
style="float:left; margin: 0 1em 1em 0;"\
src="//cesiumjs.org/images/2015/02-02/Flag_of_Wyoming.svg"/>\
<p>\
Wyoming is a state in the mountain region of the Western \
United States.\
</p>\
<p>\
Wyoming is the 10th most extensive, but the least populous \
and the second least densely populated of the 50 United \
States. The western two thirds of the state is covered mostly \
with the mountain ranges and rangelands in the foothills of \
the eastern Rocky Mountains, while the eastern third of the \
state is high elevation prairie known as the High Plains. \
Cheyenne is the capital and the most populous city in Wyoming, \
with a population estimate of 62,448 in 2013.\
</p>\
<p>\
Source: \
<a style="color: WHITE"\
target="_blank"\
href="http://en.wikipedia.org/wiki/Wyoming">Wikpedia</a>\
</p>';