tubeAnalysis.html 8.7 KB
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>淹没分析</title>

    <script src="/static/js/jquery-3.4.1.min.js"></script>
    <script src="/static/js/JavaScript.js"></script>
    <script src="/static/js/popupJS.js"></script>

    <script src="/static/js/layui/layui.js"></script>
    <link rel="stylesheet" href="/static/js/layui/css/layui.css">

    <link rel="stylesheet" href="/static/css/analysis.css">
</head>
<style>
    .tiaojian .short-search-btn {
        width: 100%;
    }
</style>



    <body marginwidth="0" marginheight="0">
        <div id="mainDiv" class="dialog tiaojian">
            <h1 class="title" onmousedown="MouseDown(event)" onmouseup="MouseUp(event)" onmouseout="MouseUp(event)">
                爆管分析<i class="guanbibtn" onclick="Close()">X</i>
            </h1>
            <form class="main">
                <div class="filter">
                    <div style="padding:20px;">
                        <button type="button" class="short-search-btn" onclick="selectTube()">选择管线</button>
                    </div>
                </div>
            </form>
        </div>
    </body>


<script language="JavaScript">

    let pointLayerName = "dx_point";//管点图层的名称(在TE Pro显示的名称)
    let pipeLayerKey = "pipe";//管线图层的名称的关键字
    let startField = "起点点号";//管线图层中一条管线中标志着起点点号的字段
    let endField = "连接方向";//管线图层中一条管线中标志着终点点号的字段
    let pointLayerDot = "图上点号";//管点图层中用于标志点号的字段
    let pointLayerDotType = "特征";//管点图层中用于标志是否是指定类型的字段
    let pointLayerSelect = "阀门";//管点图层中所想要的指定类型名称

    function selectTube() {

        let sgworld = new CreateSGObj();
        sgworld.Window.HideMessageBarText();//隐藏下面的信息栏
        //鼠标左键单击管线,选中管线(如何限定点击的对象时想要查询的对象类型,比如如何确定鼠标点击的是管线而不是设备)
        sgworld.AttachEvent("OnLButtonClicked", SelectPipeLButtonEvent);
        //sgworld.AttachEvent("OnLButtonDown", SelectPipeLButtonEvent);
        sgworld.Window.SetInputMode(1, "", true);

    }
    /**
     * 绑定鼠标左键单击事件的监听函数
     * @param Flag
     * @param X
     * @param Y
     */
    function SelectPipeLButtonEvent(Flag, X, Y) {
        var SGWorld = new CreateSGObj();

        //将屏幕的像素坐标转化为三位中的世界坐标
        var wpi = SGWorld.Window.PixelToWorld(X, Y, -1);//最后一个可以设置点击的对象是什么类型的 -1为默认值
        if (null == wpi) {
            return false;
        }
        alert("点击选中的对象ID为:" + wpi.ObjectID + "\n 对象的类型是:" + wpi.Type);
        let feature = SGWorld.ProjectTree.GetObject(wpi.ObjectID);//获取点击的对象
        //这里需要判断选中的是不是管线
        if (feature.ObjectType === 33)//OT_FEATURE = 33
        {
            //获取父图层判断是否是管线图层
            //如果是管线图层的话,获取该管线的起点点号和终点点号
            let layerName = SGWorld.ProjectTree.GetItemName(feature.LayerID);
            if (layerName.indexOf(pipeLayerKey) >= 0) {
                let startP = feature.FeatureAttributes.GetFeatureAttribute(startField).Value;
                let endP = feature.FeatureAttributes.GetFeatureAttribute(endField).Value;
                //获取所有的上游的阀门点号
                alert("startP:" + startP + ",endP:" + endP);
                //判断上游点号是否是阀门,如果是阀门,则直接将该阀门标记,否则遍历查询
                if (judgePointIsValve(startP)) {
                    alert("上游的阀门点号为ddd" + startP);
                } else {
                    let AA = getUpOrDownStreamValve(startP, feature.LayerID, endField, startField);
                    for (var i = 0; i < AA.length; i++) {
                        alert("上游的阀门点号为" + AA[i]);
                    }
                }
                //判断下游点号是否是阀门,如果是阀门,则直接将该阀门标记,否则遍历查询
                if (judgePointIsValve(endP)) {
                    alert("下游的阀门点号为ddd" + endP);
                } else {
                    let BB = getUpOrDownStreamValve(endP, feature.LayerID, startField, endField);
                    for (var i = 0; i < BB.length; i++) {
                        alert("下游的阀门点号为" + BB[i]);
                    }
                    if (BB.length === 0) {
                        alert("下游无阀门!");
                    }
                }
            }
        }
    }

    /**
     * 根据传入的信息获取管线上游或下游的阀门
     * @param point 已知的管线管点
     * @param layerID 管线图层的ID
     * @param knownName 已知管点在被选中的管线上是作为起点还是终点
     * @param unknownName 想要获取的管线管点的类型(起点或终点)
     */
    function getUpOrDownStreamValve(point, layerID, knownName, unknownName) {
        //alert("运行函数getUpOrDownStreamValve");
        let pointArr = [];
        let arr = getUpOrDownStreamByPoint(point, layerID, knownName, unknownName);
        if (arr.length > 0) {
            //遍历点号,判断是否是阀门,如果不是阀门,则继续向上遍历查找上有点号,如果是,则传入数组中
            for (var i = 0; i < arr.length; i++) {
                if (judgePointIsValve(arr[i])) {
                    pointArr.push(arr[i]);
                } else {
                    pointArr.push.apply(pointArr, getUpOrDownStreamValve(arr[i], layerID, knownName, unknownName));
                }
            }
        } else {
            //alert("Error:" + point + "上游的点位的数量为" + arr.length);
        }
        return pointArr;
    }

    /**
     * 根据点号获取上游或下游点号数组(即根据提供的点号遍历图层获取连接方向是该点号的要素)
     * aq----A----az(bq)----B-----bz  若A,B代表两根管线,aq和bq分别为AB的起始端点,az和bz分别为AB的终结端点
     * 求上游的阀门,那么knownName就是选中管线B的起始端点bq,上游管线A的终结端点,unknownName是上游管线A的起始端点aq
     * 求下游的阀门,那么knownName就是选中管线A的终结端点az,下游管线B的起始端点,unknownName是下游管线B的终结端点bz
     * @param point 已知的点号
     * @param layerID 管线数据存在的图层ID
     * @param knownName 已知的端点
     * @param unknownName 未知的端点
     */
    function getUpOrDownStreamByPoint(point, layerID, knownName, unknownName) {
        let sgworld = new CreateSGObj();
        let pointArray = [];
        let layer = sgworld.ProjectTree.GetObject(layerID);
        layer.Filter = "'" + knownName + "'='" + point + "'";
        layer.Streaming = 0;
        layer.Refresh();
        let features = layer.FeatureGroups(0).GetCurrentFeatures();
        for (var i = 0; i < features.Count; i++) {
            let feature = features.Item(i);
            pointArray.push(feature.FeatureAttributes.GetFeatureAttribute(unknownName).Value);
            //alert(point + "的查询点号为" + feature.FeatureAttributes.GetFeatureAttribute(unknownName).Value);
        }
        layer.Filter = "";
        layer.Refresh();
        return pointArray;
    }

    /**
     * judgePointIsValve() 判断传入的point点是否是管点图层中的阀门
     * @param point 需要传入的待验证的点号
     */
    function judgePointIsValve(point) {
        //alert(point);
        let sgworld = new CreateSGObj();
        let pointLayerID = sgworld.ProjectTree.FindItem(pointLayerName);
        let pointLayer = sgworld.ProjectTree.GetObject(pointLayerID);

        pointLayer.Filter = "'" + pointLayerDot + "'='" + point + "'";
        pointLayer.Streaming = 0;
        pointLayer.Refresh();
        let features = pointLayer.FeatureGroups(0).GetCurrentFeatures();

        for (var i = 0; i < features.Count; i++) {
            let feature = features.Item(i);
            if (feature.FeatureAttributes.GetFeatureAttribute(pointLayerDotType).Value === pointLayerSelect) {
                //return feature.ID;//返回要素的ID
                pointLayer.Filter = "";
                pointLayer.Refresh();
                return true;
            }
        }
        //return null;//若没有
        pointLayer.Filter = "";
        pointLayer.Refresh();
        return false;
    }

</script>


</html>