getDrawPosInfo.js
8.29 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
var vecLayerMP = null; //矢量要素图层
var featureType = null;
var isMPCheck = false;
var drawControlsMP = null;
var elementObjMP;
function DrawMP() {
if (!isMPCheck) {
if ($("#MPdialog").attr("id") == undefined)
BuildMPAlert();
else {
$.parser.parse($("#MPdialog")); //局部重新渲染
$("#MPdialog").dialog("open");
}
initMPCtrl();
isMPCheck = true;
}
else {
$("#MPdialog").dialog("close");
}
$("#getposInfoText").text("");
}
function BuildMPAlert() {
var sb = '<div id="MPdialog" class="easyui-dialog" title="取图形坐标信息" style="left:900px;top:300px;width: 200px; height: 220px; padding: 5px;" resizable="true">'
+'<table style= "border: 1px dashed gray;" ><tr style="border: 1px gray dashed;" >'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/pnt.png" width="32" height="32" title="绘制点" style="cursor: pointer;" onclick=\'toggleControlMP(0,"point")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';"/></td>'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/a2.png" width="32" height="32" title="绘制圆" style="cursor: pointer;" onclick=\'toggleControlMP(5,"RegularPolygon")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';"/></td>'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/l4.png" width="32" height="32" title="绘制线" style="cursor: pointer;" onclick=\'toggleControlMP(1,"line")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';"/></td>'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/a1.png" width="32" height="32" title="绘制矩形" style="cursor: pointer;" onclick=\'toggleControlMP(3,"RegularPolygon")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';" /></td>'
+ '</tr>'
+ '<tr style="border:gray 1px dashed;">'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/wu.png" width="32" height="32" title="规则多边形" style="cursor: pointer;" onclick=\'toggleControlMP(4,"RegularPolygon")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';"/></td>'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/a3.png" width="32" height="32" title="绘制多边形" style="cursor: pointer;" onclick=\'toggleControlMP(7,"polygon")\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';"/></td>'
+ '<td style="border: 1px gray dashed;"><img src="$$tools$$/' + toolIdMP + '/img/ra.png" width="39" height="32" title="清除图形" style="cursor: pointer;" onclick=\'ClearGraphicsMP()\' onmouseover="this.style.backgroundColor=\'#999A99\';" onmouseout="this.style.backgroundColor=\'\';" /></td>'
+ '</tr>'
+ '<tr style="border:gray 1px dashed;">'
+ '<td colspan="4"><textarea rows="5" id="getposInfoText" cols="18">坐标信息:</textarea></td>'
+ '</tr>'
+ '</table>' +
' </div>';
$("#main").append(sb);
$("#MPdialog").dialog({ closed: false, onClose: function () { closeMP(); } });
}
function initMPCtrl() {
//设置地图初始显示的中心坐标和级别
vecLayerMP = new OpenLayers.Layer.Vector("vecLayerMP");
map.addLayer(vecLayerMP);
drawControlsMP = {
point: new OpenLayers.Control.DrawFeature(vecLayerMP,
OpenLayers.Handler.Point, { featureAdded: AppendFeatureMP }),
line: new OpenLayers.Control.DrawFeature(vecLayerMP,
OpenLayers.Handler.Path, { featureAdded: AppendFeatureMP }),
polygon: new OpenLayers.Control.DrawFeature(vecLayerMP,
OpenLayers.Handler.Polygon, { featureAdded: AppendFeatureMP }),
RegularPolygon: new OpenLayers.Control.DrawFeature(vecLayerMP, OpenLayers.Handler.RegularPolygon, { featureAdded: AppendFeatureMP })
};
for (var key in drawControlsMP) {
map.addControl(drawControlsMP[key]);
}
//设置地图初始显示的中心坐标和级别
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
}
function AppendFeatureMP(element) {
if (element != null) {
switch (elementObjMP) {
case 0: //点
var geomObj = new Zondy.Object.Point2D();
geomObj.setByOL(element.geometry);
$("#getposInfoText").text("坐标信息:"+"X:" + geomObj.x + " Y:" + geomObj.y);
break;
case 1: //线
var geomObj = new Zondy.Object.PolyLine();
geomObj.setByOL(element.geometry);
var s = "";
if (geomObj.pointArr != null && geomObj.pointArr.length > 0) {
var s = geomObj.pointArr.toString();
$("#getposInfoText").text("坐标信息:" + s);
}
break;
case 2: //多边形
case 3: //矩形
case 4: //规则五边形
var geomObj = new Zondy.Object.Polygon();
geomObj.setByOL(element.geometry);
var s = "";
if (geomObj.pointArr != null && geomObj.pointArr.length > 0) {
var s = geomObj.pointArr.toString();
$("#getposInfoText").text("坐标信息:" + s);
}
break;
case 5: //圆
var geomObj = new Zondy.Object.Circle();
geomObj.setByOL(element.geometry);
var s = "";
$("#getposInfoText").text("坐标信息:" + "圆心:" + geomObj.point.toString() + '\n' + "半径:" + geomObj.radious);
break;
case 7: //多边形
var geomObj = new Zondy.Object.Polygon();
geomObj.setByOL(element.geometry);
var s = "";
if (geomObj.pointArr != null && geomObj.pointArr.length > 0) {
var s = geomObj.pointArr.toString();
$("#getposInfoText").text("坐标信息:" + s);
}
break;
}
}
}
//根据当前选择的绘制选项,切换绘制矢量图形的控件
function toggleControlMP(element,type) {
DeactiveDrawMP();
for (key in drawControlsMP) {
var control = drawControlsMP[key];
if (type == key) {
control.activate();
elementObjMP = element;
switch (element) {
case 3:
control.handler.setOptions({ sides: 4 });
break;
case 4:
control.handler.setOptions({ sides: 5 });
break;
case 5:
control.handler.setOptions({ sides: 40 });
break;
}
}
}
}
//取消矢量图形绘制控件的激活状态
function DeactiveDrawMP() {
for (key in drawControlsMP) {
var control = drawControlsMP[key];
control.deactivate();
}
}
function closeMP() {
map.removeLayer(vecLayerMP);
DeactiveDrawMP();
isMPCheck = false;
drawControlsMP = null;
featureType = null;
}
function ClearGraphicsMP() {
if (vecLayerMP != undefined && vecLayerMP != null)
vecLayerMP.removeAllFeatures();
DeactiveDrawMP();
$("#getposInfoText").text("");
}