Skip to content

方量分析

JavaScript
//1).初始化方量分析
var cutfill = new LSGlobe.LSCutFill(viewer);
var nodeMesh, tileset; //实景三维对象
var poinsTemp = []; //用于保存绘制的点
//分析对象
var tempDataSource;
//用于存储方量分析辅助面
var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("tempDataSource"));
promise.then(function(dataSource) {
    tempDataSource = dataSource;
}).otherwise(function(error) {

});

//2).点击收集构成放量分析的面
//注意:绘制方量分析时点必须点在模型上
//初始化鼠标事件
var oCutFillHandler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
oCutFillHandler.setInputAction(function(movement) {
    var cartesian = scene.pickGlobe(movement.position);
    poinsTemp.push(cartesian);

    var CurrentTileSet = whichTileset(currentClickLon, currentClickLat);
    //判断点是否在模型上函数和压平获取压平对象相同
    //可视域分析点必须在模型上
    if (CurrentTileSet.length < 1) {
        alert("请在模型上点击");
        //如果点没有点在模型上不在向下走
        return;
    } else {

        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("20191225");
            tempDataSource.entities.add({
                id: "20191225",
                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);

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);

//3).开始分析
function getProgress() {
    nodeMesh = tileset.NodeMesh;
}
modelAnalysis(oHeight);
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();
}

Released under the MIT License.