Commit afd6e98d87e1677c916cbefd05ced498cf8a762b

Authored by 王通
1 parent bafcd201

1.GPS测点工具更新,解析处理逻辑更新

src/main/resources/static/pages/base/line/editRoute.html
1 -<!-- 手动添加站点 -->  
2 -<div class="modal fade" id="edit_route_mobal" tabindex="-1" role="basic"  
3 - aria-hidden="true">  
4 -  
5 - <div class="modal-dialog">  
6 -  
7 - <div class="modal-content" >  
8 -  
9 - <div class="modal-header">  
10 - <button type="button" class="close" data-dismiss="modal"  
11 - aria-hidden="true"></button>  
12 - <h4 class="modal-title">生成路线(站点和路段)</h4>  
13 - </div>  
14 -  
15 - <div class="modal-body">  
16 -  
17 - <form class="form-horizontal" role="form"  
18 - id="save_route_template_form" action="" method="">  
19 -  
20 - <div class="alert alert-danger display-hide">  
21 - <button class="close" data-close="alert"></button>  
22 - 您的输入有误,请检查下面的输入项  
23 - </div>  
24 -  
25 - <!-- 站点名称 -->  
26 - <div class="form-body">  
27 -  
28 - <div class="form-group">  
29 - <label class="control-label col-md-2"> <span  
30 - class="required"> * </span> 坐标:  
31 - </label>  
32 - <div class="col-md-10">  
33 - <textarea class="form-control" rows="12" name="points"  
34 - id="pointInput" placeholder="坐标点"></textarea>  
35 - </div>  
36 - </div>  
37 - </div>  
38 - <div class="form-group">  
39 - <label class="col-md-3 control-label">选择文本类型:</label>  
40 - <div class="col-md-3">  
41 - <div class="icheck-list">  
42 - <label> <input type="radio" class="icheck"  
43 - name="typeCheck" value='0' checked> txt  
44 - </label> <label> <input type="radio" class="icheck"  
45 - name="typeCheck" value='1'> xml  
46 - </label>  
47 - </div>  
48 - </div>  
49 - <label class="col-md-3 control-label">选择方向:</label>  
50 - <div class="col-md-3">  
51 - <div class="icheck-list">  
52 - <label> <input type="radio" class="icheck"  
53 - name="dirCheck" value='0' checked> 上行  
54 - </label> <label> <input type="radio" class="icheck"  
55 - name="dirCheck" value='1'> 下行  
56 - </label>  
57 - </div>  
58 - </div>  
59 - </div>  
60 - <div class="form-group">  
61 - <div class="alert alert-info font-blue-chambray"  
62 - style="background-color: #2C3E50">  
63 - <h5 class="block">  
64 - <span class="help-block" style="color: #1bbc9b;"> *  
65 - 坐标生成路线规划说明: </span>  
66 - </h5>  
67 - <p>  
68 -  
69 - <span class="help-block" style="color: #1bbc9b;">  
70 - 1.txt格式  
71 - <br>&nbsp;请在文本域中按顺序依次输坐标点,每行中的数据之间用【Tab】键隔开(如果是站点,请将在坐标后面加 stop;没有  
72 - stop默认是路段点,连续带stop的坐标认为是同一个站点),每输入完一个坐标时请按回车键【Enter】换行. 例如:  
73 - <br>121.511870 31.180638 043703.000  
74 - <br>121.511870 31.180643 043705.000  
75 - <br>121.511870 31.180648 043706.000 Stop  
76 - <br>121.511872 31.180653 043707.000  
77 - </span>  
78 - </p>  
79 - <p>  
80 -  
81 - <span class="help-block" style="color: #1bbc9b;">  
82 - 2.xml格式  
83 - <br>用gps生成工具,生成的kml文件里的数据  
84 - </span>  
85 - </p>  
86 - </div>  
87 - </div>  
88 - </form>  
89 - </div>  
90 - <div class="modal-footer">  
91 - <button type="button" class="btn default" data-dismiss="modal"  
92 - id="addMobalHiden">取消</button>  
93 -<!-- <button type="button" class="btn btn-primary hidden" id="referenceCurrentVersion">引用当前版本</button> -->  
94 - <button type="button" class="btn btn-primary" id="templateSaveData">提交数据</button>  
95 - </div>  
96 - </div>  
97 - </div>  
98 -</div>  
99 -<script type="text/javascript">  
100 -  
101 -$('#edit_route_mobal').on('editRouteMobal.show', function(e,transGPS,editRoute,map,dra,ajaxd,fun){  
102 - // 延迟加载显示mobal  
103 - setTimeout(function(){$('#edit_route_mobal').modal({show : true,backdrop: 'static', keyboard: false});},200);  
104 - // 获取表单元素  
105 - var form = $('#save_route_template_form');  
106 -  
107 - // 获取错误提示信息元素  
108 - var error = $('.alert-danger', form);  
109 -  
110 - // 提交数据点击事件  
111 - $('.modal-footer #templateSaveData').on('click',function() {  
112 - form.submit();  
113 - });  
114 -  
115 -  
116 - //从xml中获取节点内容  
117 - function getXmlNode(str){  
118 - //创建文档对象  
119 - var parser=new DOMParser();  
120 - var xmlDoc=parser.parseFromString(str,"text/xml");  
121 -  
122 - //提取数据  
123 - var countrys = xmlDoc.getElementsByTagName('coordinates');  
124 - //var countrys = xmlDoc.getElementsByTagName('DataSource');  
125 -  
126 - var arr = [];  
127 -  
128 - for (var i = 0; i < countrys.length; i++) {  
129 - arr.push(countrys[i].textContent);  
130 - };  
131 - // console.log(arr);  
132 - return arr;  
133 -  
134 - }  
135 -  
136 - // xml方式上传是,处理转成txt格式的方法  
137 - var getXmlSection = function (xml) {  
138 - // var xml = $("#xmlText").val();  
139 - var stationPointList = getXmlNode(xml);  
140 - var sListSize = stationPointList.length;  
141 - var sectionPointListStr = stationPointList[stationPointList.length - 1];  
142 - var sectionPointList = sectionPointListStr.split(" ");  
143 - var index = 0;  
144 -  
145 - // var sectionStr = "";  
146 - var sections = [];  
147 - for (var i = 0; i < sectionPointList.length; i++) {  
148 - var pointStr = sectionPointList[i],  
149 - point = pointStr.split(",");  
150 -  
151 - if (index < sListSize - 1 && point == stationPointList[index]) {  
152 - sections.push(point[0] + " " + point[1] + " " + point[2] + " Stop");  
153 - index++;  
154 - } else {  
155 - sections.push(point[0] + " " + point[1] + " " + point[2]);  
156 - }  
157 - }  
158 - return sections;  
159 - };  
160 -  
161 -  
162 - // 表单验证  
163 - form.validate({  
164 -  
165 - errorElement : 'span',  
166 -  
167 - errorClass : 'help-block help-block-error',  
168 -  
169 - focusInvalid : false,  
170 -  
171 - rules : {  
172 -  
173 - 'points' : {  
174 -  
175 - required : true,  
176 -  
177 - }  
178 -  
179 - },  
180 -  
181 - invalidHandler : function(event, validator) {  
182 -  
183 - error.show();  
184 -  
185 - App.scrollTo(error, -200);  
186 -  
187 - },  
188 -  
189 - highlight : function(element) {  
190 -  
191 - $(element).closest('.form-group').addClass('has-error');  
192 -  
193 - },  
194 -  
195 - unhighlight : function(element) {  
196 -  
197 - $(element).closest('.form-group').removeClass('has-error');  
198 -  
199 - },  
200 -  
201 - success : function(label) {  
202 -  
203 - label.closest('.form-group').removeClass('has-error');  
204 -  
205 - },  
206 - submitHandler : function(f) {  
207 - // 隐藏弹出层  
208 - $('#edit_route_mobal').modal('hide');  
209 - // 获取线路对象  
210 - var line = editRoute.getLineObj();  
211 - // 原坐标类型  
212 - var baseRes = "WGS84";  
213 - // 定义线路名称  
214 - var lineNameV = $('.portlet-title .caption').text();  
215 - var dirStr = '';  
216 - // 路线方向  
217 - var directionData = $("input[name='dirCheck']:checked").val();  
218 - /**  
219 - * 添加类型0(txt)/1(xml)  
220 - * txt方式路段需要30个点取一个  
221 - * xml路段取所有点  
222 - */  
223 - var type = $("input[name='typeCheck']:checked").val();  
224 - editRoute.setLineDir(directionData);  
225 - // 设置线路对象生成方式  
226 - editRoute.setLineGenerationType('uploadGPS');  
227 - // 弹出正在加载层  
228 - var i = layer.load(2);  
229 - // 表单序列化  
230 - var paramsForm = form.serializeJSON();  
231 - var array = [];  
232 - if(type == 1){  
233 - array = getXmlSection(paramsForm.points);  
234 - } else {  
235 - // 切割坐标点  
236 - array = paramsForm.points.split('\r\n');  
237 - }  
238 - // 把坐标点转换为站点或路段  
239 - var arrayFormat = inputStationValueFormat(array);  
240 - var stationList = arrayFormat.stationList;  
241 - var sectionListTemp = arrayFormat.sectionList;  
242 - var sectionList = [];  
243 - // 隔30个取一个点(相当于30s)  
244 - var typeNum = type == 0 ? 30:1;  
245 - for(var i = 0; i*typeNum < sectionListTemp.length; i++) {  
246 - sectionList[i] = sectionListTemp[i*typeNum];  
247 - }  
248 - sectionList[sectionList.length] = sectionListTemp[sectionListTemp.length-1];  
249 -  
250 - var sectionListFinal = [];  
251 - sectionListFinal.push({sectionName : lineNameV, points : sectionList});  
252 - // 根据站点名称获取百度坐标  
253 - map.stationsPointsToLibraryPoint(stationList,function(resultJson) {  
254 - // 根据坐标点获取两点之间的时间与距离  
255 - map.getDistanceAndDuration(resultJson,function(stationdataList) {  
256 - // 设置第一个站的距离  
257 - stationdataList[0].distance = '';  
258 - // 设置第一个站的时间  
259 - stationdataList[0].duration = '';  
260 - // 定义站点信息JSON字符串  
261 - var stationJSON = JSON.stringify(stationdataList);  
262 - // 参数集合  
263 - var params = {};  
264 - params.baseRes = baseRes;  
265 - // 是否添加该站点  
266 -  
267 - // 站点信息JSON字符串  
268 - params.stationJSON = stationJSON;  
269 - // 线路ID  
270 - params.lineId = line.id;  
271 - // 方向  
272 - params.directions = directionData;  
273 - // 原始坐标类型  
274 - params.dbType = 'b';  
275 - // 圆形半径  
276 - params.radius = '80';  
277 - // 限速  
278 - params.speedLimit = '60';  
279 - // 图形类型(r:圆形;p:多边形)  
280 - params.shapesType = 'r';  
281 - // destroy:是否撤销  
282 - params.destroy = '0';  
283 - // versions:版本号  
284 - params.versions = '1';  
285 - // 定义路段信息字符串  
286 - var sectionJSON = JSON.stringify(sectionListFinal);  
287 - // 路段信息JSON字符串  
288 - params.sectionJSON = sectionJSON;  
289 - addSave(params,line.id,directionData);  
290 - });  
291 -  
292 - });  
293 - },  
294 -  
295 - });  
296 -  
297 - function inputStationValueFormat(paramsStationsArray) {  
298 - var stationList = [];  
299 - var sectionList = [];  
300 - var routeList = {"stationList":stationList, "sectionList":sectionList};  
301 - var len = paramsStationsArray.length;  
302 - // 处理相同站点判断值  
303 - var isPush = true;  
304 - for(var k =0;k<len;k++) {  
305 - if(paramsStationsArray[k]=="")  
306 - continue;  
307 - var tempStr = paramsStationsArray[k].split('\t');  
308 - var tempPoint = transGpsLoc(tempStr[0],tempStr[1]);  
309 - var point = {lng:tempPoint.lng, lat:tempPoint.lat};  
310 - if(tempStr.length < 4){  
311 - sectionList[k] = point;  
312 - isPush = true;  
313 - }else {  
314 - if(isPush) {  
315 - sectionList[k] = point;  
316 - stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}});  
317 - }  
318 - isPush = false;  
319 - }  
320 - }  
321 - for(var i = 0 ;i<sectionList.length;i++) {  
322 - if(sectionList[i] == "" || typeof(sectionList[i]) == "undefined" || sectionList[i] == null) {  
323 - sectionList.splice(i,1);//删除数组中下表i-i+1之间的值  
324 - i= i-1;  
325 - }  
326 -  
327 - }  
328 - return routeList;  
329 - }  
330 -  
331 - function transGpsLoc(lng,lat) {  
332 - var bdLoc = transGPS.locationMake(lng, lat);  
333 - var gcjLoc = transGPS.transformFromWGSToGCJ(bdLoc);  
334 - var bdEn = transGPS.bd_encrypt(gcjLoc);  
335 - return bdEn;  
336 - }  
337 -  
338 - /** 引用当前版本站点和走向*/  
339 - /* $("#referenceCurrentVersion").on('click',function() {  
340 - // 获取线路对象  
341 - var line = editRoute.getLineObj();  
342 - // 路线方向  
343 - var direction = $("input[name='dirCheck']:checked").val();  
344 - // 设置线路对象方向  
345 - editRoute.setLineDir(direction);  
346 - // 设置线路对象生成方式  
347 - editRoute.setLineGenerationType('cite');  
348 - $.post("/station/referenceCurrentVersion",{'lineId' : line.id , 'directions' : direction},function(rd){  
349 - // 隐藏弹出层  
350 - $('#edit_route_mobal').modal('hide');  
351 - // 关闭弹出层  
352 - layer.closeAll();  
353 - if(rd.status='SUCCESS') {  
354 - // 清除地图覆盖物  
355 - map.clearMarkAndOverlays();  
356 - // 查询路段信息  
357 - var params = {};  
358 - params.lineId=line.id;  
359 - params.dir = direction;  
360 - // 查询路段信息  
361 - $get('/sectionroute/findCacheSection',params,function(data) {  
362 - // 在地图上画出线路走向  
363 - fun.linePanlThree(line.id,data,direction);  
364 - });  
365 - $('#route_show').removeClass('hidden');  
366 - $('#generationRoute_div').addClass('hidden');  
367 - // 刷新路段列表  
368 - $('#section').click();  
369 - layer.msg('引用当前版本成功!');  
370 - }else {  
371 - layer.msg('引用当前版本失败,请重新引用或选择其他方式!');  
372 - }  
373 - })  
374 - }); */  
375 -  
376 - function addSave(params,lineid,directionData) {  
377 - // 保存  
378 - $post("/station/cacheSave",params,function(rd) {  
379 - // 关闭弹出层  
380 - layer.closeAll();  
381 - if(rd.status='SUCCESS') {  
382 - var stationD = rd.stationData,isNullStr = '';  
383 - for(var t = 0 ;t<stationD.length;t++) {  
384 - if(stationD[t].potion.lat =='' || stationD[t].potion.lat ==null ||  
385 - stationD[t].potion.lng =='' || stationD[t].potion.lng ==null)  
386 - isNullStr = isNullStr + stationD[t].name + ' , ';  
387 - }  
388 - if(isNullStr!='') {  
389 - layer.open({  
390 - title: '提示',  
391 - content:'【' + isNullStr + '】' + '地址系统无法解析!,请手动调整位置!'  
392 - });  
393 - }  
394 - // 清除地图覆盖物  
395 - map.clearMarkAndOverlays();  
396 - var params = {};  
397 - params.lineId = lineid;  
398 - params.dir = directionData;  
399 - // 查询路段信息  
400 - $get('/sectionroute/findCacheSection',params,function(data) {  
401 - // 在地图上画出线路走向  
402 - fun.linePanlThree(lineid,data,directionData);  
403 - });  
404 - $('#route_show').removeClass('hidden');  
405 - $('#generationRoute_div').addClass('hidden');  
406 - // 刷新路段列表  
407 - $('#section').click();  
408 - layer.open({title: '友情提示'  
409 - ,content: '生成路线成功,生成的线路可能会有误差。请先单击路段,拖动编辑、然后双击保存!'});  
410 - }else {  
411 - layer.msg('生成路线失败!');  
412 - }  
413 - });  
414 - }  
415 -}); 1 +<!-- 手动添加站点 -->
  2 +<div class="modal fade" id="edit_route_mobal" tabindex="-1" role="basic"
  3 + aria-hidden="true">
  4 +
  5 + <div class="modal-dialog">
  6 +
  7 + <div class="modal-content" >
  8 +
  9 + <div class="modal-header">
  10 + <button type="button" class="close" data-dismiss="modal"
  11 + aria-hidden="true"></button>
  12 + <h4 class="modal-title">生成路线(站点和路段)</h4>
  13 + </div>
  14 +
  15 + <div class="modal-body">
  16 +
  17 + <form class="form-horizontal" role="form"
  18 + id="save_route_template_form" action="" method="">
  19 +
  20 + <div class="alert alert-danger display-hide">
  21 + <button class="close" data-close="alert"></button>
  22 + 您的输入有误,请检查下面的输入项
  23 + </div>
  24 +
  25 + <!-- 站点名称 -->
  26 + <div class="form-body">
  27 +
  28 + <div class="form-group">
  29 + <label class="control-label col-md-2"> <span
  30 + class="required"> * </span> 坐标:
  31 + </label>
  32 + <div class="col-md-10">
  33 + <textarea class="form-control" rows="12" name="points"
  34 + id="pointInput" placeholder="坐标点"></textarea>
  35 + </div>
  36 + </div>
  37 + </div>
  38 + <div class="form-group">
  39 + <label class="col-md-3 control-label">选择文本类型:</label>
  40 + <div class="col-md-3">
  41 + <div class="icheck-list">
  42 + <label> <input type="radio" class="icheck"
  43 + name="typeCheck" value='0' checked> txt
  44 + </label> <label> <input type="radio" class="icheck"
  45 + name="typeCheck" value='1'> xml
  46 + </label>
  47 + </div>
  48 + </div>
  49 + <label class="col-md-3 control-label">选择方向:</label>
  50 + <div class="col-md-3">
  51 + <div class="icheck-list">
  52 + <label> <input type="radio" class="icheck"
  53 + name="dirCheck" value='0' checked> 上行
  54 + </label> <label> <input type="radio" class="icheck"
  55 + name="dirCheck" value='1'> 下行
  56 + </label>
  57 + </div>
  58 + </div>
  59 + </div>
  60 + <div class="form-group">
  61 + <div class="alert alert-info font-blue-chambray"
  62 + style="background-color: #2C3E50">
  63 + <h5 class="block">
  64 + <span class="help-block" style="color: #1bbc9b;"> *
  65 + 坐标生成路线规划说明: </span>
  66 + </h5>
  67 + <p>
  68 +
  69 + <span class="help-block" style="color: #1bbc9b;">
  70 + 1.txt格式
  71 + <br>&nbsp;请在文本域中按顺序依次输坐标点,每行中的数据之间用【Tab】键隔开(如果是站点,请将在坐标后面加 stop;没有
  72 + stop默认是路段点,连续带stop的坐标认为是同一个站点),每输入完一个坐标时请按回车键【Enter】换行. 例如:
  73 + <br>121.511870 31.180638 043703.000
  74 + <br>121.511870 31.180643 043705.000
  75 + <br>121.511870 31.180648 043706.000 Stop
  76 + <br>121.511872 31.180653 043707.000
  77 + </span>
  78 + </p>
  79 + <p>
  80 +
  81 + <span class="help-block" style="color: #1bbc9b;">
  82 + 2.xml格式
  83 + <br>用gps生成工具,生成的kml文件里的数据
  84 + </span>
  85 + </p>
  86 + </div>
  87 + </div>
  88 + </form>
  89 + </div>
  90 + <div class="modal-footer">
  91 + <button type="button" class="btn default" data-dismiss="modal"
  92 + id="addMobalHiden">取消</button>
  93 +<!-- <button type="button" class="btn btn-primary hidden" id="referenceCurrentVersion">引用当前版本</button> -->
  94 + <button type="button" class="btn btn-primary" id="templateSaveData">提交数据</button>
  95 + </div>
  96 + </div>
  97 + </div>
  98 +</div>
  99 +<script type="text/javascript">
  100 +
  101 +$('#edit_route_mobal').on('editRouteMobal.show', function(e,transGPS,editRoute,map,dra,ajaxd,fun){
  102 + // 延迟加载显示mobal
  103 + setTimeout(function(){$('#edit_route_mobal').modal({show : true,backdrop: 'static', keyboard: false});},200);
  104 + // 获取表单元素
  105 + var form = $('#save_route_template_form');
  106 +
  107 + // 获取错误提示信息元素
  108 + var error = $('.alert-danger', form);
  109 +
  110 + // 提交数据点击事件
  111 + $('.modal-footer #templateSaveData').on('click',function() {
  112 + form.submit();
  113 + });
  114 +
  115 +
  116 + //从xml中获取节点内容
  117 + function getXmlNode(str){
  118 + //创建文档对象
  119 + var parser=new DOMParser();
  120 + var xmlDoc=parser.parseFromString(str,"text/xml");
  121 +
  122 + //提取数据
  123 + var countrys = xmlDoc.getElementsByTagName('coordinates');
  124 + //var countrys = xmlDoc.getElementsByTagName('DataSource');
  125 +
  126 + var arr = [];
  127 +
  128 + for (var i = 0; i < countrys.length; i++) {
  129 + arr.push(countrys[i].textContent);
  130 + };
  131 + // console.log(arr);
  132 + return arr;
  133 +
  134 + }
  135 +
  136 + // xml方式上传是,处理转成txt格式的方法
  137 + var getXmlSection = function (xml) {
  138 + // var xml = $("#xmlText").val();
  139 + var stationPointList = getXmlNode(xml);
  140 + var sListSize = stationPointList.length;
  141 + var sectionPointListStr = stationPointList[stationPointList.length - 1];
  142 + var sectionPointList = sectionPointListStr.split(" ");
  143 +
  144 + // var sectionStr = "";
  145 + var sections = [];
  146 + let mapping = nearestSectionPoint(stationPointList, sectionPointList);
  147 + for (var i = 0; i < sectionPointList.length; i++) {
  148 + var pointStr = sectionPointList[i],
  149 + point = pointStr.split(",");
  150 +
  151 + if (mapping[pointStr]) {
  152 + sections.push(point[0] + " " + point[1] + " " + point[2] + " Stop");
  153 + } else {
  154 + sections.push(point[0] + " " + point[1] + " " + point[2]);
  155 + }
  156 + }
  157 + return sections;
  158 + };
  159 +
  160 + var nearestSectionPoint = function (stationPointList, sectionPointList) {
  161 + let mapping = {};
  162 + for (let i = 0;i < stationPointList.length - 1;i++) {
  163 + let minDistance = 999999999, stationPoint = stationPointList[i].split(","), pointStr;
  164 + for (let j = 0;j < sectionPointList.length;j++) {
  165 + let sectionPointStr = sectionPointList[j], sectionPoint = sectionPointStr.split(",");
  166 + let distance = Math.sqrt(Math.pow(parseFloat(stationPoint[0]) - parseFloat(sectionPoint[0]), 2) + Math.pow(parseFloat(stationPoint[1]) - parseFloat(sectionPoint[1]), 2));
  167 + if (distance < minDistance) {
  168 + minDistance = distance;
  169 + pointStr = sectionPointStr;
  170 + }
  171 + }
  172 + mapping[pointStr] = stationPointList[i];
  173 + }
  174 +
  175 + return mapping;
  176 + }
  177 +
  178 +
  179 + // 表单验证
  180 + form.validate({
  181 +
  182 + errorElement : 'span',
  183 +
  184 + errorClass : 'help-block help-block-error',
  185 +
  186 + focusInvalid : false,
  187 +
  188 + rules : {
  189 +
  190 + 'points' : {
  191 +
  192 + required : true,
  193 +
  194 + }
  195 +
  196 + },
  197 +
  198 + invalidHandler : function(event, validator) {
  199 +
  200 + error.show();
  201 +
  202 + App.scrollTo(error, -200);
  203 +
  204 + },
  205 +
  206 + highlight : function(element) {
  207 +
  208 + $(element).closest('.form-group').addClass('has-error');
  209 +
  210 + },
  211 +
  212 + unhighlight : function(element) {
  213 +
  214 + $(element).closest('.form-group').removeClass('has-error');
  215 +
  216 + },
  217 +
  218 + success : function(label) {
  219 +
  220 + label.closest('.form-group').removeClass('has-error');
  221 +
  222 + },
  223 + submitHandler : function(f) {
  224 + // 隐藏弹出层
  225 + $('#edit_route_mobal').modal('hide');
  226 + // 获取线路对象
  227 + var line = editRoute.getLineObj();
  228 + // 原坐标类型
  229 + var baseRes = "WGS84";
  230 + // 定义线路名称
  231 + var lineNameV = $('.portlet-title .caption').text();
  232 + var dirStr = '';
  233 + // 路线方向
  234 + var directionData = $("input[name='dirCheck']:checked").val();
  235 + /**
  236 + * 添加类型0(txt)/1(xml)
  237 + * txt方式路段需要30个点取一个
  238 + * xml路段取所有点
  239 + */
  240 + var type = $("input[name='typeCheck']:checked").val();
  241 + editRoute.setLineDir(directionData);
  242 + // 设置线路对象生成方式
  243 + editRoute.setLineGenerationType('uploadGPS');
  244 + // 弹出正在加载层
  245 + var i = layer.load(2);
  246 + // 表单序列化
  247 + var paramsForm = form.serializeJSON();
  248 + var array = [];
  249 + if(type == 1){
  250 + array = getXmlSection(paramsForm.points);
  251 + } else {
  252 + // 切割坐标点
  253 + array = paramsForm.points.split('\r\n');
  254 + }
  255 + // 把坐标点转换为站点或路段
  256 + var arrayFormat = inputStationValueFormat(array);
  257 + var stationList = arrayFormat.stationList;
  258 + var sectionListTemp = arrayFormat.sectionList;
  259 + var sectionList = [];
  260 + // 隔30个取一个点(相当于30s)
  261 + var typeNum = type == 0 ? 30:1;
  262 + for(var i = 0; i*typeNum < sectionListTemp.length; i++) {
  263 + sectionList[i] = sectionListTemp[i*typeNum];
  264 + }
  265 + sectionList[sectionList.length] = sectionListTemp[sectionListTemp.length-1];
  266 +
  267 + var sectionListFinal = [];
  268 + sectionListFinal.push({sectionName : lineNameV, points : sectionList});
  269 + // 根据站点名称获取百度坐标
  270 + map.stationsPointsToLibraryPoint(stationList,function(resultJson) {
  271 + // 根据坐标点获取两点之间的时间与距离
  272 + map.getDistanceAndDuration(resultJson,function(stationdataList) {
  273 + // 设置第一个站的距离
  274 + stationdataList[0].distance = '';
  275 + // 设置第一个站的时间
  276 + stationdataList[0].duration = '';
  277 + // 定义站点信息JSON字符串
  278 + var stationJSON = JSON.stringify(stationdataList);
  279 + // 参数集合
  280 + var params = {};
  281 + params.baseRes = baseRes;
  282 + // 是否添加该站点
  283 +
  284 + // 站点信息JSON字符串
  285 + params.stationJSON = stationJSON;
  286 + // 线路ID
  287 + params.lineId = line.id;
  288 + // 方向
  289 + params.directions = directionData;
  290 + // 原始坐标类型
  291 + params.dbType = 'b';
  292 + // 圆形半径
  293 + params.radius = '80';
  294 + // 限速
  295 + params.speedLimit = '60';
  296 + // 图形类型(r:圆形;p:多边形)
  297 + params.shapesType = 'r';
  298 + // destroy:是否撤销
  299 + params.destroy = '0';
  300 + // versions:版本号
  301 + params.versions = '1';
  302 + // 定义路段信息字符串
  303 + var sectionJSON = JSON.stringify(sectionListFinal);
  304 + // 路段信息JSON字符串
  305 + params.sectionJSON = sectionJSON;
  306 + addSave(params,line.id,directionData);
  307 + });
  308 +
  309 + });
  310 + },
  311 +
  312 + });
  313 +
  314 + function inputStationValueFormat(paramsStationsArray) {
  315 + var stationList = [];
  316 + var sectionList = [];
  317 + var routeList = {"stationList":stationList, "sectionList":sectionList};
  318 + var len = paramsStationsArray.length;
  319 + // 处理相同站点判断值
  320 + var isPush = true;
  321 + for(var k =0;k<len;k++) {
  322 + if(paramsStationsArray[k]=="")
  323 + continue;
  324 + var tempStr = paramsStationsArray[k].split('\t');
  325 + var tempPoint = transGpsLoc(tempStr[0],tempStr[1]);
  326 + var point = {lng:tempPoint.lng, lat:tempPoint.lat};
  327 + if(tempStr.length < 4){
  328 + sectionList[k] = point;
  329 + isPush = true;
  330 + }else {
  331 + if(isPush) {
  332 + sectionList[k] = point;
  333 + stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}});
  334 + }
  335 + isPush = false;
  336 + }
  337 + }
  338 + for(var i = 0 ;i<sectionList.length;i++) {
  339 + if(sectionList[i] == "" || isNaN(sectionList[i].lng) || typeof(sectionList[i]) == "undefined" || sectionList[i] == null) {
  340 + sectionList.splice(i,1);//删除数组中下表i-i+1之间的值
  341 + i= i-1;
  342 + }
  343 +
  344 + }
  345 + return routeList;
  346 + }
  347 +
  348 + function transGpsLoc(lng,lat) {
  349 + var bdLoc = transGPS.locationMake(lng, lat);
  350 + var gcjLoc = transGPS.transformFromWGSToGCJ(bdLoc);
  351 + var bdEn = transGPS.bd_encrypt(gcjLoc);
  352 + return bdEn;
  353 + }
  354 +
  355 + /** 引用当前版本站点和走向*/
  356 + /* $("#referenceCurrentVersion").on('click',function() {
  357 + // 获取线路对象
  358 + var line = editRoute.getLineObj();
  359 + // 路线方向
  360 + var direction = $("input[name='dirCheck']:checked").val();
  361 + // 设置线路对象方向
  362 + editRoute.setLineDir(direction);
  363 + // 设置线路对象生成方式
  364 + editRoute.setLineGenerationType('cite');
  365 + $.post("/station/referenceCurrentVersion",{'lineId' : line.id , 'directions' : direction},function(rd){
  366 + // 隐藏弹出层
  367 + $('#edit_route_mobal').modal('hide');
  368 + // 关闭弹出层
  369 + layer.closeAll();
  370 + if(rd.status='SUCCESS') {
  371 + // 清除地图覆盖物
  372 + map.clearMarkAndOverlays();
  373 + // 查询路段信息
  374 + var params = {};
  375 + params.lineId=line.id;
  376 + params.dir = direction;
  377 + // 查询路段信息
  378 + $get('/sectionroute/findCacheSection',params,function(data) {
  379 + // 在地图上画出线路走向
  380 + fun.linePanlThree(line.id,data,direction);
  381 + });
  382 + $('#route_show').removeClass('hidden');
  383 + $('#generationRoute_div').addClass('hidden');
  384 + // 刷新路段列表
  385 + $('#section').click();
  386 + layer.msg('引用当前版本成功!');
  387 + }else {
  388 + layer.msg('引用当前版本失败,请重新引用或选择其他方式!');
  389 + }
  390 + })
  391 + }); */
  392 +
  393 + function addSave(params,lineid,directionData) {
  394 + // 保存
  395 + $post("/station/cacheSave",params,function(rd) {
  396 + // 关闭弹出层
  397 + layer.closeAll();
  398 + if(rd.status='SUCCESS') {
  399 + var stationD = rd.stationData,isNullStr = '';
  400 + for(var t = 0 ;t<stationD.length;t++) {
  401 + if(stationD[t].potion.lat =='' || stationD[t].potion.lat ==null ||
  402 + stationD[t].potion.lng =='' || stationD[t].potion.lng ==null)
  403 + isNullStr = isNullStr + stationD[t].name + ' , ';
  404 + }
  405 + if(isNullStr!='') {
  406 + layer.open({
  407 + title: '提示',
  408 + content:'【' + isNullStr + '】' + '地址系统无法解析!,请手动调整位置!'
  409 + });
  410 + }
  411 + // 清除地图覆盖物
  412 + map.clearMarkAndOverlays();
  413 + var params = {};
  414 + params.lineId = lineid;
  415 + params.dir = directionData;
  416 + // 查询路段信息
  417 + $get('/sectionroute/findCacheSection',params,function(data) {
  418 + // 在地图上画出线路走向
  419 + fun.linePanlThree(lineid,data,directionData);
  420 + });
  421 + $('#route_show').removeClass('hidden');
  422 + $('#generationRoute_div').addClass('hidden');
  423 + // 刷新路段列表
  424 + $('#section').click();
  425 + layer.open({title: '友情提示'
  426 + ,content: '生成路线成功,生成的线路可能会有误差。请先单击路段,拖动编辑、然后双击保存!'});
  427 + }else {
  428 + layer.msg('生成路线失败!');
  429 + }
  430 + });
  431 + }
  432 +});
416 </script> 433 </script>
417 \ No newline at end of file 434 \ No newline at end of file