styleExample.js
10.5 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
var isSECheck = false;
var drawControlsSE = null; //矢量图形绘制控件数组
var pointLayerSE; //矢量点图层
var lineLayerSE; //矢量线图层
var polygonLayerSE; //矢量多边形图层
var sInitColor = null;
var srcElementStyleEx= null;
function DrawSE() {
if (!isSECheck) {
if ($("#SEdialog").attr("id") == undefined)
BuildSEAlert();
else {
$.parser.parse($("#SEdialog")); //局部重新渲染
$("#SEdialog").dialog("open");
}
initSECtrl();
isSECheck = true;
}
else {
$("#SEdialog").dialog("close");
}
}
function BuildSEAlert() {
var sb = '<div id="SEdialog" class="easyui-dialog" title="图形样式设置" style="left:950px;top:150px;width: 295px; height: 370px;padding: 5px;overflow:hidden;" resizable="true">' +
'<div id="toolspanelSE">'+
' <div id="dialogboxSE">' +
'<div id="itembox" class="itembox">'+
' <label for="themeType">选择要素类型:</label>'+
'<select id="VectorType" name="vec" style="width:80px;" >'+
' <option value="polygon">多边形</option>'+
' <option value="line">线</option>'+
' <option value="point">点</option>'+
' </select>'+
' </div>'+
' <div id="Div1" class="itembox">'+
' 转角类型:'+
' <select id="capType" name="cap">'+
' <option value="butt">butt</option>'+
' <option value="round">round</option>'+
' <option value="square">square</option>'+
'</select>'+
' </div>'+
' <div id="Div2" class="itembox">'+
' 线型:'+
' <select id="LineType" name="dash">'+
' <option value="dot">dot</option>'+
' <option value="dash">dash</option>'+
' <option value="dashdot">dashdot</option>'+
' <option value="longdash">longdash</option>'+
' <option value="longdashdot">longdashdot</option>'+
' <option value="solid">solid</option>'+
' </select>'+
'</div>'+
'<div id="Div3" class="itembox">'+
' 选择线颜色:<input id="linCol" type="text" size="6" onclick=\'showcolors("stroke","linCol")\' style="background-color:#FF0000" alt="clrDlgLin" value="#FF0000" readonly/>' +
'</div>'+
' <div id="Div4" class="itembox">'+
' 填充颜色:<input id="fillCol" type="text" size="6" alt="clrDlgFill" onclick=\'showcolors("fill","fillCol")\' style="background-color:#FFCC00" value="#FFCC00" readonly/>' +
'</div>'+
' <div id="Div5" class="itembox">'+
' 线宽度(pix):<input id="linWid" type="text" size="6" value="2" />'+
'</div>'+
' <div id="Div6" class="itembox">'+
'线透明度(0-1):<input id="linOpc" type="text" size="4" value="0.8" />'+
' </div>'+
' <input id="Submit2" class="functionButton" type="submit" value="开始绘制" onclick="return Submit1_onclick()" />'+
' <input id="Reset2" class="functionButton" type="reset" value="结束绘制" onclick="return Reset1_onclick()" />' +
' <input id="clear2" class="functionButton" type="reset" value="清除" onclick="return StyleDraw_clearEx()" />' +
'</div>'+
' </div>' +
' </div>';
$("#main").append(sb);
$("#SEdialog").dialog({ closed: false, onClose: function () { closebackStyleEx(); } });
}
function initSECtrl() {
//添加绘制矢量点、线、多边形的矢量图层
pointLayerSE = new OpenLayers.Layer.Vector("Point Layer");
lineLayerSE = new OpenLayers.Layer.Vector("Line Layer");
polygonLayerSE = new OpenLayers.Layer.Vector("Polygon Layer");
map.addLayers([pointLayerSE, lineLayerSE, polygonLayerSE]);
//添加图层切换以及显示鼠标位置控件
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
//添加交互绘制矢量图形的控件(点、线、多边形)
drawControlsSE = {
point: new OpenLayers.Control.DrawFeature(pointLayerSE,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(lineLayerSE,
OpenLayers.Handler.Path),
polygon: new OpenLayers.Control.DrawFeature(polygonLayerSE,
OpenLayers.Handler.Polygon)
};
for (var key in drawControlsSE) {
map.addControl(drawControlsSE[key]);
}
}
//根据当前选择的绘制选项,切换绘制矢量图形的控件
function toggleControlStyleEx(element) {
for (key in drawControlsSE) {
var control = drawControlsSE[key];
if (element.value == key) {
control.activate();
} else {
control.deactivate();
}
}
}
//修改矢量图层的样式,实现绘制不同风格的矢量图形
function Submit1_onclick() {
var vecType = $("#VectorType")[0];
var strokeCap = $("#capType")[0];
var strokeDash = $("#LineType")[0];
var linWidth = $("#linWid")[0];
var linOpca = $("#linOpc")[0];
var linColor = $("#linCol")[0];
var linFillColor = $("#fillCol")[0];
switch (vecType.value) {
case "point":
if (pointLayerSE != null) {
if (strokeDash.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.strokeDashstyle = String(strokeDash.value);
}
if (linColor.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.strokeColor = String(linColor.value);
}
if (linWidth.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.strokeWidth = Number(linWidth.value);
}
if (linFillColor.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.fillColor = String(linFillColor.value);
}
if (linOpca.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.strokeOpacity = Number(linOpca.value);
}
if (strokeCap.value) {
pointLayerSE.styleMap.styles["default"].defaultStyle.strokeLinecap = String(strokeCap.value);
}
toggleControlStyleEx(vecType);
}
break;
case "line":
if (lineLayerSE != null) {
if (strokeDash.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.strokeDashstyle = String(strokeDash.value);
}
if (linColor.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.strokeColor = String(linColor.value);
}
if (linWidth.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.strokeWidth = Number(linWidth.value);
}
if (linFillColor.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.fillColor = String(linFillColor.value);
}
if (linOpca.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.strokeOpacity = Number(linOpca.value);
}
if (strokeCap.value) {
lineLayerSE.styleMap.styles["default"].defaultStyle.strokeLinecap = String(strokeCap.value);
}
toggleControlStyleEx(vecType);
}
break;
case "polygon":
if (polygonLayerSE != null) {
if (strokeDash.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.strokeDashstyle = String(strokeDash.value);
}
if (linColor.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.strokeColor = String(linColor.value);
}
if (linWidth.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.strokeWidth = Number(linWidth.value);
}
if (linFillColor.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.fillColor = String(linFillColor.value);
}
if (linOpca.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.strokeOpacity = Number(linOpca.value);
}
if (strokeCap.value) {
polygonLayerSE.styleMap.styles["default"].defaultStyle.strokeLinecap = String(strokeCap.value);
}
toggleControlStyleEx(vecType);
}
break;
default:
break;
}
}
//取消矢量图形绘制控件的激活状态
function Reset1_onclick() {
for (key in drawControlsSE) {
var control = drawControlsSE[key];
control.deactivate();
}
}
function closebackStyleEx() {
map.removeLayer(pointLayerSE);
map.removeLayer(lineLayerSE);
map.removeLayer(polygonLayerSE);
isSECheck = false;
for (var key in drawControlsSE) {
drawControlsSE[key].deactivate();
map.removeControl(drawControlsSE[key]);
}
drawControlsSE = null; //矢量图形绘制控件数组
pointLayerSE = null; //矢量点图层
lineLayerSE = null; //矢量线图层
polygonLayerSE = null; //矢量多边形图层
sInitColor = null;
srcElementStyleEx = null;
}
var inputObjStyleEx = null;
//*设置颜色选择器
function showcolors(type, ids) {
var o = document.getElementById(ids);
inputObjStyleEx = o;
showColorPicker(o, o, colorchangStyleEx);
}
function colorchangStyleEx(e) {
inputObjStyleEx.style.background = inputObjStyleEx.value;
}
//清除绘制的图形
function StyleDraw_clearEx() {
closebackStyleEx();
initSECtrl();
isSECheck = true;
}