main.js
6.37 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
var main = {
map:null,
layer:null,
vectorLayer:null,
dragFeature:null,
drawPoint:null,
currentPoint:null,
pastPoint:null,
pointId:null,
init:function () {
//初始化地图
this.map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Navigation()
// new SuperMap.Control.Zoom(),
// new SuperMap.Control.LayerSwitcher()
]
});
this.map.events.on({
zoomend: function (evt) {
mapLevel.setLevel(main.map.getZoom());
}
});
this.layer = new SuperMap.Layer.CloudLayer();
//实例化矢量图层 vectorLayer
this.vectorLayer = new SuperMap.Layer.Vector("vectorLayer");
//实例化 DragFeature 控件
// this.dragFeature = new SuperMap.Control.DragFeature(this.vectorLayer);
//实例化 DrawFeature 控件
this.drawPoint = new SuperMap.Control.DrawFeature(this.vectorLayer, SuperMap.Handler.Point, {multi: true});
//监听 featureadded 事件,当添加要素时会触发此事件
this.drawPoint.events.on({"featureadded": this.drawCompleted});
//map上添加控件
// this.map.addControl(this.dragFeature);
this.map.addControl(this.drawPoint);
//加载图层
this.map.addLayers([this.layer,this.vectorLayer]);
//画点样式
this.vectorLayer.style = {
externalGraphic:"src/image/icon.png",
graphicWidth:21,
graphicHeight:30
};
// this.map.setCenter(new SuperMap.LonLat(11339634.286396, 4588716.5813769), 5);
//加载地图大小缩放控件
mapLevel.loadLevelControl(main.map);
//加载按钮事件
$('#location_cancel').hide();
$('#location_confirm').hide();
$('#location_update').click(function () {
main.updateLocation("location_update");
});
$('#location_cancel').click(function () {
main.updateLocation("location_cancel");
});
$('#location_confirm').click(function () {
main.updateLocation("location_confirm");
});
$('#btn_update').click(function () {
main.updateReturn();
});
//获取网点
this.validate();
// this.getInfoSuccess(11);
},
validate:function () {
var method = "/v1/point/search";
var parameter = {
custom_id:"{\"fieldName\":\"名称\",\"fieldValue\":\"网点1\"}"
};
saas.saasHttpRequest(method,parameter,this.validateSuccess,this.validateError);
},
validateSuccess:function (data) {
if (data.code == "S001"){
var result = data.result;
if (result.length > 0){
var pointName = result[0].pointName;
main.pointId = result[0].id;
main.getInfo(main.pointId);
}
}
},
validateError:function (error) {
},
getInfo:function (id) {
var method = "/v1/point/getPointById";
var parameter = {
pointId:id,
needExtCols:true
};
saas.saasHttpRequest(method,parameter,this.getInfoSuccess,this.getInfoError);
},
getInfoSuccess:function (data) {
// var lonlat = {x:120.42995, y:36.131393};
// var po = latLonToMeters(lonlat);
// main.addMarker(po.x, po.y,1, "src/image/icon.png");
// main.map.setCenter(new SuperMap.LonLat(po.x, po.y), 5);
if (data.code == "S001"){
var result = data.result;
main.addMarker(result.x, result.y,result.id, "src/image/icon.png");
main.map.setCenter(new SuperMap.LonLat(result.x, result.y), 5);
}
},
getInfoError:function (error) {
},
updateLocation:function (btn) {
if (btn == "location_update"){
$('#location_update').hide();
$('#location_cancel').show();
$('#location_confirm').show();
//激活控件
// main.dragFeature.activate();
main.drawPoint.activate();
}else if (btn == "location_cancel"){
$('#location_update').show();
$('#location_cancel').hide();
$('#location_confirm').hide();
//注销控件
// main.dragFeature.deactivate();
main.drawPoint.deactivate();
}else if (btn == "location_confirm"){
$('#location_update').show();
$('#location_cancel').hide();
$('#location_confirm').hide();
//注销控件
// main.dragFeature.deactivate();
main.drawPoint.deactivate();
// var point = this.pointFeature.geometry.getCentroid();
// console.log(point.x+","+point.y);
}
},
addMarker: function (pointX,pointY,code,iconPath) {
var lonlat = {
x:pointX,
y:pointY
};
// var lonlat = latLonToMeters(pointX,pointY);
var geometry = new SuperMap.Geometry.Point(lonlat.x,lonlat.y);
var style = {
// fillColor:iconPath,
// pointRadius:3,
// stroke:true,
// strokeColor:iconPath
externalGraphic:iconPath,
graphicWidth:21,
graphicHeight:30
};
this.currentPoint = new SuperMap.Feature.Vector(geometry,{id:code},style);
this.vectorLayer.addFeatures(this.currentPoint);
},
updateReturn:function () {
console.log(main.pointId)
//跳转修改信息界面
localStorage.setItem('pointId',main.pointId)
window.location.href="dataPage.html";
},
drawCompleted:function (eventArgs) {
main.pastPoint = main.currentPoint;
main.currentPoint = eventArgs.feature;
main.vectorLayer.removeAllFeatures();
main.vectorLayer.addFeatures(main.currentPoint);
var geometry = eventArgs.feature.geometry.getCentroid();
main.updatePoint(geometry.x,geometry.y);
},
updatePoint: function (x,y) {
var method = "/point/updatePoint";
var parameter = {
custom_id:"{\"fieldName\":\"名称\",\"fieldValue\":\"网点1\"}",
infos:"{\"fieldName\":\"名称\",\"fieldValue\":\"网点1\"}",
x:x,
y:y,
coord_type:"gcj02mc"
};
saas.customHttpRequest(method,parameter,this.getInfoSuccess,this.getInfoError);
}
}