填挖方分析
填挖方分析是一种用于计算工程施工过程中土方量的方法,通过比较设计地形和现状地形的差异来计算需要填充或挖掘的土方量。这种方法在建筑施工、设计领域有着广泛的应用,直接影响工程费用概算以及方案优选。
初始化填挖方分析
JavaScript
var cutfill = new LSGlobe.LSCutFill(viewer);
var poinsTemp = []; //用于保存绘制的点
//分析面容器
var tempDataSource;
//用于存储填挖方分析辅助面
var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("tempDataSource"));
promise.then(function(dataSource) {
tempDataSource = dataSource;
}).otherwise(function(error) {
console.log(error)
});
点击收集构成填挖方的分析的面
此处使用鼠标事件,点击收集构成填挖方的分析的面,并绘制面。也可以使用 标绘插件直接绘制形成参考面。
JavaScript
//初始化鼠标事件
var oCutFillHandler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
oCutFillHandler.setInputAction(function(movement) {
var cartesian = scene.pickGlobe(movement.position);
poinsTemp.push(cartesian);
//判断点是否在模型上函数和压平获取压平对象相同
//可视域分析点必须在模型上
tempDataSource.entities.add({
position: cartesian,
clampToGround: true,
point: {
pixelSize: 3,
color: LSGlobe.Color.YELLOW,
perPositionHeight: false,
disableDepthTestDistance: 1000000000 //优先级
}
});
if (poinsTemp.length >= 2) {
tempDataSource.entities.removeById("2025");
tempDataSource.entities.add({
id: "2025",
name: 'line on the surface',
polyline: {
positions: poinsTemp,
width: 2,
material: LSGlobe.Color.fromCssColorString("rgba(0,186,255,0.5)"),
depthFailMaterial: new LSGlobe.PolylineDashMaterialProperty({
color: LSGlobe.Color.fromCssColorString("rgba(0,186,255,0.5)")
}),
disableDepthTestDistance: 1000000000 //优先级
}
});
}
},
LSGlobe.ScreenSpaceEventType.LEFT_CLICK);
// 面的点高度统一
function ChangePolygonPosition(type, oPositions) {
var oValuePoint = [];
//点集合设置为统一平均高度
var heightCollection = 0;
for (var a = 0; a < oPositions.length; a++) {
var cartographic = LSGlobe.Cartographic.fromCartesian(oPositions[a]);
heightCollection = heightCollection + cartographic.height;
}
var Height = heightCollection / oPositions.length;
for (var a = 0; a < oPositions.length; a++) {
var CurrentPoint = oPositions[a];
var cartographic = LSGlobe.Cartographic.fromCartesian(CurrentPoint);
var currentClickLon = LSGlobe.Math.toDegrees(cartographic.longitude);
var currentClickLat = LSGlobe.Math.toDegrees(cartographic.latitude);
oValuePoint.push(currentClickLon);
oValuePoint.push(currentClickLat);
oValuePoint.push(Height);
}
return oValuePoint;
}
oCutFillHandler.setInputAction(function(movement) {
//生成面
var oValuePoint = ChangePolygonPosition(poinsTemp);
for (var i = 2; i < oValuePoint.length; i = i + 3) {
oValuePoint[i] = oHeight;
}
tempDataSource.entities.removeAll();
//该面是辅助填挖方分析结果的面,最后填挖方分析的高度和范围是该面显示的高度和范围
tempDataSource.entities.add({
name: '填挖方分析辅助面',
id: new Date().getTime(),
polygon: {
hierarchy: LSGlobe.Cartesian3.fromDegreesArrayHeights(oValuePoint),
material: new LSGlobe.Color(0.5, 1.0, 1.0, 0.7),
fill: true,
outline: true,
outlineColor: LSGlobe.Color.YELLOW,
perPositionHeight: true
}
});
},
LSGlobe.ScreenSpaceEventType.RIGHT_CLICK);
开始分析
JavaScript
function progress() {
//分析结果
//填方体积
var fillvolume = cutfill.fillVolume.toFixed(3);
//挖方体积
var cutvolume = cutfill.cutVolume.toFixed(3);
console.log('填方体积:' + fillvolume + '立方米');
console.log('挖方体积:' + cutvolume + '立方米');
}
// 基准面为10计算填挖方
modelAnalysis(10);
function modelAnalysis(oHeight) {
cutfill.clear();
cutfill.completeEvent.addEventListener(progress);
var cartographic = LSGlobe.Cartographic.fromCartesian(poinsTemp[0]);
if (oHeight) {
cutfill.zFactor = height;
} else {
cutfill.zFactor = cartographic.height;
}
//分析的面对象
var Mypolygon = new LSGlobe.PolygonGeometry({
polygonHierarchy: new LSGlobe.PolygonHierarchy(poinsTemp),
perPositionHeight: true
});
cutfill.polygon = Mypolygon;
//采样间隔
cutfill.sampleGap = interval;
//执行分析
cutfill.apply();
}