Commit a45ae7db9e2c4fbedf6dde8df00448a00a51fd7c
1 parent
8955189b
修复测点 百度地图生成线路
Showing
5 changed files
with
134 additions
and
84 deletions
src/main/java/com/bsth/controller/StationController.java
| ... | ... | @@ -89,7 +89,7 @@ public class StationController extends BaseController<Station, Integer> { |
| 89 | 89 | |
| 90 | 90 | @RequestMapping(value="cacheSave" , method = RequestMethod.POST) |
| 91 | 91 | public Map<String, Object> cacheSave(@RequestParam Map<String, Object> map) { |
| 92 | - return service.cacheSave(map); | |
| 92 | + return service.cacheSave(map); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** | ... | ... |
src/main/java/com/bsth/service/impl/StationServiceImpl.java
| ... | ... | @@ -1487,6 +1487,8 @@ public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implem |
| 1487 | 1487 | if (!pointsStr.equals("")) { |
| 1488 | 1488 | JSONArray pointsArray = JSONArray.parseArray(pointsStr); |
| 1489 | 1489 | for (int p = 0; p < pointsArray.size(); p++) { |
| 1490 | + if(pointsArray.getJSONObject(p).get("lng") == null) | |
| 1491 | + continue; | |
| 1490 | 1492 | String pointsLngStr = pointsArray.getJSONObject(p).get("lng").toString(); |
| 1491 | 1493 | String pointsLatStr = pointsArray.getJSONObject(p).get("lat").toString(); |
| 1492 | 1494 | Location resultPoint = FromBDPointToWGSPoint(pointsLngStr, pointsLatStr); | ... | ... |
src/main/resources/static/pages/base/stationroute/addstationstemplate.html
| ... | ... | @@ -85,6 +85,30 @@ |
| 85 | 85 | </div> |
| 86 | 86 | <script type="text/javascript"> |
| 87 | 87 | |
| 88 | + // xml方式上传是,处理转成txt格式的方法 | |
| 89 | + var getXmlSection = function (xml) { | |
| 90 | + // var xml = $("#xmlText").val(); | |
| 91 | + var stationPointList = getXmlNode(xml); | |
| 92 | + var sListSize = stationPointList.length; | |
| 93 | + var sectionPointListStr = stationPointList[stationPointList.length - 1]; | |
| 94 | + var sectionPointList = sectionPointListStr.split(" "); | |
| 95 | + | |
| 96 | + // var sectionStr = ""; | |
| 97 | + var sections = []; | |
| 98 | + var mapping = nearestSectionPoint(stationPointList, sectionPointList); | |
| 99 | + for (var i = 0; i < sectionPointList.length; i++) { | |
| 100 | + var pointStr = sectionPointList[i], | |
| 101 | + point = pointStr.split(","); | |
| 102 | + | |
| 103 | + if (mapping[pointStr]) { | |
| 104 | + sections.push(point[0] + " " + point[1] + " " + point[2] + " Stop"); | |
| 105 | + } else { | |
| 106 | + sections.push(point[0] + " " + point[1] + " " + point[2]); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + return sections; | |
| 110 | + }; | |
| 111 | + | |
| 88 | 112 | $('#add_station_template_mobal').on('AddStationTempMobal.show', function(e,map,ajaxd,dir,line,fun){ |
| 89 | 113 | |
| 90 | 114 | |
| ... | ... | @@ -154,33 +178,45 @@ $('#add_station_template_mobal').on('AddStationTempMobal.show', function(e,map,a |
| 154 | 178 | }, |
| 155 | 179 | |
| 156 | 180 | submitHandler : function(f) { |
| 157 | - // 隐藏手动规划弹出层 | |
| 158 | - $('#add_station_template_mobal').modal('hide'); | |
| 159 | - var directionData = dir; | |
| 181 | + // 隐藏弹出层 | |
| 182 | + $('#edit_route_mobal').modal('hide'); | |
| 183 | + // 原坐标类型 | |
| 184 | + var baseRes = "WGS84"; | |
| 160 | 185 | // 定义线路名称 |
| 161 | 186 | var lineNameV = $('.portlet-title .caption').text(); |
| 162 | 187 | var dirStr = ''; |
| 163 | - // 上行 | |
| 164 | - if(directionData==0){ | |
| 165 | - dirStr = '上行路段'; | |
| 166 | - // 隐藏上行规划 | |
| 167 | - $('#upToolsMobal').hide(); | |
| 168 | - // 下行 | |
| 169 | - }else if(directionData==1){ | |
| 170 | - dirStr = '下行路段'; | |
| 171 | - // 隐藏上行规划 | |
| 172 | - $('#downToolsMobal').hide(); | |
| 173 | - } | |
| 188 | + // 路线方向 | |
| 189 | + var directionData = dir; | |
| 190 | + | |
| 191 | + var type = $("input[name='typeCheck']:checked").val(); | |
| 192 | + | |
| 174 | 193 | // 弹出正在加载层 |
| 175 | - var i = layer.load(0,{offset:['200px', '280px']}); | |
| 194 | + var i = layer.load(2); | |
| 176 | 195 | // 表单序列化 |
| 177 | 196 | var paramsForm = form.serializeJSON(); |
| 178 | - var baseResValue = paramsForm.baseRes; | |
| 179 | - // 站点名称字符串切割 | |
| 180 | - var array = paramsForm.stations.split('\r\n'); | |
| 197 | + var array = []; | |
| 198 | + if(type == 1){ | |
| 199 | + array = getXmlSection(paramsForm.points); | |
| 200 | + } else { | |
| 201 | + // 切割坐标点 | |
| 202 | + array = paramsForm.points.split('\r\n'); | |
| 203 | + } | |
| 204 | + // 把坐标点转换为站点或路段 | |
| 181 | 205 | var arrayFormat = inputStationValueFormat(array); |
| 206 | + var stationList = arrayFormat.stationList; | |
| 207 | + var sectionListTemp = arrayFormat.sectionList; | |
| 208 | + var sectionList = []; | |
| 209 | + // 隔30个取一个点(相当于30s) | |
| 210 | + var typeNum = type == 0 ? 30:1; | |
| 211 | + for(var i = 0; i*typeNum < sectionListTemp.length; i++) { | |
| 212 | + sectionList[i] = sectionListTemp[i*typeNum]; | |
| 213 | + } | |
| 214 | + sectionList[sectionList.length] = sectionListTemp[sectionListTemp.length-1]; | |
| 215 | + | |
| 216 | + var sectionListFinal = []; | |
| 217 | + sectionListFinal.push({sectionName : lineNameV, points : sectionList}); | |
| 182 | 218 | // 根据站点名称获取百度坐标 |
| 183 | - map.stationsNameToPoints(arrayFormat,function(resultJson) { | |
| 219 | + map.stationsPointsToLibraryPoint(stationList,function(resultJson) { | |
| 184 | 220 | // 根据坐标点获取两点之间的时间与距离 |
| 185 | 221 | map.getDistanceAndDuration(resultJson,function(stationdataList) { |
| 186 | 222 | // 设置第一个站的距离 |
| ... | ... | @@ -189,14 +225,15 @@ $('#add_station_template_mobal').on('AddStationTempMobal.show', function(e,map,a |
| 189 | 225 | stationdataList[0].duration = ''; |
| 190 | 226 | // 定义站点信息JSON字符串 |
| 191 | 227 | var stationJSON = JSON.stringify(stationdataList); |
| 192 | - var addLine = line.getLineObj(); | |
| 193 | 228 | // 参数集合 |
| 194 | 229 | var params = {}; |
| 195 | - params.baseRes = baseResValue; | |
| 230 | + params.baseRes = baseRes; | |
| 231 | + // 是否添加该站点 | |
| 232 | + | |
| 196 | 233 | // 站点信息JSON字符串 |
| 197 | 234 | params.stationJSON = stationJSON; |
| 198 | 235 | // 线路ID |
| 199 | - params.lineId = addLine.id; | |
| 236 | + params.lineId = line.id; | |
| 200 | 237 | // 方向 |
| 201 | 238 | params.directions = directionData; |
| 202 | 239 | // 原始坐标类型 |
| ... | ... | @@ -211,64 +248,53 @@ $('#add_station_template_mobal').on('AddStationTempMobal.show', function(e,map,a |
| 211 | 248 | params.destroy = '0'; |
| 212 | 249 | // versions:版本号 |
| 213 | 250 | params.versions = '1'; |
| 214 | - map.lineInfoPanl(lineNameV,directionData,function(BusLine){ | |
| 215 | - // 如果线路信息不为空 | |
| 216 | - if(BusLine && Polygon){ | |
| 217 | - // 获取公交线几何对象, 仅当结果自动添加到地图上时有效 | |
| 218 | - var Polygon = BusLine.getPolyline(); | |
| 219 | - // 返回多边型的点数组(自1.2新增) | |
| 220 | - var polyGonArray = Polygon.getPath(); | |
| 221 | - var jsonArray = [{sectionName:lineNameV+dirStr,points:polyGonArray}]; | |
| 222 | - // 定义路段信息字符串 | |
| 223 | - var sectionJSON = JSON.stringify(jsonArray); | |
| 224 | - // 路段信息JSON字符串 | |
| 225 | - // if(sectionJSON != null && sectionJSON != "") { | |
| 226 | - params.sectionJSON = sectionJSON; | |
| 227 | - addSave(params,addLine.id,directionData); | |
| 228 | - /* } else { | |
| 229 | - layer.msg('百度地图上没有此线路的相应路段,请更换方式规划!!!'); | |
| 230 | - } */ | |
| 231 | - }else { | |
| 232 | - // 根据坐标点获取两点之间的折线路段 | |
| 233 | - map.getSectionListPlonly(stationdataList,function(sectiondata) { | |
| 234 | - // 定义路段信息字符串 | |
| 235 | - var sectionJSON = JSON.stringify(sectiondata); | |
| 236 | - // 路段信息JSON字符串 | |
| 237 | - //if(sectionJSON != null && sectionJSON != "") { | |
| 238 | - params.sectionJSON = sectionJSON; | |
| 239 | - addSave(params,addLine.id,directionData); | |
| 240 | - /* } else { | |
| 241 | - layer.msg('无法生成路段,请重试!'); | |
| 242 | - return; | |
| 243 | - } */ | |
| 244 | - }); | |
| 245 | - } | |
| 246 | - }); | |
| 247 | - | |
| 248 | - }); | |
| 251 | + // 定义路段信息字符串 | |
| 252 | + var sectionJSON = JSON.stringify(sectionListFinal); | |
| 253 | + // 路段信息JSON字符串 | |
| 254 | + params.sectionJSON = sectionJSON; | |
| 255 | + addSave(params,line.id,directionData); | |
| 256 | + }); | |
| 249 | 257 | |
| 250 | - }); | |
| 251 | - | |
| 252 | - } | |
| 258 | + }); | |
| 259 | + }, | |
| 253 | 260 | |
| 254 | - }); | |
| 261 | + }); | |
| 255 | 262 | |
| 256 | 263 | function inputStationValueFormat(paramsStationsArray) { |
| 257 | 264 | var stationList = []; |
| 265 | + var sectionList = []; | |
| 266 | + var routeList = {"stationList":stationList, "sectionList":sectionList}; | |
| 258 | 267 | var len = paramsStationsArray.length; |
| 268 | + // 处理相同站点判断值 | |
| 269 | + var isPush = true; | |
| 259 | 270 | for(var k =0;k<len;k++) { |
| 260 | 271 | if(paramsStationsArray[k]=="") |
| 261 | 272 | continue; |
| 262 | 273 | var tempStr = paramsStationsArray[k].split('\t'); |
| 263 | - if(tempStr.length<2){ | |
| 264 | - stationList.push({name:paramsStationsArray[k]+"公交车站",wgs:{x:'',y:''}}); | |
| 274 | + var tempPoint = transGpsLoc(tempStr[0],tempStr[1]); | |
| 275 | + var point = {lng:tempPoint.lng, lat:tempPoint.lat}; | |
| 276 | + if(tempStr.length < 4){ | |
| 277 | + sectionList[k] = point; | |
| 278 | + isPush = true; | |
| 265 | 279 | }else { |
| 266 | - stationList.push({name:tempStr[0]+"公交车站",wgs:{x:tempStr[1], y:tempStr[2]}}); | |
| 280 | + if(isPush) { | |
| 281 | + sectionList[k] = point; | |
| 282 | + stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}}); | |
| 283 | + } | |
| 284 | + isPush = false; | |
| 267 | 285 | } |
| 268 | 286 | } |
| 269 | - return stationList; | |
| 287 | + for(var i = 0 ;i<sectionList.length;i++) { | |
| 288 | + if(sectionList[i] == "" || isNaN(sectionList[i].lng) || typeof(sectionList[i]) == "undefined" || sectionList[i] == null) { | |
| 289 | + sectionList.splice(i,1);//删除数组中下表i-i+1之间的值 | |
| 290 | + i= i-1; | |
| 291 | + } | |
| 292 | + | |
| 293 | + } | |
| 294 | + return routeList; | |
| 270 | 295 | } |
| 271 | 296 | |
| 297 | + | |
| 272 | 298 | function addSave(params,lineid,directionData) { |
| 273 | 299 | |
| 274 | 300 | ... | ... |
src/main/resources/static/pages/base/stationroute/editRoute.html
| ... | ... | @@ -138,30 +138,48 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - // xml方式上传是,处理转成txt格式的方法 | |
| 141 | + // xml方式上传是,处理转成txt格式的方法 | |
| 142 | 142 | var getXmlSection = function (xml) { |
| 143 | 143 | // var xml = $("#xmlText").val(); |
| 144 | 144 | var stationPointList = getXmlNode(xml); |
| 145 | 145 | var sListSize = stationPointList.length; |
| 146 | 146 | var sectionPointListStr = stationPointList[stationPointList.length - 1]; |
| 147 | 147 | var sectionPointList = sectionPointListStr.split(" "); |
| 148 | - var index = 0; | |
| 149 | 148 | |
| 150 | 149 | // var sectionStr = ""; |
| 151 | 150 | var sections = []; |
| 151 | + var mapping = nearestSectionPoint(stationPointList, sectionPointList); | |
| 152 | 152 | for (var i = 0; i < sectionPointList.length; i++) { |
| 153 | 153 | var pointStr = sectionPointList[i], |
| 154 | 154 | point = pointStr.split(","); |
| 155 | 155 | |
| 156 | - if (index < sListSize - 1 && point == stationPointList[index]) { | |
| 156 | + if (mapping[pointStr]) { | |
| 157 | 157 | sections.push(point[0] + " " + point[1] + " " + point[2] + " Stop"); |
| 158 | - index++; | |
| 159 | 158 | } else { |
| 160 | 159 | sections.push(point[0] + " " + point[1] + " " + point[2]); |
| 161 | 160 | } |
| 162 | 161 | } |
| 163 | 162 | return sections; |
| 164 | 163 | }; |
| 164 | + | |
| 165 | + var nearestSectionPoint = function (stationPointList, sectionPointList) { | |
| 166 | + var mapping = {}; | |
| 167 | + for (var i = 0;i < stationPointList.length - 1;i++) { | |
| 168 | + var minDistance = 999999999, stationPoint = stationPointList[i].split(","), pointStr; | |
| 169 | + for (var j = 0;j < sectionPointList.length;j++) { | |
| 170 | + var sectionPointStr = sectionPointList[j], sectionPoint = sectionPointStr.split(","); | |
| 171 | + var distance = Math.sqrt(Math.pow(parseFloat(stationPoint[0]) - parseFloat(sectionPoint[0]), 2) + Math.pow(parseFloat(stationPoint[1]) - parseFloat(sectionPoint[1]), 2)); | |
| 172 | + if (distance < minDistance) { | |
| 173 | + minDistance = distance; | |
| 174 | + pointStr = sectionPointStr; | |
| 175 | + } | |
| 176 | + } | |
| 177 | + mapping[pointStr] = stationPointList[i]; | |
| 178 | + } | |
| 179 | + | |
| 180 | + return mapping; | |
| 181 | + } | |
| 182 | + | |
| 165 | 183 | |
| 166 | 184 | |
| 167 | 185 | // 表单验证 |
| ... | ... | @@ -209,9 +227,9 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 209 | 227 | |
| 210 | 228 | }, |
| 211 | 229 | submitHandler : function(f) { |
| 212 | - // 隐藏弹出层 | |
| 230 | + debugger; | |
| 231 | + // 隐藏弹出层 | |
| 213 | 232 | $('#edit_route_mobal').modal('hide'); |
| 214 | - | |
| 215 | 233 | // 原坐标类型 |
| 216 | 234 | var baseRes = "WGS84"; |
| 217 | 235 | // 定义线路名称 |
| ... | ... | @@ -225,9 +243,6 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 225 | 243 | * xml路段取所有点 |
| 226 | 244 | */ |
| 227 | 245 | var type = $("input[name='typeCheck']:checked").val(); |
| 228 | - //editRoute.setLineDir(directionData); | |
| 229 | - // 设置线路对象生成方式 | |
| 230 | - //editRoute.setLineGenerationType('uploadGPS'); | |
| 231 | 246 | // 弹出正在加载层 |
| 232 | 247 | var i = layer.load(2); |
| 233 | 248 | // 表单序列化 |
| ... | ... | @@ -241,9 +256,6 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 241 | 256 | // 切割坐标点 |
| 242 | 257 | array = paramsForm.points.split('\r\n'); |
| 243 | 258 | } |
| 244 | - | |
| 245 | - | |
| 246 | - | |
| 247 | 259 | // 把坐标点转换为站点或路段 |
| 248 | 260 | var arrayFormat = inputStationValueFormat(array); |
| 249 | 261 | var stationList = arrayFormat.stationList; |
| ... | ... | @@ -313,8 +325,16 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 313 | 325 | for(var k =0;k<len;k++) { |
| 314 | 326 | if(paramsStationsArray[k]=="") |
| 315 | 327 | continue; |
| 328 | + | |
| 316 | 329 | var tempStr = paramsStationsArray[k].split('\t'); |
| 330 | + | |
| 331 | + if(tempStr[0] == "undefined" || tempStr[0] == ""){ | |
| 332 | + continue; | |
| 333 | + } | |
| 334 | + | |
| 317 | 335 | var tempPoint = transGpsLoc(tempStr[0],tempStr[1]); |
| 336 | + | |
| 337 | + | |
| 318 | 338 | var point = {lng:tempPoint.lng, lat:tempPoint.lat}; |
| 319 | 339 | if(tempStr.length < 4){ |
| 320 | 340 | sectionList[k] = point; |
| ... | ... | @@ -337,6 +357,7 @@ $('#edit_route_mobal').on('editRouteMobal.show', function(e,WorldsBMap,GetAjaxDa |
| 337 | 357 | return routeList; |
| 338 | 358 | } |
| 339 | 359 | |
| 360 | + | |
| 340 | 361 | function transGpsLoc(lng,lat) { |
| 341 | 362 | var bdLoc = TransGPS.locationMake(lng, lat); |
| 342 | 363 | var gcjLoc = TransGPS.transformFromWGSToGCJ(bdLoc); | ... | ... |
src/main/resources/static/pages/base/stationroute/js/stationroute-list-function.js
| ... | ... | @@ -305,16 +305,17 @@ var PublicFunctions = function () { |
| 305 | 305 | |
| 306 | 306 | /** 直接保存 @param:<lineNameV:线路名称;directionData:方向(0:上行;1:下行)> */ |
| 307 | 307 | systemLineStation : function(lineNameV,directionData) { |
| 308 | + debugger; | |
| 308 | 309 | /** 从百度地图获取线路信息 @param:<lineNameV:线路名称;directionData:方向(0:上行;1:下行);callback>*/ |
| 309 | 310 | WorldsBMap.lineInfoPanl(lineNameV,directionData,function(BusLine){ |
| 310 | 311 | // 如果线路信息不为空 |
| 311 | - if(BusLine && Polygon) { | |
| 312 | + if(BusLine) { | |
| 312 | 313 | // 获取公交线几何对象, 仅当结果自动添加到地图上时有效 |
| 313 | - var Polygon = BusLine.getPolyline(); | |
| 314 | + var Polygon = BusLine.Zi; | |
| 314 | 315 | // 返回多边型的点数组(自1.2新增) |
| 315 | - var polyGonArray = Polygon.getPath(); | |
| 316 | + var polyGonArray = Polygon.Bo; | |
| 316 | 317 | // 获取公交站点个数(自 1.2 新增) |
| 317 | - var stationNumber = BusLine.getNumBusStations(); | |
| 318 | + var stationNumber = BusLine.UB.length; | |
| 318 | 319 | // 定义线路信息集合 |
| 319 | 320 | var stationInfo = []; |
| 320 | 321 | // 遍历 |
| ... | ... | @@ -322,9 +323,9 @@ var PublicFunctions = function () { |
| 322 | 323 | // 定义线路信息集合 |
| 323 | 324 | var tempM = {}; |
| 324 | 325 | // 添加站点名称 |
| 325 | - tempM.name = BusLine.getBusStation(k).name; | |
| 326 | + tempM.name = BusLine.UB[k].name; | |
| 326 | 327 | // 添加站点坐标 |
| 327 | - tempM.potion = BusLine.getBusStation(k).position; | |
| 328 | + tempM.potion = BusLine.UB[k].position; | |
| 328 | 329 | tempM.wgs = {x:'',y:''}; |
| 329 | 330 | // 添加 |
| 330 | 331 | stationInfo.push(tempM); | ... | ... |