-
Notifications
You must be signed in to change notification settings - Fork 0
/
toShareMap.html
309 lines (268 loc) · 9.72 KB
/
toShareMap.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>公交线路分享</title>
<meta name="Keywords" content=""/>
<meta name="Description" content=""/>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script type="text/javascript"
src="http://webapi.amap.com/maps?v=1.3&key=b16e9282ef90c9c932f32cc705a13b92&plugin=AMap.LineSearch,AMap.Autocomplete,AMap.Transfer"></script>
<script type="text/javascript" src="./js/addToolbar.js"></script>
<script src="js/jquery1.42.min.js" type="text/javascript"></script>
<script>
</script>
<style>
.markerC {
color: #ff0000;
padding: 4px 10px;
white-space: nowrap;
font-size: 14px;
font-family: "";
}
.marker {
color: #ffffff;
white-space: nowrap;
font-size: 12px;
font-family: "";
font-weight:900;
width: 30px;
height: 30px;
border: 1px solid #fff;
text-align: center;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
-o-border-radius:15px;
border-radius:15px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.titleDiv{
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
font-size: 18px;
font-weight:900;
}
.amap-marker .marker-route {
position: absolute;
width: 40px;
height: 44px;
color: #e90000;
background: url(http://webapi.amap.com/theme/v1.3/images/newpc/poi-1.png) no-repeat;
cursor: pointer;
}
.amap-marker .marker-marker-bus-from {
background-position: -334px -180px;
}
.amap-marker .marker-marker-bus-from2 {
background-position: -334px -135px;
}
.copy-tips{position:fixed;z-index:999;bottom:50%;left:50%;margin:0 0 -20px -80px;background-color:rgba(0, 0, 0, 0.2);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr=#30000000, endColorstr=#30000000);padding:6px;}
.copy-tips-wrap{padding:10px 20px;text-align:center;border:1px solid #F4D9A6;background-color:#FFFDEE;font-size:14px;}
</style>
</head>
<body>
<div id="container"></div>
<script language="javascript">
var _isShowStation=GetQueryString('isShowStation');
var _city=GetQueryString('city');
var _lineStr=GetQueryString('lineStr');
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return decodeURI( unescape(r[2])); return null;
}
var color=new Array("#227700","#FF0000","#0000CC","#FF0088","#003377","#5555FF","#FF88C2","#99FF33","#FF7744","#000000","#FFCCCC","#00DDDD","#77FFCC","#FFFF33","#00DD00","#FFAA33","#7A0099","#99BBFF","#66009D","#FF5511");
var city = _city;
var lineStr = _lineStr;
var isShowStation = _isShowStation;
var lineArr = lineStr.split(",");
var poiStr = '';
var poiArr = poiStr.split("|");
var poiLength = poiArr.length-1;
for(var i=0;i<lineArr.length;i++){
lineSearch(color[i],lineArr[i]);
}
/*
* 该示例主要流程分为三个步骤
* 1. 首先调用公交路线查询服务(lineSearch)
* 2. 根据返回结果解析,输出解析结果(lineSearch_Callback)
* 3. 在地图上绘制公交线路()
*/
var map = new AMap.Map("container", {
zoom: 11 //地图显示的缩放级别
});
for(var j=0;j<poiLength;j++){
var dataStr = poiArr[j];
var dataArr = dataStr.split(",");
tradingArea(dataArr[0],dataArr[1],dataArr[2]);
}
/*公交线路查询*/
function lineSearch(colorStyle,lineName) {
cityName = city;
//实例化公交线路查询类,只取回一条路线
var linesearch = new AMap.LineSearch({
pageIndex: 1,
city: cityName,
pageSize: 1,
extensions: 'all'
});
//搜索相关公交线路
linesearch.search(lineName, function(status, result) {
if (status === 'complete' && result.info === 'OK') {
lineSearch_Callback(result,lineName,colorStyle);
} else {
alert("暂无数据");
map.clearMap();
}
});
}
/*公交路线查询服务返回数据解析概况*/
function lineSearch_Callback(data,lineName,colorStyle) {
var lineArr = data.lineInfo;
var lineNum = data.lineInfo.length;
if (lineNum == 0) {
} else {
for (var i = 0; i < lineNum; i++) {
var pathArr = lineArr[i].path;
var stops = lineArr[i].via_stops;
var startPot = stops[0].location;
var endPot = stops[stops.length - 1].location;
for(var j=0;j<stops.length;j++){
var stationMark;
if (isShowStation=="true" && j >0 && j < stops.length-1){
stationMark = new AMap.Marker({
map: map,
position: stops[j].location,
offset:new AMap.Pixel(-18,-13),
icon: new AMap.Icon({
size: new AMap.Size(0,0)
})
});
}else{
stationMark = new AMap.Marker({
map: map,
position: stops[j].location,
offset:new AMap.Pixel(-18,-13),
icon: new AMap.Icon({
size: new AMap.Size(40,40), //图标大小
image: "http://webapi.amap.com/theme/v1.3/images/newpc/way_btn2.png",
imageOffset: new AMap.Pixel(0, -130)
})
});
}
//添加点标记,并使用自己的icon
}
if (i == 0) drawbusLine(startPot, endPot, pathArr,lineName,colorStyle);
}
}
}
/*绘制路线*/
function drawbusLine(startPot, endPot, BusArr,lineName,colorStyle) {
if(lineName.indexOf("路") > 0){
lineName = lineName.substring(0,lineName.indexOf("路"));
}
//绘制起点,终点
var markerStart = new AMap.Marker({
map: map,
position: [startPot.lng, startPot.lat], //基点位置
icon: "http://webapi.amap.com/theme/v1.3/markers/n/start.png",
zIndex: 10
});
var markerContent = document.createElement("div");
markerContent.className = 'titleDiv';
var markerSpan = document.createElement("span");
var txtSpan = document.createElement("span");
markerSpan.className = 'marker';
markerSpan.style.backgroundColor=colorStyle;
markerSpan.innerHTML = lineName;
txtSpan.style.color=colorStyle;
txtSpan.innerHTML = "路";
markerContent.appendChild(markerSpan);
markerContent.appendChild(txtSpan);
markerStart.setContent(markerContent); //更新点标记内容
var markerEnd = new AMap.Marker({
map: map,
position: [endPot.lng, endPot.lat], //基点位置
icon: "http://webapi.amap.com/theme/v1.3/markers/n/end.png",
zIndex: 10
});
var markerContent2 = document.createElement("div2");
markerContent2.className = 'titleDiv';
var markerSpan2 = document.createElement("span2");
var txtSpan2 = document.createElement("span");
markerSpan2.className = 'marker';
markerSpan2.style.backgroundColor=colorStyle;
markerSpan2.innerHTML = lineName;
txtSpan2.style.color=colorStyle;
txtSpan2.innerHTML = "路";
markerContent2.appendChild(markerSpan2);
markerContent2.appendChild(txtSpan2);
markerEnd.setContent(markerContent2); //更新点标记内容
//绘制乘车的路线
busPolyline = new AMap.Polyline({
map: map,
path: BusArr,
strokeColor: colorStyle,//线颜色
strokeOpacity: 1,//线透明度
strokeWeight: 3//线宽
});
map.setFitView();
}
var colorIndex = 0;
var delIndex = 0;
$("#selSearch").click(function(){
var cname = cityName;
var lineName = $("#selectSearch2").val();
//把添加的线路元素加入待分享的数组中
addLineArr(cname,lineName);
lineSearch(color[colorIndex]);
colorIndex++;
//动态添加左侧公交线路对比列表
var cname = cityName;
var lineName = $("#selectSearch2").val();
compArr.push(lineName);
if(cname!=""&&lineName!=""){
var showName = cname+lineName;
var divname = "tmpDiv"+delIndex;
$("#leftList").append("<div class='middle_02' id='"+divname+"'><p><img onclick='delDiv("+delIndex+")' src='http://www.quyaohe.com/img/delete11.png' style='width:15px;height:15px;margin-right:10px;vertical-align:middle;'/>"+showName+"</p></div>");
delIndex++;
}
});
function tradingArea(title,lon,lat){
map.setDefaultCursor("crosshair");
var circle = new AMap.Circle({
center: [lon,lat],// 圆心位置
radius: 1000, //半径
strokeColor: "#F33", //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 2, //线粗细度
fillColor: "#F33", //填充颜色
fillOpacity: 0.35,//填充透明度
strokeStyle:'dashed'
});
circle.setMap(map);
var markerAoti = new AMap.Marker({
icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [lon,lat]
});
markerAoti.setMap(map);
// 点标记中的文本
// 自定义点标记内容
var markerContent3 = document.createElement("div");
var markerSpan3 = document.createElement("span");
markerSpan3.className = 'markerC';
markerSpan3.innerHTML = title;
markerContent3.appendChild(markerSpan3);
markerAoti.setContent(markerContent3);
}
</script>
</body>
</html>