Commit 2caf5f9a6f2201baed9768d46d06ec6283d04773
1 parent
caf50a20
update...
Showing
8 changed files
with
267 additions
and
58 deletions
src/main/java/com/bsth/entity/geo_data/GeoStation.java
| 1 | 1 | package com.bsth.entity.geo_data; |
| 2 | 2 | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | + | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 3 | 7 | /** |
| 4 | 8 | * Created by panzhao on 2017/12/7. |
| 5 | 9 | */ |
| ... | ... | @@ -25,8 +29,11 @@ public class GeoStation { |
| 25 | 29 | |
| 26 | 30 | private Float gLaty; |
| 27 | 31 | |
| 32 | + @JsonIgnore | |
| 28 | 33 | private String gPolygonGrid; |
| 29 | 34 | |
| 35 | + private List<String> bdCoords; | |
| 36 | + | |
| 30 | 37 | private Integer radius; |
| 31 | 38 | |
| 32 | 39 | private String shapesType; |
| ... | ... | @@ -134,4 +141,12 @@ public class GeoStation { |
| 134 | 141 | public void setShapesType(String shapesType) { |
| 135 | 142 | this.shapesType = shapesType; |
| 136 | 143 | } |
| 144 | + | |
| 145 | + public List<String> getBdCoords() { | |
| 146 | + return bdCoords; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public void setBdCoords(List<String> bdCoords) { | |
| 150 | + this.bdCoords = bdCoords; | |
| 151 | + } | |
| 137 | 152 | } | ... | ... |
src/main/java/com/bsth/service/geo_data/impl/GeoDataServiceImpl.java
| ... | ... | @@ -39,6 +39,10 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 39 | 39 | |
| 40 | 40 | List<GeoStation> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(GeoStation.class)); |
| 41 | 41 | |
| 42 | + for(GeoStation station : list){ | |
| 43 | + if(station.getShapesType().equals("d")) | |
| 44 | + station.setBdCoords(multiWgsToBd(station.getgPolygonGrid(), 9, 3)); | |
| 45 | + } | |
| 42 | 46 | map.put("status", ResponseCode.SUCCESS); |
| 43 | 47 | map.put("list", list); |
| 44 | 48 | }catch (Exception e){ |
| ... | ... | @@ -59,7 +63,7 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 59 | 63 | List<GeoRoad> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(GeoRoad.class)); |
| 60 | 64 | |
| 61 | 65 | for(GeoRoad road : list){ |
| 62 | - road.setBdCoords(multiWgsToBd(road.getGsectionVector())); | |
| 66 | + road.setBdCoords(multiWgsToBd(road.getGsectionVector(), 11, 2)); | |
| 63 | 67 | } |
| 64 | 68 | map.put("status", ResponseCode.SUCCESS); |
| 65 | 69 | map.put("list", list); |
| ... | ... | @@ -88,17 +92,32 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 88 | 92 | station.setgLonx(Float.parseFloat(String.valueOf(loc.getLng()))); |
| 89 | 93 | |
| 90 | 94 | String sql; |
| 91 | - if(station.getShapesType().equals("r")){ | |
| 92 | - sql = "update bsth_c_station set g_lonx=?, g_laty=?, radius=? where station_cod=?"; | |
| 93 | - int rsCount = jdbcTemplate.update(sql, station.getgLonx(), station.getgLaty(), station.getRadius(), station.getStationCode()); | |
| 95 | + String shapesType = station.getShapesType(); | |
| 96 | + int rsCount = -1; | |
| 97 | + if(shapesType.equals("r")){ | |
| 98 | + sql = "update bsth_c_station set g_lonx=?, g_laty=?, radius=?,shapes_type='r' where station_cod=?"; | |
| 99 | + rsCount = jdbcTemplate.update(sql, station.getgLonx(), station.getgLaty(), station.getRadius(), station.getStationCode()); | |
| 100 | + } | |
| 101 | + else if(shapesType.equals("d")){ | |
| 102 | + //多边形坐标转换 | |
| 103 | + String bdPolygon = "POLYGON((" + station.getgPolygonGrid() +"))"; | |
| 104 | + String wgsPolygon = "POLYGON((" + bdPolygon2Wgs(station.getgPolygonGrid()) +"))"; | |
| 105 | + sql = "update bsth_c_station set g_lonx=?, g_laty=?,shapes_type='d', radius=null,b_polygon_grid=ST_GeomFromText('"+bdPolygon+"'),g_polygon_grid=ST_GeomFromText('"+wgsPolygon+"') where station_cod=?"; | |
| 106 | + | |
| 107 | + rsCount = jdbcTemplate.update(sql, station.getgLonx(), station.getgLaty(), station.getStationCode()); | |
| 108 | + } | |
| 94 | 109 | |
| 95 | - if(rsCount > 0){ | |
| 96 | - sql = "SELECT t1.*, t2.g_lonx,g_laty,ST_AsText (g_polygon_grid) AS g_polygon_grid,radius,shapes_type FROM (SELECT id,station_name,station_route_code,line_code,station_code,station_mark,versions,directions FROM bsth_c_ls_stationroute WHERE id="+station.getId()+" AND destroy = 0) t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod"; | |
| 97 | - List list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(GeoStation.class)); | |
| 110 | + //从数据库里重新查询对象 | |
| 111 | + if(rsCount > 0){ | |
| 112 | + sql = "SELECT t1.*, t2.g_lonx,g_laty,ST_AsText (g_polygon_grid) AS g_polygon_grid,radius,shapes_type FROM (SELECT id,station_name,station_route_code,line_code,station_code,station_mark,versions,directions FROM bsth_c_ls_stationroute WHERE id="+station.getId()+" AND destroy = 0) t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod"; | |
| 113 | + List<GeoStation> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(GeoStation.class)); | |
| 98 | 114 | |
| 99 | - rs.put("station", list.get(0)); | |
| 100 | - rs.put("status", ResponseCode.SUCCESS); | |
| 115 | + for(GeoStation s : list){ | |
| 116 | + if(s.getShapesType().equals("d")) | |
| 117 | + s.setBdCoords(multiWgsToBd(s.getgPolygonGrid(), 9, 3)); | |
| 101 | 118 | } |
| 119 | + rs.put("station", list.get(0)); | |
| 120 | + rs.put("status", ResponseCode.SUCCESS); | |
| 102 | 121 | } |
| 103 | 122 | |
| 104 | 123 | }catch (Exception e){ |
| ... | ... | @@ -109,22 +128,40 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 109 | 128 | return rs; |
| 110 | 129 | } |
| 111 | 130 | |
| 131 | + | |
| 132 | + private String bdPolygon2Wgs(String bdPolygon){ | |
| 133 | + StringBuilder wgsPolygon = new StringBuilder(); | |
| 134 | + List<String> list = Splitter.on(",").splitToList(bdPolygon); | |
| 135 | + String[] array; | |
| 136 | + | |
| 137 | + TransGPS.Location location; | |
| 138 | + for(String p : list){ | |
| 139 | + array = p.split(" "); | |
| 140 | + location =TransGPS.transformFromGCJToWGS(TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(array[0]), Double.parseDouble(array[1])))); | |
| 141 | + | |
| 142 | + wgsPolygon.append(location.getLng() + " " + location.getLat() + ","); | |
| 143 | + } | |
| 144 | + | |
| 145 | + if(wgsPolygon.length() > 0){ | |
| 146 | + wgsPolygon.deleteCharAt(wgsPolygon.length() - 1); | |
| 147 | + } | |
| 148 | + return wgsPolygon.toString(); | |
| 149 | + } | |
| 150 | + | |
| 112 | 151 | /** |
| 113 | 152 | * wgs 坐标数组转 百度 |
| 114 | 153 | * |
| 115 | 154 | * @return |
| 116 | 155 | */ |
| 117 | - private List<String> multiWgsToBd(String crdStr) { | |
| 156 | + private List<String> multiWgsToBd(String crdStr, int si, int ei) { | |
| 118 | 157 | List<String> bdList = new ArrayList<>(); |
| 119 | 158 | |
| 120 | - List<String> gList = Splitter.on(",").splitToList(crdStr.substring(11, crdStr.length() - 2)); | |
| 159 | + List<String> gList = Splitter.on(",").splitToList(crdStr.substring(si, crdStr.length() - ei)); | |
| 121 | 160 | TransGPS.Location location; |
| 122 | - //StringBuilder itemStr = new StringBuilder(); | |
| 123 | 161 | String[] cds; |
| 124 | 162 | for(String gs : gList){ |
| 125 | 163 | cds = gs.split(" "); |
| 126 | 164 | location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(TransGPS.LocationMake(Double.parseDouble(cds[0]), Double.parseDouble(cds[1])))); |
| 127 | - //itemStr.append(location.getLng() + " " + location.getLat() + ","); | |
| 128 | 165 | |
| 129 | 166 | bdList.add(location.getLng() + " " + location.getLat()); |
| 130 | 167 | } | ... | ... |
src/main/resources/static/assets/js/baidu/bd_GeoUtils_min.js
0 → 100644
| 1 | +var BMapLib=window.BMapLib=BMapLib||{};(function(){var a=6370996.81;var b=BMapLib.GeoUtils=function(){};b.isPointInRect=function(f,g){if(!(f instanceof BMap.Point)||!(g instanceof BMap.Bounds)){return false}var e=g.getSouthWest();var h=g.getNorthEast();return(f.lng>=e.lng&&f.lng<=h.lng&&f.lat>=e.lat&&f.lat<=h.lat)};b.isPointInCircle=function(e,h){if(!(e instanceof BMap.Point)||!(h instanceof BMap.Circle)){return false}var i=h.getCenter();var g=h.getRadius();var f=b.getDistance(e,i);if(f<=g){return true}else{return false}};b.isPointOnPolyline=function(f,h){if(!(f instanceof BMap.Point)||!(h instanceof BMap.Polyline)){return false}var e=h.getBounds();if(!this.isPointInRect(f,e)){return false}var m=h.getPath();for(var k=0;k<m.length-1;k++){var l=m[k];var j=m[k+1];if(f.lng>=Math.min(l.lng,j.lng)&&f.lng<=Math.max(l.lng,j.lng)&&f.lat>=Math.min(l.lat,j.lat)&&f.lat<=Math.max(l.lat,j.lat)){var g=(l.lng-f.lng)*(j.lat-f.lat)-(j.lng-f.lng)*(l.lat-f.lat);if(g<2e-10&&g>-2e-10){return true}}}return false};b.isPointInPolygon=function(o,l){if(!(o instanceof BMap.Point)||!(l instanceof BMap.Polygon)){return false}var k=l.getBounds();if(!this.isPointInRect(o,k)){return false}var t=l.getPath();var h=t.length;var n=true;var j=0;var g=2e-10;var s,q;var e=o;s=t[0];for(var f=1;f<=h;++f){if(e.equals(s)){return n}q=t[f%h];if(e.lat<Math.min(s.lat,q.lat)||e.lat>Math.max(s.lat,q.lat)){s=q;continue}if(e.lat>Math.min(s.lat,q.lat)&&e.lat<Math.max(s.lat,q.lat)){if(e.lng<=Math.max(s.lng,q.lng)){if(s.lat==q.lat&&e.lng>=Math.min(s.lng,q.lng)){return n}if(s.lng==q.lng){if(s.lng==e.lng){return n}else{++j}}else{var r=(e.lat-s.lat)*(q.lng-s.lng)/(q.lat-s.lat)+s.lng;if(Math.abs(e.lng-r)<g){return n}if(e.lng<r){++j}}}}else{if(e.lat==q.lat&&e.lng<=q.lng){var m=t[(f+1)%h];if(e.lat>=Math.min(s.lat,m.lat)&&e.lat<=Math.max(s.lat,m.lat)){++j}else{j+=2}}}s=q}if(j%2==0){return false}else{return true}};b.degreeToRad=function(e){return Math.PI*e/180};b.radToDegree=function(e){return(180*e)/Math.PI};function d(g,f,e){if(f!=null){g=Math.max(g,f)}if(e!=null){g=Math.min(g,e)}return g}function c(g,f,e){while(g>e){g-=e-f}while(g<f){g+=e-f}return g}b.getDistance=function(j,h){if(!(j instanceof BMap.Point)||!(h instanceof BMap.Point)){return 0}j.lng=c(j.lng,-180,180);j.lat=d(j.lat,-74,74);h.lng=c(h.lng,-180,180);h.lat=d(h.lat,-74,74);var f,e,i,g;f=b.degreeToRad(j.lng);i=b.degreeToRad(j.lat);e=b.degreeToRad(h.lng);g=b.degreeToRad(h.lat);return a*Math.acos((Math.sin(i)*Math.sin(g)+Math.cos(i)*Math.cos(g)*Math.cos(e-f)))};b.getPolylineDistance=function(f){if(f instanceof BMap.Polyline||f instanceof Array){var l;if(f instanceof BMap.Polyline){l=f.getPath()}else{l=f}if(l.length<2){return 0}var j=0;for(var h=0;h<l.length-1;h++){var k=l[h];var g=l[h+1];var e=b.getDistance(k,g);j+=e}return j}else{return 0}};b.getPolygonArea=function(t){if(!(t instanceof BMap.Polygon)&&!(t instanceof Array)){return 0}var R;if(t instanceof BMap.Polygon){R=t.getPath()}else{R=t}if(R.length<3){return 0}var w=0;var D=0;var C=0;var L=0;var J=0;var F=0;var E=0;var S=0;var H=0;var p=0;var T=0;var I=0;var q=0;var e=0;var M=0;var v=0;var K=0;var N=0;var s=0;var O=0;var l=0;var g=0;var z=0;var Q=0;var G=0;var j=0;var A=0;var o=0;var m=0;var y=0;var x=0;var h=0;var k=0;var f=0;var n=a;var B=R.length;for(var P=0;P<B;P++){if(P==0){D=R[B-1].lng*Math.PI/180;C=R[B-1].lat*Math.PI/180;L=R[0].lng*Math.PI/180;J=R[0].lat*Math.PI/180;F=R[1].lng*Math.PI/180;E=R[1].lat*Math.PI/180}else{if(P==B-1){D=R[B-2].lng*Math.PI/180;C=R[B-2].lat*Math.PI/180;L=R[B-1].lng*Math.PI/180;J=R[B-1].lat*Math.PI/180;F=R[0].lng*Math.PI/180;E=R[0].lat*Math.PI/180}else{D=R[P-1].lng*Math.PI/180;C=R[P-1].lat*Math.PI/180;L=R[P].lng*Math.PI/180;J=R[P].lat*Math.PI/180;F=R[P+1].lng*Math.PI/180;E=R[P+1].lat*Math.PI/180}}S=Math.cos(J)*Math.cos(L);H=Math.cos(J)*Math.sin(L);p=Math.sin(J);T=Math.cos(C)*Math.cos(D);I=Math.cos(C)*Math.sin(D);q=Math.sin(C);e=Math.cos(E)*Math.cos(F);M=Math.cos(E)*Math.sin(F);v=Math.sin(E);K=(S*S+H*H+p*p)/(S*T+H*I+p*q);N=(S*S+H*H+p*p)/(S*e+H*M+p*v);s=K*T-S;O=K*I-H;l=K*q-p;g=N*e-S;z=N*M-H;Q=N*v-p;m=(g*s+z*O+Q*l)/(Math.sqrt(g*g+z*z+Q*Q)*Math.sqrt(s*s+O*O+l*l));m=Math.acos(m);G=z*l-Q*O;j=0-(g*l-Q*s);A=g*O-z*s;if(S!=0){o=G/S}else{if(H!=0){o=j/H}else{o=A/p}}if(o>0){y+=m;k++}else{x+=m;h++}}var u,r;u=y+(2*Math.PI*h-x);r=(2*Math.PI*k-y)+x;if(y>x){if((u-(B-2)*Math.PI)<1){f=u}else{f=r}}else{if((r-(B-2)*Math.PI)<1){f=r}else{f=u}}w=(f-(B-2)*Math.PI)*n*n;return w}})(); | |
| 0 | 2 | \ No newline at end of file | ... | ... |
src/main/resources/static/pages/base/geo_data_edit/fragments/f_station_route.html
| ... | ... | @@ -75,7 +75,7 @@ |
| 75 | 75 | <option value="r" {{shapesType=='r'?'selected':''}}>圆形</option> |
| 76 | 76 | <option value="d" {{shapesType=='d'?'selected':''}}>多边形</option> |
| 77 | 77 | </select> |
| 78 | - <span class="draw_polygon_switch" data-type="1"><a>暂停绘制</a></span> | |
| 78 | + <span class="draw_polygon_switch" data-type="{{shapesType=='d'?'3':'1'}}"><a>{{shapesType=='d'?'重新绘制':'暂停绘制'}}</a></span> | |
| 79 | 79 | </div> |
| 80 | 80 | <div class="uk-inline"> |
| 81 | 81 | <span class="uk-form-icon uk-form-icon-flip" >半径</span> | ... | ... |
src/main/resources/static/pages/base/geo_data_edit/js/map.js
| ... | ... | @@ -21,6 +21,7 @@ var gb_ct_map = function () { |
| 21 | 21 | var map_status=0; |
| 22 | 22 | var editCircle; |
| 23 | 23 | var editPolygon; |
| 24 | + var dragMarker; | |
| 24 | 25 | |
| 25 | 26 | map = new BMap.Map($(gb_map_consts.mapContainer)[0], {enableMapClick: false}); |
| 26 | 27 | //中心点和缩放级别 |
| ... | ... | @@ -65,6 +66,7 @@ var gb_ct_map = function () { |
| 65 | 66 | marker=createStationMark(this); |
| 66 | 67 | marker.stationCode = this.stationCode; |
| 67 | 68 | marker.ct_data = this; |
| 69 | + marker.ct_source='1'; | |
| 68 | 70 | map.addOverlay(marker); |
| 69 | 71 | |
| 70 | 72 | array.push(marker); |
| ... | ... | @@ -93,6 +95,7 @@ var gb_ct_map = function () { |
| 93 | 95 | polyline = new BMap.Polyline(pos, style); |
| 94 | 96 | polyline.ct_data = item; |
| 95 | 97 | polyline.ct_data.oldColor = color; |
| 98 | + polyline.ct_source='1'; | |
| 96 | 99 | map.addOverlay(polyline); |
| 97 | 100 | |
| 98 | 101 | polyline.addEventListener('mouseover', function(){ |
| ... | ... | @@ -290,7 +293,7 @@ var gb_ct_map = function () { |
| 290 | 293 | |
| 291 | 294 | var cp = calcCenterPoint(p.ct_data.bdCoords); |
| 292 | 295 | openRoadInfoWin(p, new BMap.Point(cp.longitude, cp.latitude)); |
| 293 | - } | |
| 296 | + }; | |
| 294 | 297 | |
| 295 | 298 | var calcCenterPoint = function (coords) { |
| 296 | 299 | var array = [], strs; |
| ... | ... | @@ -300,14 +303,18 @@ var gb_ct_map = function () { |
| 300 | 303 | } |
| 301 | 304 | |
| 302 | 305 | return geolib.getCenter(array); |
| 303 | - } | |
| 306 | + }; | |
| 304 | 307 | |
| 305 | 308 | var exitEditBufferStatus = function (s) { |
| 306 | 309 | map_status = 0; |
| 307 | 310 | enabledOtherElem(); |
| 308 | 311 | gb_station_route.hideEditPanel(); |
| 309 | 312 | |
| 310 | - map.removeOverlay(editCircle); | |
| 313 | + clearOtherOverlay(); | |
| 314 | + reSetDragMarker();//关闭marker 拖拽 | |
| 315 | + | |
| 316 | + clearEditBuffer(); | |
| 317 | + //map.removeOverlay(editCircle); | |
| 311 | 318 | |
| 312 | 319 | openStationInfoWin(getStationMarker(s.stationCode, s.directions)); |
| 313 | 320 | }; |
| ... | ... | @@ -321,52 +328,98 @@ var gb_ct_map = function () { |
| 321 | 328 | map.closeInfoWindow();//关闭infoWindow |
| 322 | 329 | gb_station_route.clearFocus(); |
| 323 | 330 | gb_station_route.focus(s); |
| 324 | - clearOldOverlay(); | |
| 325 | 331 | disabledOtherElem(); |
| 326 | 332 | gb_station_route.showEditPanel(s); |
| 327 | 333 | |
| 328 | 334 | var marker = getStationMarker(s.stationCode, s.directions); |
| 335 | + setDragMarker(marker);//站点 点位可拖拽 | |
| 336 | + | |
| 329 | 337 | map.centerAndZoom(marker.point, 18); |
| 330 | 338 | var bElem = openBufferOverlay(marker); |
| 331 | 339 | |
| 332 | 340 | if(s.shapesType=='r'){ |
| 333 | 341 | //lineupdate |
| 334 | 342 | bElem.addEventListener('lineupdate', function (e) { |
| 335 | - //console.log('lineupdatelineupdate', e); | |
| 336 | - //var ec = e.target; | |
| 337 | - //var radius = ec.getRadius().toFixed(2); | |
| 338 | - //console.log('getRadius', ec.getRadius(), radius); | |
| 339 | 343 | gb_station_route.reWriteEditPanel(e.target); |
| 340 | 344 | }); |
| 341 | 345 | } |
| 346 | + else if(s.shapesType=='d'){ | |
| 347 | + //调整多边形 | |
| 348 | + | |
| 349 | + } | |
| 342 | 350 | }; |
| 343 | - | |
| 344 | - var clearOldOverlay = function () { | |
| 345 | - map.removeOverlay(editCircle); | |
| 346 | - map.removeOverlay(editPolygon); | |
| 347 | - } | |
| 351 | + | |
| 352 | + var setDragMarker = function (marker) { | |
| 353 | + marker.enableDragging(); | |
| 354 | + dragMarker = marker; | |
| 355 | + dragMarker._old_point = dragMarker.point; | |
| 356 | + //监听拖拽事件 dragging | |
| 357 | + dragMarker.addEventListener('dragging', dragMarkerDragEvent); | |
| 358 | + }; | |
| 359 | + | |
| 360 | + var dragMarkerDragEvent = function () { | |
| 361 | + if(editPolygon){ | |
| 362 | + if(!BMapLib.GeoUtils.isPointInPolygon(this.point, editPolygon)) | |
| 363 | + dragMarker.setPosition(dragMarker._old_point);//还原位置 | |
| 364 | + | |
| 365 | + gb_station_route.reWriteEditPanel(this, true); | |
| 366 | + } | |
| 367 | + else if(editCircle){ | |
| 368 | + editCircle.disableEditing(); | |
| 369 | + //缓冲区跟随点位运动 | |
| 370 | + editCircle.setCenter(this.point); | |
| 371 | + editCircle.enableEditing(); | |
| 372 | + } | |
| 373 | + }; | |
| 374 | + | |
| 375 | + var reSetDragMarker = function () { | |
| 376 | + if(dragMarker){ | |
| 377 | + dragMarker.setPosition(dragMarker._old_point); | |
| 378 | + dragMarker.removeEventListener('dragging', dragMarkerDragEvent); | |
| 379 | + dragMarker.disableDragging(); | |
| 380 | + dragMarker = null; | |
| 381 | + } | |
| 382 | + }; | |
| 383 | + | |
| 384 | + | |
| 385 | +/* var removeDragMarkerEvent = function () { | |
| 386 | + dragMarker.removeEventListener('dragging', dragMarkerDragEvent); | |
| 387 | + };*/ | |
| 348 | 388 | |
| 349 | 389 | /** |
| 350 | 390 | * 禁用其他元素 |
| 351 | 391 | */ |
| 352 | 392 | var disabledOtherElem = function () { |
| 353 | 393 | $('.main_left_panel_m_layer').show(); |
| 354 | - } | |
| 394 | + }; | |
| 355 | 395 | |
| 356 | 396 | var enabledOtherElem = function () { |
| 357 | 397 | $('.main_left_panel_m_layer').hide(); |
| 358 | - } | |
| 398 | + }; | |
| 359 | 399 | |
| 360 | 400 | var openBufferOverlay = function (m) { |
| 361 | 401 | var elem; |
| 362 | 402 | var data = m.ct_data; |
| 363 | 403 | if(data.shapesType=='r'){ |
| 364 | - var circle = new BMap.Circle(m.point,data.radius, {strokeColor: '#E91E63'/*updownColor(data.directions)*/}); | |
| 365 | - map.addOverlay(circle); | |
| 366 | - circle.enableEditing(); | |
| 404 | + elem = new BMap.Circle(m.point,data.radius, {strokeColor: '#E91E63'/*updownColor(data.directions)*/}); | |
| 405 | + editCircle = elem; | |
| 367 | 406 | } |
| 368 | - editCircle = circle; | |
| 369 | - return circle; | |
| 407 | + else if(data.shapesType=='d'){ | |
| 408 | + var array = data.bdCoords; | |
| 409 | + var pos = []; | |
| 410 | + var temp = []; | |
| 411 | + for(var i=0,c;c=array[i++];){ | |
| 412 | + temp = c.split(' '); | |
| 413 | + pos.push(new BMap.Point(temp[0], temp[1])); | |
| 414 | + } | |
| 415 | + | |
| 416 | + elem = new BMap.Polygon(pos); | |
| 417 | + editPolygon = elem; | |
| 418 | + } | |
| 419 | + | |
| 420 | + map.addOverlay(elem); | |
| 421 | + elem.enableEditing(); | |
| 422 | + return elem; | |
| 370 | 423 | }; |
| 371 | 424 | |
| 372 | 425 | /** |
| ... | ... | @@ -379,6 +432,8 @@ var gb_ct_map = function () { |
| 379 | 432 | transCoord(s); |
| 380 | 433 | m.ct_data = s; |
| 381 | 434 | m.setPosition(new BMap.Point(s.bd_lon, s.bd_lat)); |
| 435 | + m._old_point = this.point; | |
| 436 | + m.disableDragging(); | |
| 382 | 437 | } |
| 383 | 438 | |
| 384 | 439 | var topOverlay; |
| ... | ... | @@ -395,29 +450,82 @@ var gb_ct_map = function () { |
| 395 | 450 | */ |
| 396 | 451 | var _drawingManager; |
| 397 | 452 | var changeShapeType = function (v) { |
| 398 | - if(v == 'd'){ | |
| 399 | - map.removeOverlay(editCircle); | |
| 453 | + clearEditBuffer(); | |
| 400 | 454 | |
| 455 | + if(v == 'd'){ | |
| 401 | 456 | _drawingManager = new BMapLib.DrawingManager(map,{}); |
| 402 | 457 | _drawingManager.open(); |
| 458 | + _drawingManager.enableCalculate(); | |
| 403 | 459 | _drawingManager.setDrawingMode('polygon'); |
| 404 | 460 | |
| 405 | 461 | //绘制结束事件 |
| 406 | - _drawingManager.addEventListener('polygoncomplete', function (e) { | |
| 407 | - console.log('end ', e); | |
| 462 | + _drawingManager.addEventListener('overlaycomplete', function (e) { | |
| 463 | + editPolygon = e.overlay; | |
| 408 | 464 | gb_station_route.drawEnd(); |
| 409 | 465 | }); |
| 410 | 466 | } |
| 467 | + else if(v == 'r'){ | |
| 468 | + updateDragRadius(80); | |
| 469 | + /*map.removeOverlay(editCircle); | |
| 470 | + map.removeOverlay(editPolygon); | |
| 471 | + | |
| 472 | + //以站点为中心,生成一个默认的圆 | |
| 473 | + var marker = getStationMarker(s.stationCode, s.directions); | |
| 474 | + editCircle = new BMap.Circle(marker.point,s.radius?s.radius:50, {strokeColor: '#E91E63'}); | |
| 475 | + editCircle.enableEditing(); | |
| 476 | + map.addOverlay(editCircle);*/ | |
| 477 | + } | |
| 478 | + }; | |
| 479 | + | |
| 480 | + var clearEditBuffer = function () { | |
| 481 | + map.removeOverlay(editCircle); | |
| 482 | + map.removeOverlay(editPolygon); | |
| 483 | + editCircle = null; | |
| 484 | + editPolygon = null; | |
| 485 | + }; | |
| 486 | + | |
| 487 | + var updateDragRadius = function (radius) { | |
| 488 | + if(!editCircle){ | |
| 489 | + clearOtherOverlay(); | |
| 490 | + var s = gb_station_route.getRealEditStation(); | |
| 491 | + | |
| 492 | + //以站点为中心,生成一个默认的圆 | |
| 493 | + var marker = getStationMarker(s.stationCode, s.directions); | |
| 494 | + var circle = new BMap.Circle(marker.point,s.radius?s.radius:80, {strokeColor: '#E91E63'}); | |
| 495 | + | |
| 496 | + setTimeout(function () { | |
| 497 | + circle.enableEditing(); | |
| 498 | + }, 200); | |
| 499 | + map.addOverlay(circle); | |
| 500 | + | |
| 501 | + editCircle = circle; | |
| 502 | + } | |
| 503 | + | |
| 504 | + editCircle.setRadius(radius); | |
| 411 | 505 | }; |
| 412 | 506 | |
| 413 | 507 | var exitDrawStatus = function () { |
| 414 | - if(_drawingManager) | |
| 508 | + if(_drawingManager){ | |
| 509 | + clearOtherOverlay(); | |
| 415 | 510 | _drawingManager.close(); |
| 511 | + } | |
| 416 | 512 | }; |
| 417 | 513 | |
| 418 | 514 | var openDrawStatus = function () { |
| 419 | - if(_drawingManager) | |
| 515 | + if(_drawingManager){ | |
| 516 | + clearOtherOverlay(); | |
| 420 | 517 | _drawingManager.open(); |
| 518 | + } | |
| 519 | + }; | |
| 520 | + | |
| 521 | + var clearOtherOverlay = function () { | |
| 522 | + var all = map.getOverlays(); | |
| 523 | + for(var i=0,obj; obj=all[i++];){ | |
| 524 | + if(obj.ct_source && obj.ct_source=='1') | |
| 525 | + continue; | |
| 526 | + map.removeOverlay(obj); | |
| 527 | + //obj = null; | |
| 528 | + } | |
| 421 | 529 | }; |
| 422 | 530 | res_load_ep.emitLater('load_map'); |
| 423 | 531 | return { |
| ... | ... | @@ -430,6 +538,10 @@ var gb_ct_map = function () { |
| 430 | 538 | exitEditBufferStatus: exitEditBufferStatus, |
| 431 | 539 | changeShapeType: changeShapeType, |
| 432 | 540 | exitDrawStatus: exitDrawStatus, |
| 433 | - openDrawStatus: openDrawStatus | |
| 541 | + openDrawStatus: openDrawStatus, | |
| 542 | + getDrawPolygon: function () { | |
| 543 | + return editPolygon; | |
| 544 | + }, | |
| 545 | + updateDragRadius: updateDragRadius | |
| 434 | 546 | }; |
| 435 | 547 | }(); |
| 436 | 548 | \ No newline at end of file | ... | ... |
src/main/resources/static/pages/base/geo_data_edit/js/station_route.js
| ... | ... | @@ -77,9 +77,11 @@ var gb_station_route = function () { |
| 77 | 77 | return null; |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | + var realEditStation; | |
| 80 | 81 | var callbackHandler = { |
| 81 | 82 | edit_buffer: function (station) { |
| 82 | 83 | //编辑缓冲区 |
| 84 | + realEditStation = station; | |
| 83 | 85 | gb_ct_map.editStationBuffer(station); |
| 84 | 86 | } |
| 85 | 87 | }; |
| ... | ... | @@ -123,7 +125,7 @@ var gb_station_route = function () { |
| 123 | 125 | |
| 124 | 126 | var edPanelRunFlag; |
| 125 | 127 | var ecObj; |
| 126 | - var reWriteEditPanel = function (ec) { | |
| 128 | + var reWriteEditPanel = function (ec, isPolygon) { | |
| 127 | 129 | if(edPanelRunFlag){ |
| 128 | 130 | ecObj = ec; |
| 129 | 131 | return; |
| ... | ... | @@ -132,9 +134,14 @@ var gb_station_route = function () { |
| 132 | 134 | edPanelRunFlag = true; |
| 133 | 135 | setTimeout(function () { |
| 134 | 136 | var panel = $('.buffer_edit_panel'); |
| 135 | - $('[name=radius]', panel).val(parseInt(ecObj.getRadius()));//半径 | |
| 137 | + var p; | |
| 138 | + if(!isPolygon){ | |
| 139 | + $('[name=radius]', panel).val(parseInt(ecObj.getRadius()));//半径 | |
| 140 | + p = ecObj.getCenter(); | |
| 141 | + }else{ | |
| 142 | + p = ecObj.point; | |
| 143 | + } | |
| 136 | 144 | |
| 137 | - var p = ecObj.getCenter(); | |
| 138 | 145 | $('[name=gLaty]', panel).val(p.lat); |
| 139 | 146 | $('[name=gLonx]', panel).val(p.lng); |
| 140 | 147 | edPanelRunFlag = false; |
| ... | ... | @@ -146,16 +153,18 @@ var gb_station_route = function () { |
| 146 | 153 | for(var i=0,item; item=array[i++];){ |
| 147 | 154 | if(item.stationCode==s.stationCode){ |
| 148 | 155 | s.index = i; |
| 149 | - array.splice(i, 1, s); | |
| 156 | + array.splice(i - 1, 1, s); | |
| 150 | 157 | break; |
| 151 | 158 | } |
| 152 | 159 | } |
| 153 | 160 | }; |
| 154 | 161 | |
| 162 | + | |
| 163 | + var $editWrap = '.buffer_edit_panel>.buffer_edit_body'; | |
| 155 | 164 | /** |
| 156 | 165 | * 缓冲区编辑 取消 |
| 157 | 166 | */ |
| 158 | - $(document).on('click', '.buffer_edit_panel>.buffer_edit_body button.cancel', function (e) { | |
| 167 | + $(document).on('click', $editWrap + ' button.cancel', function (e) { | |
| 159 | 168 | var f = $(this).parents('form'); |
| 160 | 169 | var data = f.serializeJSON(); |
| 161 | 170 | |
| ... | ... | @@ -165,26 +174,38 @@ var gb_station_route = function () { |
| 165 | 174 | /** |
| 166 | 175 | * 缓冲区编辑 切换缓冲区类型(圆形,多边形) |
| 167 | 176 | */ |
| 168 | - $(document).on('click', '.buffer_edit_panel>.buffer_edit_body select[name=shapesType]', function (e) { | |
| 177 | + $(document).on('change', $editWrap +' select[name=shapesType]', function (e) { | |
| 169 | 178 | var v = $(this).val(); |
| 170 | - | |
| 171 | - gb_ct_map.changeShapeType(v); | |
| 172 | 179 | if(v=='d'){ |
| 173 | 180 | $('.buffer_edit_panel .shapes_type').addClass('st_d'); |
| 174 | - | |
| 175 | - | |
| 176 | - // | |
| 177 | - //UIkit.notification("使用鼠标在地图上绘制多边形,可点击上发“暂停绘制”链接,退出绘制模式,以拖拽地图", {status: 'primary', pos: 'bottom-center'}) | |
| 178 | 181 | } |
| 179 | 182 | else{ |
| 180 | 183 | $('.buffer_edit_panel .shapes_type').removeClass('st_d'); |
| 184 | + $('input[name=radius]', $editWrap).val(80); | |
| 181 | 185 | } |
| 186 | + gb_ct_map.changeShapeType(v); | |
| 187 | + }); | |
| 188 | + | |
| 189 | + /** | |
| 190 | + * 半径修改 | |
| 191 | + */ | |
| 192 | + var update_radius_flag, update_radius; | |
| 193 | + $(document).on('input', $editWrap +' input[name=radius]', function (e) { | |
| 194 | + update_radius = $(this).val(); | |
| 195 | + if(update_radius_flag){ | |
| 196 | + return; | |
| 197 | + } | |
| 198 | + update_radius_flag = true; | |
| 199 | + setTimeout(function () { | |
| 200 | + gb_ct_map.updateDragRadius(update_radius); | |
| 201 | + update_radius_flag = false; | |
| 202 | + }, 180); | |
| 182 | 203 | }); |
| 183 | 204 | |
| 184 | 205 | /** |
| 185 | 206 | * 缓冲区编辑 切换绘制模式 |
| 186 | 207 | */ |
| 187 | - var drawPolygonSwitch = '.buffer_edit_panel>.buffer_edit_body .draw_polygon_switch'; | |
| 208 | + var drawPolygonSwitch = $editWrap +' .draw_polygon_switch'; | |
| 188 | 209 | $(document).on('click', drawPolygonSwitch, function (e) { |
| 189 | 210 | var type = $(this).data('type'); |
| 190 | 211 | if(type==1){ |
| ... | ... | @@ -196,6 +217,10 @@ var gb_station_route = function () { |
| 196 | 217 | gb_ct_map.openDrawStatus(); |
| 197 | 218 | $(this).data('type', 1).find('a').text('暂停绘制'); |
| 198 | 219 | } |
| 220 | + else if(type==3){ | |
| 221 | + gb_ct_map.changeShapeType('d'); | |
| 222 | + $(this).data('type', 1).find('a').text('暂停绘制'); | |
| 223 | + } | |
| 199 | 224 | }); |
| 200 | 225 | |
| 201 | 226 | /** |
| ... | ... | @@ -221,6 +246,9 @@ var gb_station_route = function () { |
| 221 | 246 | hideEditPanel: hideEditPanel, |
| 222 | 247 | reWriteEditPanel: reWriteEditPanel, |
| 223 | 248 | update: update, |
| 224 | - drawEnd: drawEnd | |
| 249 | + drawEnd: drawEnd, | |
| 250 | + getRealEditStation: function () { | |
| 251 | + return realEditStation; | |
| 252 | + } | |
| 225 | 253 | }; |
| 226 | 254 | }(); |
| 227 | 255 | \ No newline at end of file | ... | ... |
src/main/resources/static/pages/base/geo_data_edit/js/submit.js
| ... | ... | @@ -10,13 +10,27 @@ var gb_data_submit = function () { |
| 10 | 10 | var f = $(this).parents('form'); |
| 11 | 11 | var data = f.serializeJSON(); |
| 12 | 12 | UIkit.modal.confirm('确定保存【'+data.stationName+'】的缓冲区信息?').then(function() { |
| 13 | + if(data.shapesType=='d'){ | |
| 14 | + var polygon = gb_ct_map.getDrawPolygon(); | |
| 15 | + if(null == polygon){ | |
| 16 | + alert('失败,无法获取到 polygon..'); | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + var pos = polygon.getPath(); | |
| 20 | + //闭合 | |
| 21 | + pos.push(pos[0]); | |
| 22 | + var gPolygonGrid = ''; | |
| 23 | + for(var i=0,p;p=pos[i++];){ | |
| 24 | + gPolygonGrid += (p.lng + " " + p.lat + ","); | |
| 25 | + } | |
| 26 | + data.gPolygonGrid = gPolygonGrid.substr(0, gPolygonGrid.length - 1); | |
| 27 | + } | |
| 13 | 28 | |
| 14 | - //console.log('aaa',f, f.serializeJSON()); | |
| 29 | + //gb_ct_map.removeDragMarkerEvent(); | |
| 15 | 30 | show_run_text('正在提交缓冲区信息'); |
| 16 | 31 | gb_common.$post('/_geo_data/updateBufferInfo', data, function (rs) { |
| 17 | 32 | hide_run_text(); |
| 18 | 33 | UIkit.notification("提交成功!", {status: 'success'}); |
| 19 | - | |
| 20 | 34 | //更新前端数据 |
| 21 | 35 | gb_station_route.update(rs.station); |
| 22 | 36 | gb_ct_map.updateStation(rs.station); | ... | ... |
src/main/resources/static/pages/base/geo_data_edit/main.html
| ... | ... | @@ -102,6 +102,8 @@ |
| 102 | 102 | <script src="/real_control_v2/geolib/geolib.js" ></script> |
| 103 | 103 | <!-- jquery contextMenu --> |
| 104 | 104 | <script src="/real_control_v2/assets/js/jquery.contextMenu.min.js" ></script> |
| 105 | +<script src="/assets/js/baidu/bd_GeoUtils_min.js" ></script> | |
| 106 | + | |
| 105 | 107 | <script> |
| 106 | 108 | var $loadPanel = $('body>.loading'); |
| 107 | 109 | //___________________________________ |
| ... | ... | @@ -130,7 +132,7 @@ |
| 130 | 132 | //路段 |
| 131 | 133 | eq.once('init_road', function () { |
| 132 | 134 | gb_road_route.init(g_emit('init_map')) |
| 133 | - }) | |
| 135 | + }); | |
| 134 | 136 | //地图 |
| 135 | 137 | eq.once('init_map', function () { |
| 136 | 138 | gb_ct_map._render(g_emit('end')); | ... | ... |