/*data.rightTops
data.leftBottom 经纬度点
*/
var p3 = Cartesian3.fromDegrees(data.rightTop.split(',')[0]*1,data.rightTop.split(',')[1]*1,15) //转化成Cartesian3形式
var p0 = Cartesian3.fromDegrees(data.leftBottom.split(',')[0]*1,data.leftBottom.split(',')[1]*1,15)
var aa4 = Cartesian3.midpoint(p0,p3,new Cartesian3()) //计算两点之间的中点
// 定位以及添加墙体
let center = Cartographic.fromCartesian(aa4) //将经纬度转换为弧度坐标系
this.viewer.camera.flyTo({ //相机定位
destination: Cartesian3.fromRadians(center.longitude,center.latitude,2000), //属性描述
duration: 0,
complete: function () { //绘制的位置
let wallps = data.leftTop+','+data.leftBottom+','+data.rightBottom+','+data.rightTop+','+data.leftTop
m.createWall(wallps.split(',').map(Number),objectsToExclude)
}
});
}
//墙体
createWall= function (ps,objectsToExclude) {
let points = Cartesian3.fromDegreesArray(ps)
let minimumHeights = [];
var maximumHeights = [];
let wallHeight = 20;// 墙体高
var positions = [];
// 插值100个点,点越多模拟越精确,但是效率会低
var count = 100;
for (var i = 0; i < count; i++) {
var cart = new Cartesian3;
if(i<25){
cart = Cartesian3.lerp(points[0], points[1], i / 25, new Cartesian3()); //线条绘制
}else if(i<50){
cart = Cartesian3.lerp(points[1], points[2], (i-25) / 25, new Cartesian3());
}else if(i<75){
cart = Cartesian3.lerp(points[2], points[3], (i-50) / 25, new Cartesian3());
}else {
cart = Cartesian3.lerp(points[3], points[4], (i-75) / 25, new Cartesian3());
}
positions.push(cart);
}
positions.push(points[0]);
let viewer = this.viewer
let cartographicPS = []
positions.forEach((p) => {
cartographicPS.push(Cartographic.fromCartesian(p))
})
var promise = sampleTerrainMostDetailed(viewer.terrainProvider, cartographicPS);
when(promise, function(updatedPositions) {
updatedPositions.forEach((o) => {
minimumHeights.push(o.height);
maximumHeights.push(o.height + wallHeight)
})
viewer.wall = viewer.entities.add({
wall: {
positions: positions,
maximumHeights : maximumHeights,
minimumHeights : minimumHeights,
material : new CheckerboardMaterialProperty({
evenColor:Color.CYAN.withAlpha(0.2),
oddColor:Color.WHITE.withAlpha(0.2),
repeat : new Cartesian2(500.0, 15.0)
})
}
});
});
}
cesiuim+vue -------墙体绘制
最新推荐文章于 2024-05-29 14:16:59 发布