section-operation.js
6.44 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
var SectionOperation = function () {
var map, type = 0, editSection;
var operation = {
initMap: function() {
//var CENTER_POINT = {lng: 121.528733,lat: 31.237425};
map = new BMap.Map('map_section');
map.centerAndZoom('成都', 15);
map.enableDragging();
map.enableScrollWheelZoom();
map.disableDoubleClickZoom();
map.enableKeyboard();
},
initSection: function() {
operation.initMap();
type = 0;
var sectionId = $.url().param('no');
SectionService.getSectionById(sectionId,function(section) {
if (section) {
operation.drawSection(section);
}
});
},
initSections: function () {
operation.initMap();
type = 1;
var sectionName = $.url().param('no');
if (sectionName) {
SectionService.findSectionByName(sectionName, function (sections) {
sections.forEach(function(section) {
operation.drawSection(section);
})
})
}
},
initEventBind: function () {
$('#backUp').on('click',function() {
loadPage('/pages/base/section/list.html');
});
},
setSectionFormValue : function(section) {
$('#edit_section_form input,select,textarea').each(function(){
if (this.name) {
$(this).val(section[this.name]);
}
})
},
recoverPolylineColor: function() {
var overlays = map.getOverlays();
overlays.forEach(function (overlay) {
if (overlay.cdata && overlay.cdata.id) {
overlay.setStrokeColor('#5298ff');
}
});
},
refreshPolylineData: function () {
if (!type) {
operation.initSection();
} else {
operation.initSections();
}
},
drawSection : function(section) {
var bsectionVectorWkt = section.bsectionVectorWkt;
bsectionVectorWkt = bsectionVectorWkt.substring(11, bsectionVectorWkt.length - 1);
var coordinates = bsectionVectorWkt.split(',');
var centerPoint, points = new Array();
var clen = coordinates.length, middle = Math.ceil(clen / 2);
for(var i = 0;i < clen;i++) {
var coordinate = coordinates[i].split(' ');
points.push(new BMap.Point(coordinate[0], coordinate[1]));
if (i == middle) {
centerPoint = new BMap.Point(coordinate[0], coordinate[1])
}
}
var polyline = new BMap.Polyline(points, {strokeColor : "#5298ff",strokeWeight : 6,strokeOpacity :1,strokeStyle:'solid'});
polyline.cdata = section;
map.addOverlay(polyline);
var opts = {
width: 200,
height: 350,
offset: new BMap.Size(0, 0),
title: '<h4 style="color:#FFFFFF">' + (section.sectionName ? section.sectionName : '') + ' 路段详情</h4>',
enableMessage: false,
enableCloseOnClick: true,
enableAutoPan: true
};
var html = new Array();
html.push('<HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>');
html.push('<span style="color:#DDD;font-size: 15px;">路段名称:');html.push(section.sectionName);html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">路段编码:');html.push(section.sectionCode);html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">交叉路段:');html.push(section.crosesRoad);html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">东西向:');html.push((section.ewDirection === undefined ? '' : section.ewDirection == 0 ? '东->西' : '西->东'));html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">南北向:');html.push((section.snDirection === undefined ? '' : section.snDirection == 0 ? '南->北' : '北->南'));html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">路段限速:');html.push(section.speedLimit);html.push('</span>');
html.push('<span class="help-block" style="color:#DDD;font-size: 15px;">路段长度:');html.push(section.sectionDistance);html.push('</span>');
html.push('<button id="editSectionInfo" class="info_win_btn">修改路段信息</button>');
html.push('<button id="movePolyline" class="info_win_btn">移动路段位置</button>');
var infoWindow = new BMap.InfoWindow(html.join(''), opts);
var icon = new BMap.Icon('/pages/base/stationroute/css/img/blank.gif', new BMap.Size(20, 20));
var marker = new BMap.Marker(centerPoint, {icon: icon});
map.addOverlay(marker);
var panOpts = {noAnimation: true};
map.panTo(centerPoint, panOpts);
map.panBy(0, -110, panOpts);
polyline.addEventListener('click', function(event) {
operation.recoverPolylineColor();
var polyline = event.target, path = polyline.getPath();
polyline.setStrokeColor('#FF0000');
map.addOverlay(marker);
marker.setPosition(path[Math.ceil(path.length / 2)]);
marker.openInfoWindow(infoWindow);
$('#editSectionInfo').on('click', function() {
operation.editSection(section.id);
});
$('#movePolyline').on('click', function() {
operation.editPolyline(section.id);
});
});
},
editPolyline : function(sectionId) {
var overlays = map.getOverlays();
overlays.forEach(function (overlay) {
if (overlay.cdata && overlay.cdata.id == sectionId) {
overlay.enableEditing();
overlay.addEventListener('rightclick', operation.confirmPolyline);
layer.msg('拖动路段至相应位置,然后右击确定!');
}
});
},
confirmPolyline: function (event) {
var polyline = event.target;
polyline.removeEventListener('rightclick', operation.confirmPolyline);
polyline.disableEditing();
var points = polyline.getPath(), bsectionVectorWkt = new Array();
for (var i = 0;i < points.length;i++) {
bsectionVectorWkt.push(points[i].lng + ' ' + points[i].lat);
}
SectionService.sectionUpdate({id: polyline.cdata.id, bsectionVectorWkt: 'LINESTRING(' + bsectionVectorWkt.join(',') + ')'}, function(result) {
if (result.status == 'SUCCESS') {
layer.msg('修改成功...');
} else {
layer.msg('修改失败...');
}
});
},
editSection: function(sectionId) {
layer.closeAll();
var overlays = map.getOverlays();
overlays.forEach(function (overlay) {
if (overlay.cdata && overlay.cdata.id == sectionId) {
overlay.disableEditing();
var editPloyLineArray = overlay.getPath();
editSection = overlay.cdata;
$.get('editsection.html', function(m){
$(pjaxContainer).append(m);
$('#edit_section_modal').trigger('modal.show', [SectionOperation, SectionService, editSection]);
});
}
});
},
clearMarkAndOverlays : function() {
map.clearOverlays();
map.removeOverlay();
}
}
return operation;
}();