station-positions-map.js
4.55 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
/**
* 百度地图
*
*/
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: 103.52514, lat: 30.589808};
// 初始化百度地图
mapBValue = new BMap.Map("positionBmap_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;
},
setDragEnable: function() {
marker.enableDragging();
marker.addEventListener('rightclick', Bmap.confirmCenterPoint);
layer.msg('拖动站点至相应位置,然后右击确定中心点!');
},
confirmCenterPoint: function(event) {
marker.disableDragging();
var station = event.target.station, point = event.target.point;
PositionsPublicFunctions.stationUpdate({id: station.id, centerPointWkt: 'POINT(' + point.lng + ' ' + point.lat + ')'}, function () {
layer.msg('已确定中心点!');
marker.removeEventListener('rightclick', Bmap.confirmCenterPoint);
});
},
editStation: function () {
$.get('edit.html', function(m){
$(pjaxContainer).append(m);
$('#edit_station_modal').trigger('modal.show', [StationPositionsWorldsBMap,PositionsPublicFunctions,PositionsStationObj]);
});
},
position : function(station, html, opts) {
// 将视图切换到指定的缩放等级,中心点坐标不变。注意:当有信息窗口在地图上打开时,地图缩放将保证信息窗口所在的坐标位置不动。(自1.2新增)
mapBValue.centerAndZoom(station.point, 17);
// 创建信息窗口
infoWindow = new BMap.InfoWindow(html, opts);
// 创建点
marker = new BMap.Marker(station.point);
marker.station = station;
// 把标注添物加到地图上
mapBValue.addOverlay(marker);
// 是否在平移过程中禁止动画。(自1.2新增)
var options ={noAnimation: true};
// 将地图的中心点更改为给定的点。
mapBValue.panTo(station.point, options);
mapBValue.panBy(10, -250, options);
// 添加标志物监听事件
marker.addEventListener("click",function() {
//开启信息窗口
marker.openInfoWindow(infoWindow, station.point);
$('#editStationInfo').on('click', function() {
StationPositionsWorldsBMap.editStation(station.id);
});
$('#moveCenterPoint').on('click', function() {
StationPositionsWorldsBMap.setDragEnable(true);
});
});
},
// 定位
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;
}();