cesium加载点线面和模型。
1.绘制点
使用entity
// 点
var addPoint = {
id: 'point',
name: '点',
show: true, //显示.
position: Cesium.Cartesian3.fromDegrees(118, 32, 0.0),
point: {
color: Cesium.Color.BLUE, //颜色
pixelSize: 5, //点大小
}
}
使用primitive
// Create a pointPrimitive collection with two points
const points = scene.primitives.add(new Cesium.PointPrimitiveCollection());
points.add({
position : new Cesium.Cartesian3(1.0, 2.0, 3.0),
color : Cesium.Color.YELLOW
});
points.add({
position : new Cesium.Cartesian3(4.0, 5.0, 6.0),
color : Cesium.Color.CYAN
});
2.绘制线
使用entity
// 线
var addLine = {
id: 'line',
name: '线',
show: true, //显示
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([108.0, 31.0, 100.0, 36.0, 105.0, 39.0]),
width: 1, //线条粗细
material: Cesium.Color.RED, //线条材质
//clampToGround: true
}
}
使用Primitive
//绘制线
//定义几何形状
var polyline = new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray([
108.0, 31.0,
100.0, 36.0,
105.0, 39.0
]),
width: 2.0
})
});
//定义外观
var polylineAppearance = new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType('Color')
})
//创建Primitive
var addPolylineGeometry = new Cesium.Primitive({
geometryInstances: polyline,
appearance: polylineAppearance
})
3.绘制面
entity
//面
var addPolygon = {
id: 'polygon',
name: '面',
show: true,
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([118, 30, 119, 32, 116, 32, 116, 30]),
//outline: false,
material: Cesium.Color.RED.withAlpha(0.4),
}
}
使用Primitive
//绘制面
//定义几何形状
var polygon = new Cesium.GeometryInstance({
geometry: new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(
Cesium.Cartesian3.fromDegreesArray([
108, 45,
109, 48,
104, 48,
103, 45
])
)
})
});
//定义外观
var polygonAppearance = new Cesium.MaterialAppearance({
material: Cesium.Material.fromType('Dot'),
})
//创建Primitive
var addPolygonGeometry = new Cesium.Primitive({
geometryInstances: polygon,
appearance: polygonAppearance
})