flowAnalysis.html
5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<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>
.tiaojian .short-search-btn {
width: 30%;
}
</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 style="padding:20px;">
<button type="button" class="short-search-btn" onclick="selectPipe()">选择管线</button>
<button type="button" class="short-search-btn" onclick="stopSelect()">结束选择</button>
<button type="button" class="short-search-btn" onclick="clearArrow()">清除</button>
</div>
</div>
</form>
</div>
</body>
<script>
var groupID = "";
var arrowList = [];
function selectPipe() {
var sgworld = CreateSGObj();
sgworld.AttachEvent("OnLButtonClicked", flowAnalysisLBClick);
sgworld.Window.SetInputMode(1, "", true);
}
function stopSelect() {
var sgworld = CreateSGObj();
sgworld.DetachEvent("OnLButtonClicked", flowAnalysisLBClick);
sgworld.Window.SetInputMode(0, "", true);
}
function clearArrow() {
var sgworld = CreateSGObj();
sgworld.ProjectTree.DeleteItem(groupID);
}
function flowAnalysisLBClick(Flags, 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);
if (obj.ObjectType === 33)//选中的对象是图层中的一个要素,而不是单个模型、标签等对象时
{
if (obj.Geometry.GeometryType === 0)//Point
{
//点图层的话需要知道 点的位置和目标点的位置
//目标点的位置恐怕需要根据图层中的数据获取
pointObjSelected(obj);
}
else if (obj.Geometry.GeometryType === 1 || obj.Geometry.GeometryType === 2)//1-LineString;2-LinearRing
{
//通过前一个点和后一个点的相互关系来获取
lineObjSelected(obj);
}
else {
//POLYGON = 3 MULTILINESTRING = 5 MULTIPOLYGON = 6
}
}
}
//点图层的话需要根据点图层的属性值来获取方向和长度
function pointObjSelected(obj) {
var sgworld = CreateSGObj();
var layer = sgworld.ProjectTree.GetObject(obj.LayerID);
var yaw = obj.FeatureAttributes.GetFeatureAttribute("Yaw").Value;
var pitch = obj.FeatureAttributes.GetFeatureAttribute("Pitch").Value;
var length = obj.FeatureAttributes.GetFeatureAttribute("Length").Value;
var startP = sgworld.Creator.CreatePosition(obj.Geometry.X, obj.Geometry.Y, obj.Geometry.Z, layer.Position.AltitudeType, yaw, pitch);
if (length >= 3) {
for (var i = 0; i < length / 2; i++) {
var pos = startP.Move(2 * i + 1, yaw, pitch);
var arrow = createArrow(pos);
arrowList.push(arrow.ID);
}
} else {
var arrow = createArrow(startP);
arrowList.push(arrow.ID);
}
}
function lineObjSelected(obj) {
obj.Geometry.StartEdit();
var points = obj.Geometry.Points;//获取线或环的所有点
//points.Count-1 获取倒数第二个为止,这样就可以在最后一次获取倒数第二个和倒数第一个点之间的线段
for (var i = 0; i < points.Count - 1; i++) {
drawArrow(points.Item(i), points.Item(i + 1));
}
obj.Geometry.EndEdit();
}
function drawArrow(startP, endP) {
var sgworld = CreateSGObj();
var pos1 = sgworld.Creator.CreatePosition(startP.X, startP.Y, startP.Z);
var pos2 = sgworld.Creator.CreatePosition(endP.X, endP.Y, endP.Z);
var linelength = pos1.Distance(pos2);
pos1.AimTo(pos2);
if (linelength >= 3)//箭头长度的3倍,一倍的剪头自身长度,一倍的间隔长度,一倍的第二个箭头长度
{
for (var i = 0; i < linelength / 2; i++) {
var pos = pos1.MoveToward(pos2, 2 * i + 1);
pos.AimTo(pos2);
var arrow = createArrow(pos);
arrowList.push(arrow.ID);
}
} else {
var arrow = createArrow(pos);
arrowList.push(arrow.ID);
}
}
function createArrow(pos) {
//alert("进入createArrow");
var sgworld = CreateSGObj();
var linecolor = sgworld.Creator.CreateColor(255, 0, 0, 1);
var fillcolor = sgworld.Creator.CreateColor(0, 0, 255, 1);
if (groupID === "") {
groupID = sgworld.ProjectTree.CreateGroup("流向标志", "");
}
pos.Altitude = pos.Altitude + 1;
return sgworld.Creator.CreateArrow(pos, 1, 4, linecolor, fillcolor, groupID, "");
}
</script>
</html>