map.js
5.86 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
/**
* @description TODO(路段限速地图JS模块)
*
* @author bsth@lq
*
* @date 二〇一六年十月二十一日 15:34:33
*
*/
var SectionSpeedVmapWorlds = function() {
/** 路段限速地图JS模块下的全局变量 <mapB:地图对象;drawingManager:鼠标绘制对象;polyUpline:线路走向对象;bitsPolyline:路段对象> */
var mapB = '', drawingManager = '',polyUpline = '',bitsPolyline='';
var overlays = [];
/** 路段限速地图JS模块下的全局变量---鼠标绘制参数
* <strokeColor:边线颜色;
* fillColor:填充颜色。当参数为空时,圆形将没有填充效果;
* strokeWeight: 边线的宽度,以像素为单位
* strokeOpacity:边线透明度,取值范围0 - 1;
* fillOpacity:填充的透明度,取值范围0 - 1;
* strokeStyle:边线的样式,solid或dashed> */
var styleOptions = {strokeColor : "red", fillColor : "red", strokeWeight : 3,strokeOpacity : 0.8,fillOpacity : 0.6, strokeStyle : 'solid'};
/** 鼠标工具参数
* <anchor:位置;
* offset:偏离值;
* scale:工具栏缩放比例;
* drawingModes:工具模型> */
var drawingToolOptions = {anchor : BMAP_ANCHOR_TOP_LEFT, offset : new BMap.Size(80, 5),scale : 0.8,drawingModes:[BMAP_DRAWING_POLYLINE]};
/** 路段限速地图JS模块下的全局变量---鼠标监听时间参数
* <isOpen:是否开启绘制模式;
* enableDrawingTool:是否显示工具栏;
* drawingToolOptions:鼠标工具参数;
* polylineOptions:线的样式> */
var drawingManagerOptions = {isOpen : false,enableDrawingTool : false,drawingToolOptions : drawingToolOptions,polylineOptions : styleOptions,}
/** 鼠标监听事件 */
function addDrawingManagerEvent(e,overlay) {}
/** 地图绘制地图走向参数 */
var polylineOptions = {strokeColor : "blue",strokeWeight : 6,strokeOpacity : 0.5};
/** 自定义标注物图片 */
var icon_target = new BMap.Icon('/pages/base/stationroute/css/img/gjzd.png',new BMap.Size(10, 10));
/** 创建标注物参数 */
var RichMarkerOptions = {"anchor" : new BMap.Size(-10,8), "enableDragging" : true};
var Bmap = {
/** 初始化地图 */
init : function() {
/** 设置中心点 */
var CENTER_POINT = {lng : 121.528733,lat : 31.237425};
/** 百度API Key */
var bdKey = '1TgEKvYqohJyeGXnN6yHSSTb4psOarQw';
/** 初始化百度地图 */
mapB = new BMap.Map("mapContainer",{enableMapClick:false});
/** 中心点和缩放级别 */
mapB.centerAndZoom(new BMap.Point(CENTER_POINT.lng,CENTER_POINT.lat), 15);
/** 启用地图拖拽事件,默认启用(可不写) */
mapB.enableDragging();
/** 启用地图滚轮放大缩小 */
mapB.enableScrollWheelZoom();
/** 禁用鼠标双击放大 */
mapB.disableDoubleClickZoom();
/** 启用键盘上下左右键移动地图 */
mapB.enableKeyboard();
/** 创建鼠标绘制管理类 */
// drawingManager = new BMapLib.DrawingManager(mapB, drawingManagerOptions);
/** 添加绘画完成事件 */
// drawingManager.addEventListener('polylinecomplete', addDrawingManagerEvent);
return mapB;
},
/** 关闭信息窗口 */
closeMapInfoWin:function() {
mapB.closeInfoWindow();
},
/** 在地图上画出线路走向 */
drawingUpline : function (polylineArray,resultdata) {
/** 创建线路走向 */
polyUpline = new BMap.Polyline(polylineArray,polylineOptions);
/** 把折线添加到地图上 */
mapB.addOverlay(polyUpline);
var ceter_index = Math.round(resultdata.length / 2);
var ceterPointsStr = resultdata[ceter_index].bJwpoints;
var ceterPointsArray = ceterPointsStr.split(' ');
var polyline_center = new BMap.Point(ceterPointsArray[0],ceterPointsArray[1]);
var PanOptions_ ={noAnimation :true};
mapB.reset();
mapB.panTo(polyline_center,PanOptions_);
mapB.setZoom(14);
},
/** 在地图上画出路段 */
drawingSecitons : function(polylineArray) {
/** 创建路段 */
bitsPolyline = new BMap.Polyline(polylineArray, {strokeColor : "red",strokeWeight : 6,strokeOpacity : 0.5});
/** 把路段添加到地图上 */
mapB.addOverlay(bitsPolyline);
},
/** 在地图上画点 @param:<point_center:中心坐标点> */
drawingUpStationPoint : function(point_center,stationName,s) {
var html2 = '<div style="position: absolute; margin: 0pt; padding: 0pt; width: 160px; height: 26px; left: -10px; top: -35px; overflow: hidden;">'
+ '<img class="rm3_image" style="border:none;left:0px; top:0px; position:absolute;" src="/pages/base/stationroute/css/img/back160.png">'
+ '</div>'
+ '<label class=" BMapLabel" unselectable="on" style="position: absolute; -moz-user-select: none; display: inline; cursor: inherit; border: 0px none; padding: 2px 1px 1px; white-space: nowrap; font: 12px arial,simsun; z-index: 80; color: rgb(255, 102, 0); left: 15px; top: -35px;"><span style="float: left; color: #fdfdfd; margin-left: -22px; font-size: 6px;">'+ s+'</span>'+ stationName+'</label>';
var myRichMarker1 = new BMapLib.RichMarker(html2, point_center,RichMarkerOptions);
myRichMarker1.disableDragging();
mapB.addOverlay(myRichMarker1);
/** 创建标注物 */
marker = new BMap.Marker(point_center,{icon : icon_target});
/** 允许覆盖物在map.clearOverlays方法中被清除。 */
marker.enableMassClear();
/** 添加 */
mapB.addOverlay(marker);
},
/** 清除地图覆盖物 */
clearMarkAndOverlays : function() {
// 清楚地图覆盖物
mapB.clearOverlays();
mapB.removeOverlay();
}
}
return Bmap;
}();