1. 使用entities创建
var viewer = new Cesium.Viewer("cesiumContainer");
let a = Cesium.Cartesian3.fromDegrees(116.445663,39.984186)
let b = Cesium.Cartesian3.fromDegrees(116.611238,40.001875)
let c = Cesium.Cartesian3.fromDegreesArray([116.445663,39.984186,116.611238,40.001875])
var redLine = viewer.entities.add({
name: "Red line on terrain",
position:a,
polyline: {
show:false,
positions: c,
width: 5,
material: Cesium.Color.RED,
clampToGround: true,
},
label:{
text:"测试"
}
});
//-75, 35, -125, 35, -125, 37,-75, 37
setTimeout(()=>{
redLine.polyline.show=true
},2000)
console.log(c)
console.log(Cesium.Cartesian3.fromDegreesArray([-75, 35, -125, 35, -125, 37,-75, 37]))
viewer.zoomTo(viewer.entities);
2. 使用czml创建
this.ljCzml = new Czml({
name: 'ljCzml',
isHeight: false
})
paths.forEach((_item,_idx)=>{
if(_idx<item.path.length-1){
let start = this.LngLatPoint.toGPSPoint(_item.lng, _item.lat)
let end =this.LngLatPoint.toGPSPoint(item.path[_idx+1].lng, item.path[_idx+1].lat)
//绘制线
let obj = {
id:'line_'+_idx,
name:'redline_'+_idx,
polyline : {
positions : {
cartographicDegrees : [start.lng,start.lat, 0, end.lng,end.lat, 0]
},
material: {
solidColor: {
color: {
rgba: [255, 0, 0, 255],
},
},
},
width :4,
clampToGround : true,
}
}//obj结束
czml.push(obj)
}//if结束
})//forEach结束
this.ljCzml.load(czml)
本周疑问,czml和entities 还是不太理解,待深入学习