addstationstemplate.html
10.6 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!-- 手动添加站点 -->
<div class="modal fade" id="add_station_template_mobal" tabindex="-1" role="basic" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">手动添加站点</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" id="save_station_template_form" action="/module" method="post">
<div class="alert alert-danger display-hide"> <button class="close" data-close="alert"></button>
您的输入有误,请检查下面的输入项
</div>
<!-- 站点名称 -->
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-3">
<span class="required"> * </span> 站点名称:
</label>
<div class="col-md-9">
<textarea class="form-control" rows="12" name="stations" id="stationsInput" placeholder="站点名称"></textarea>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">坐标系类型:</label>
<div class="col-md-9">
<div class="icheck-list">
<label>
<input type="radio" class="icheck" name="baseRes" value='No'> 暂无坐标系
</label>
<label>
<input type="radio" class="icheck" name="baseRes" value='GCJ02' > 火星坐标系
</label>
<label >
<input type="radio" class="icheck" name="baseRes" value='BD09'> 百度坐标系
</label>
<label >
<input type="radio" class="icheck" name="baseRes" value='WGS84' checked> WGS84坐标系
</label>
</div>
</div>
</div>
<!-- 版本号 -->
<div class="form-body">
<div class="form-group">
<label class="col-md-3 control-label">版本号 :</label>
<div class="col-md-6">
<input type="text" class="form-control" name="versions" id='versionsInput' Readonly>
</div>
</div>
</div>
<div class="form-group">
<div class="alert alert-info font-blue-chambray" style="background-color: #2C3E50">
<h5 class="block"><span class="help-block" style="color:#1bbc9b;"> * 手动添加站点规划说明: </span></h5>
<p>
<span class="help-block" style="color:#1bbc9b;">
请在文本域中按站点顺序依次输入站点名称(如果已有站点GPS坐标(坐标点也用【Tab】键隔开),请将坐标跟在站点名称后面用【Tab】键隔开),每输入完一个站名时请按回车键【Enter】换行.
例如:<br><br>
浦东大道金桥路 121.496612 31.238960<br>
浦东大道居家桥路 121.496618 31.238957<br>
浦东大道德平路 121.496622 31.238948<br>
</span>
</p>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn default" data-dismiss="modal" id="addMobalHiden">取消</button>
<button type="button" class="btn btn-primary" id="templateSaveData">提交数据</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
// xml方式上传是,处理转成txt格式的方法
var getXmlSection = function (xml) {
// var xml = $("#xmlText").val();
var stationPointList = getXmlNode(xml);
var sListSize = stationPointList.length;
var sectionPointListStr = stationPointList[stationPointList.length - 1];
var sectionPointList = sectionPointListStr.split(" ");
// var sectionStr = "";
var sections = [];
var mapping = nearestSectionPoint(stationPointList, sectionPointList);
for (var i = 0; i < sectionPointList.length; i++) {
var pointStr = sectionPointList[i],
point = pointStr.split(",");
if (mapping[pointStr]) {
sections.push(point[0] + " " + point[1] + " " + point[2] + " Stop");
} else {
sections.push(point[0] + " " + point[1] + " " + point[2]);
}
}
return sections;
};
$('#add_station_template_mobal').on('AddStationTempMobal.show', function(e,map,ajaxd,dir,line,fun){
// 延迟加载显示mobal
setTimeout(function(){$('#add_station_template_mobal').modal({show : true,backdrop: 'static', keyboard: false});},200);
// 获取表单元素
var form = $('#save_station_template_form');
$('#versionsInput').val($("#versions").val());
// 获取错误提示信息元素
var error = $('.alert-danger', form);
// 提交数据点击事件
$('.modal-footer #templateSaveData').on('click',function() {
// 表单提交
form.submit();
});
// 表单验证
form.validate({
errorElement : 'span',
errorClass : 'help-block help-block-error',
focusInvalid : false,
rules : {
'stations' : {
required : true,
}
},
invalidHandler : function(event, validator) {
error.show();
App.scrollTo(error, -200);
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight : function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
},
submitHandler : function(f) {
// 隐藏弹出层
$('#edit_route_mobal').modal('hide');
// 原坐标类型
var baseRes = "WGS84";
// 定义线路名称
var lineNameV = $('.portlet-title .caption').text();
var dirStr = '';
// 路线方向
var directionData = dir;
var type = $("input[name='typeCheck']:checked").val();
// 弹出正在加载层
var i = layer.load(2);
// 表单序列化
var paramsForm = form.serializeJSON();
var array = [];
if(type == 1){
array = getXmlSection(paramsForm.points);
} else {
// 切割坐标点
array = paramsForm.points.split('\r\n');
}
// 把坐标点转换为站点或路段
var arrayFormat = inputStationValueFormat(array);
var stationList = arrayFormat.stationList;
var sectionListTemp = arrayFormat.sectionList;
var sectionList = [];
// 隔30个取一个点(相当于30s)
var typeNum = type == 0 ? 30:1;
for(var i = 0; i*typeNum < sectionListTemp.length; i++) {
sectionList[i] = sectionListTemp[i*typeNum];
}
sectionList[sectionList.length] = sectionListTemp[sectionListTemp.length-1];
var sectionListFinal = [];
sectionListFinal.push({sectionName : lineNameV, points : sectionList});
// 根据站点名称获取百度坐标
map.stationsPointsToLibraryPoint(stationList,function(resultJson) {
// 根据坐标点获取两点之间的时间与距离
map.getDistanceAndDuration(resultJson,function(stationdataList) {
// 设置第一个站的距离
stationdataList[0].distance = '';
// 设置第一个站的时间
stationdataList[0].duration = '';
// 定义站点信息JSON字符串
var stationJSON = JSON.stringify(stationdataList);
// 参数集合
var params = {};
params.baseRes = baseRes;
// 是否添加该站点
// 站点信息JSON字符串
params.stationJSON = stationJSON;
// 线路ID
params.lineId = line.id;
// 方向
params.directions = directionData;
// 原始坐标类型
params.dbType = 'b';
// 圆形半径
params.radius = '100';
// 限速
params.speedLimit = '60';
// 图形类型(r:圆形;p:多边形)
params.shapesType = 'r';
// destroy:是否撤销
params.destroy = '0';
// versions:版本号
params.versions = '1';
// 定义路段信息字符串
var sectionJSON = JSON.stringify(sectionListFinal);
// 路段信息JSON字符串
params.sectionJSON = sectionJSON;
addSave(params,line.id,directionData);
});
});
},
});
function inputStationValueFormat(paramsStationsArray) {
var stationList = [];
var sectionList = [];
var routeList = {"stationList":stationList, "sectionList":sectionList};
var len = paramsStationsArray.length;
// 处理相同站点判断值
var isPush = true;
for(var k =0;k<len;k++) {
if(paramsStationsArray[k]=="")
continue;
var tempStr = paramsStationsArray[k].split('\t');
var tempPoint = transGpsLoc(tempStr[0],tempStr[1]);
var point = {lng:tempPoint.lng, lat:tempPoint.lat};
if(tempStr.length < 4){
sectionList[k] = point;
isPush = true;
}else {
if(isPush) {
sectionList[k] = point;
stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}});
}
isPush = false;
}
}
for(var i = 0 ;i<sectionList.length;i++) {
if(sectionList[i] == "" || isNaN(sectionList[i].lng) || typeof(sectionList[i]) == "undefined" || sectionList[i] == null) {
sectionList.splice(i,1);//删除数组中下表i-i+1之间的值
i= i-1;
}
}
return routeList;
}
function addSave(params,lineid,directionData) {
var version = $("#versions").val();
params.versions = version;
// 保存
ajaxd.manualSave(params,function(rd) {
// 关闭弹出层
layer.closeAll();
if(rd.status='SUCCESS') {
layer.msg('保存成功!');
var stationD = rd.stationData,isNullStr = '';
for(var t = 0 ;t<stationD.length;t++) {
if(stationD[t].potion.lat =='' || stationD[t].potion.lat ==null ||
stationD[t].potion.lng =='' || stationD[t].potion.lng ==null)
isNullStr = isNullStr + stationD[t].name + ' , ';
}
if(isNullStr!='') {
layer.open({
title: '提示',
content:'【' + isNullStr + '】' + '地址系统无法解析!,请手动调整位置!'
});
}
}else {
layer.msg('保存失败!');
}
// 清除地图覆盖物
map.clearMarkAndOverlays();
// 刷新树
fun.resjtreeDate(lineid,directionData,version);
//PublicFunctions.resjtreeDate(lineid,directionData,version);
// 查询上行路段信息
//ajaxd.getSectionRouteInfo(lineid,directionData,version,function(data) {
// // 在地图上画出线路走向
// fun.linePanlThree(lineid,data,directionData,version);
//});
});
}
});
</script>