station-positions-map.js
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/**
* 百度地图
*
*/
var StationPositionsWorldsBMap = function () {
var mapBValue = '',marker='',polygon='';
var Bmap = {
init : function() {
// 关闭左侧栏
if (!$('body').hasClass('page-sidebar-closed')) {
$('.menu-toggler.sidebar-toggler').click();
}
// 设置中心点,
var CENTER_POINT = {lng : 121.528733,lat : 31.237425};
// 百度API Key
var bdKey = 'IGGrr4UjwIYzatoCRFKEL8sT';
// 初始化百度地图
mapBValue = new BMap.Map("bmap_basic");
//中心点和缩放级别
mapBValue.centerAndZoom(new BMap.Point(CENTER_POINT.lng,CENTER_POINT.lat), 15);
//启用地图拖拽事件,默认启用(可不写)
mapBValue.enableDragging();
//启用地图滚轮放大缩小
mapBValue.enableScrollWheelZoom();
//禁用鼠标双击放大
mapBValue.disableDoubleClickZoom();
//启用键盘上下左右键移动地图
mapBValue.enableKeyboard();
return mapBValue;
},
// 获取百度地图map值
getMapBValue : function(){
return mapBValue;
},
pointsCircle : function(r,point,htm,opts) {
// 将视图切换到指定的缩放等级,中心点坐标不变。注意:当有信息窗口在地图上打开时,地图缩放将保证信息窗口所在的坐标位置不动。(自1.2新增)
mapBValue.setZoom(17);
//创建圆
circle = new BMap.Circle(point,r[0].stationRadius,{strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});
// 允许覆盖物在map.clearOverlays方法中被清除
circle.enableMassClear();
// 百度地图添加覆盖物圆
mapBValue.addOverlay(circle);
// 创建信息窗口
infoWindow = new BMap.InfoWindow(htm, opts);
// 自定义标注物图片
var icon_target = new BMap.Icon('/pages/base/stationroute/css/img/cz.png',new BMap.Size(20, 20));
// 创建点
marker = new BMap.Marker(point,{icon : icon_target});
// 把标注添物加到地图上
mapBValue.addOverlay(marker);
setTimeout(function(){
//开启信息窗口
marker.openInfoWindow(infoWindow,point);
},100);
// 是否在平移过程中禁止动画。(自1.2新增)
var PanOptions_ ={noAnimation :true};
// 将地图的中心点更改为给定的点。
mapBValue.panTo(point,PanOptions_);
mapBValue.panBy(10,-250,PanOptions_);
// 添加标志物监听事件
marker.addEventListener("click",function() {
//开启信息窗口
marker.openInfoWindow(infoWindow,point);
});
},
pointsPolygon : function(r,pointPolygon,htm,opts_polygon) {
// 获取多边形坐标字符串
var stationBPolygonGrid = r[0].stationBPolyonGrid;
// 截取多边形坐标字符串
var stationBPolygonGridStr = stationBPolygonGrid.substring(9,stationBPolygonGrid.length-2);
// 按逗号切割
var pointPolygonArray = stationBPolygonGridStr.split(',');
// 多边形坐标集合
var polygonP = [];
for(var v = 0;v<pointPolygonArray.length;v++) {
polygonP.push(new BMap.Point(pointPolygonArray[v].split(" ")[0],pointPolygonArray[v].split(" ")[1]));
}
// 画多边形
polygon = new BMap.Polygon(polygonP, {
// 线条显色
strokeColor : "blue",
// 边线的宽度,以像素为单位。
strokeWeight : 2,
// 边线透明度,取值范围0 - 1。
strokeOpacity : 0.5
});
// 增加地图覆盖物多边形
mapBValue.addOverlay(polygon);
// 创建信息窗口
infoWindow = new BMap.InfoWindow(htm, opts_polygon);
// 自定义标注物图片
var icon_target = new BMap.Icon('/pages/base/stationroute/css/img/cz.png',new BMap.Size(20, 20));
// 创建点
marker = new BMap.Marker(pointPolygon,{icon : icon_target});
// 把标注添物加到地图上
mapBValue.addOverlay(marker);
// 是否在平移过程中禁止动画。(自1.2新增)
var PanOptions_ ={noAnimation :true};
// 将地图的中心点更改为给定的点。
mapBValue.panTo(pointPolygon,PanOptions_);
// 将地图在水平位置上移动x像素,垂直位置上移动y像素。
mapBValue.panBy(10,110,PanOptions_);
//开启信息窗口
marker.openInfoWindow(infoWindow,pointPolygon);
},
// 编辑图形
editShapes : function(stationShapesTypeV,mindex) {
// 关闭信息窗口
marker.closeInfoWindow();
// 清除marker
mapBValue.removeOverlay(marker);
// 编辑圆
if(stationShapesTypeV =='r') {
// 开启编辑功能
circle.enableEditing();
// 编辑圆监听事件
circle.addEventListener('dblclick',function() {
// 关闭提示弹出层
layer.close(mindex);
// 返回圆形的半径,单位为米。
var newRadius = circle.getRadius();
// 返回圆形的中心点坐标。
var newCenter = circle.getCenter().lng + ' ' + circle.getCenter().lat;
var centre_New = [{potion:{lng:circle.getCenter().lng,lat:circle.getCenter().lat}}];
/** 设置修改站点集合对象站点中心点百度坐标属性值 @param:<bJwpoints:中心点百度坐标) */
PositionsStationObj.setEitdStationBJwpoints(newCenter);
/** 设置修改站点集合对象范围图形类型属性值 @param:<shapesType:范围图形类型) */
PositionsStationObj.setEitdStationShapesType('r');
/** 设置修改站点集合对象圆形半径属性值 @param:<radius:圆形半径) */
PositionsStationObj.setEitdStationRadius(Math.round(newRadius));
/** 设置修改站点集合对象图形百度坐标集合属性值 @param:<bPolygonGrid:图形百度坐标集合) */
PositionsStationObj.setEitdBPolygonGrid('');
// 加载编辑页面
$.get('edit.html', function(m){
$(pjaxContainer).append(m);
$('#editPoitsions_station_mobal').trigger('editStationMobal_show', [StationPositionsWorldsBMap,PositionsPublicFunctions,PositionsStationObj]);
});
});
// 编辑多变行
}else if(stationShapesTypeV =='d') {
// 开启编辑功能(自 1.1 新增)
polygon.enableEditing();
// 添加多变行编辑事件
polygon.addEventListener('dblclick',function(e) {
// 获取编辑的多边形对象
var edit_pointE = polygon;
var edit_bPloygonGrid = "";
var editPolyGonLen_ = edit_pointE.getPath().length;
for(var k =0;k<editPolyGonLen_;k++) {
if(k==0) {
edit_bPloygonGrid = edit_pointE.getPath()[k].lng + ' ' + edit_pointE.getPath()[k].lat;
}else {
edit_bPloygonGrid = edit_bPloygonGrid + ',' + edit_pointE.getPath()[k].lng + ' ' + edit_pointE.getPath()[k].lat;
}
}
edit_bPloygonGrid = edit_bPloygonGrid + ',' + edit_pointE.getPath()[0].lng + ' ' + edit_pointE.getPath()[0].lat;
// 多边形中心点
var centre_points = edit_pointE.getBounds().getCenter().lng + ' ' + edit_pointE.getBounds().getCenter().lat;
/** 设置修改站点集合对象站点中心点百度坐标属性值 @param:<bJwpoints:中心点百度坐标) */
PositionsStationObj.setEitdStationBJwpoints(centre_points);
/** 设置修改站点集合对象范围图形类型属性值 @param:<shapesType:范围图形类型) */
PositionsStationObj.setEitdStationShapesType('d');
/** 设置修改站点集合对象圆形半径属性值 @param:<radius:圆形半径) */
PositionsStationObj.setEitdStationRadius('');
/** 设置修改站点集合对象图形百度坐标集合属性值 @param:<bPolygonGrid:图形百度坐标集合) */
PositionsStationObj.setEitdBPolygonGrid(edit_bPloygonGrid);
$.get('edit.html', function(m){
$(pjaxContainer).append(m);
$('#editPoitsions_station_mobal').trigger('editStationMobal_show', [StationPositionsWorldsBMap,PositionsPublicFunctions,PositionsStationObj]);
});
});
}
},
localSearchFromAdreesToPoint: function(Address,callback) {
// 创建一个搜索类实例
var localSearch = new BMap.LocalSearch(mapBValue);
// 检索完成后的回调函数。
localSearch.setSearchCompleteCallback(function (searchResult) {
var resultPoints = '';
if(searchResult) {
// 返回索引指定的结果。索引0表示第1条结果
var poi = searchResult.getPoi(0);
if(poi) {
//获取经度和纬度
resultPoints = poi.point.lng + ' ' + poi.point.lat;
callback && callback(resultPoints);
}else {
callback && callback(false);
}
}else {
callback && callback(false);
}
});
// 根据检索词发起检索。
localSearch.search(Address);
},
localtionPoint : function(stationNameV) {
StationPositionsWorldsBMap.localSearchFromAdreesToPoint(stationNameV,function(Points) {
if(Points) {
var BJwpointsArray = Points.split(' ');
var stationNameChangePoint = new BMap.Point(BJwpointsArray[0], BJwpointsArray[1]);
var marker_stargt2 = new BMap.Marker(stationNameChangePoint);
var PanOptions ={noAnimation :true};
mapBValue.panTo(stationNameChangePoint,PanOptions);
mapBValue.panBy(0,-100);
// 将标注添加到地图中
mapBValue.addOverlay(marker_stargt2);
//跳动的动画
marker_stargt2.setAnimation(BMAP_ANIMATION_BOUNCE);
}
});
},
clearMarkAndOverlays : function() {
// 清楚地图覆盖物
mapBValue.clearOverlays();
}
}
return Bmap;
}();