floodAnalysis.html 5.76 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">
    <style>
        .layui-form-item {
            margin-top: 20px;
        }

        /* 输入框的样式 */
        .layui-input {
            height: 30px;
        }

        .layui-input-block {
            margin-left: 110px;
            margin-right: 20px;
            padding-top: 4px;
        }
    </style>
</head>
    <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" label-width="70px" label-position="left">
                <div class="filter">
                    <h1 class="filter-title">参数设置</h1>
                    <div class="box">
                        <div class="layui-form-item">
                            <label class="layui-form-label">水面高度</label>
                            <div class="layui-input-block">
                                <input type="text" name="surfaceHeight" id="surfaceHeight" lay-verify="number"
                                    autocomplete="off" value="5.0" class="layui-input" onchange="heightChange()">
                            </div>
                        </div>
                    </div>
                    <div style="padding:20px;">
                        <button type="button" class="short-search-btn" onclick="startDrawWater()">绘制水面</button>
                        <button type="button" class="short-search-btn" onclick="choiceWater()">选择水面</button>
                    </div>
                </div>
            </form>
        </div>
    </body>

<script>
    var position = null,
        floodObj = null;
    function startDrawWater() {
        var sgWorld = CreateSGObj();
        position = null;
        floodObj = null;
        sgWorld.AttachEvent("OnLButtonClicked", drawWater);
        sgWorld.AttachEvent("OnFrame", drawWaterFrame);
        sgWorld.Window.SetInputMode(1, "", true);
    }

    function drawWater(Flags, X, Y) {
        var sgWorld = CreateSGObj();
        var wpi = sgWorld.Window.PixelToWorld(X, Y, -1);
        if (null == position) {
            //将屏幕的像素坐标转化为三位中的世界坐标
            if (null == wpi) {
                return false;
            }
            position = wpi.Position.Copy();
            floodObj = sgWorld.Creator.CreateCircle(
                position,
                1,
                "0xFF00FF00",
                "0xFF646464",
                "",
                ""
            );
            floodObj.FillStyle.Color.FromHTMLColor("#0000ff"); //设置圆形的颜色为蓝色
            floodObj.FillStyle.Color.SetAlpha(0.2); //不透明度为0.2
            floodObj.FillStyle.Texture.FileName = "$$WATER$$";
            floodObj.Position.ChangeAltitudeType(0); //调整对象的高度类型为相对于地表
            var height = parseFloat($("#surfaceHeight").val());
            floodObj.Position.Altitude = height;
        } else {
            var pos = wpi.Position;
            var radius = position.DistanceTo(pos);
            floodObj.Radius = radius;
            position = null;
            sgWorld.DetachEvent("OnLButtonClicked", drawWater);
            sgWorld.DetachEvent("OnFrame", drawWaterFrame);
            sgWorld.Window.SetInputMode(0, "", true);
        }
    }
    function drawWaterFrame() {
        var sgWorld = CreateSGObj();
        if (null == position) return;
        var mi = sgWorld.Window.GetMouseInfo();
        var pos = sgWorld.Window.PixelToWorld(mi.X, mi.Y, -1).Position;
        var radius = position.DistanceTo(pos);
        floodObj.Radius = radius;
    }

    function heightChange() {
        if (null !== floodObj) {
            var height = parseFloat($("#surfaceHeight").val());
            floodObj.Position.Altitude = height;
        }
    }

    function choiceWater() {
        var sgWorld = CreateSGObj();
        sgWorld.AttachEvent("OnLButtonClicked", choiceWaterClick);
        sgWorld.Window.SetInputMode(1, "", true);
    }
    function choiceWaterClick(Flag, X, Y) {
        var sgWorld = CreateSGObj();
        var wpi = sgWorld.Window.PixelToWorld(X, Y, -1);
        if (null == wpi) {
            return false;
        }
        var obj = sgWorld.ProjectTree.GetObject(wpi.ObjectID),
            objType = obj.ObjectType;
        if (CheckType(objType)) {
            floodObj = obj;
            sgWorld.DetachEvent("OnLButtonClicked", choiceWaterClick);
            sgWorld.Window.SetInputMode(0, "", true);
        }
    }

    function CheckType(type) {
        switch (type) {
            case 2: //POLYGON 多边形
                return true;
                break;
            case 3: //RECTANGLE 矩形
                return true;
                break;
            case 4: //REGULAR_POLYGON 正多边形
                return true;
                break;
            case 5: //CIRCLE 圆形
                return true;
                break;
            case 12: //ELLIPSE 椭圆
                return true;
                break;
            case 14: //ARROW 箭头
                return true;
                break;
            default:
                break;
        }
        return false;
    }
</script>

</html>