-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaode-mapSelf.html
196 lines (181 loc) · 7.17 KB
/
gaode-mapSelf.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
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<style type="text/css">
body,
html,
#container {
height: 100%;
margin: 0px;
}
</style>
<title>高德</title>
</head>
<body>
<input type="text" name="" id="" value="" placeholder="请输入站点" />
<button onclick="outputLine()">生成</button>
<div id="container" tabindex="0"></div>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.4&key=ef42fbd3d4b3676cf2f33745f98d0197&plugin=AMap.Transfer"></script>
<script type="text/javascript">
//回车
document.onkeydown=function(event){
var e = event || window.event || arguments.callee.caller.arguments[0];
if(e && e.keyCode==13){ // enter 键
//要做的事情
lineSearch()
}
};
//地铁站线路
var LineList = []
//基础地图构建
var map = new AMap.Map('container', {
resizeEnable: true,
zoom: 12,
center: [116.397573, 39.908743]
});
map.setMapStyle('amap://styles/8c687c6bbb79c87904d211e81ebc0dee');
//公交站点----1号线
var _line1 = [],
_line2 = [],
_line10 = [],
_line4 = [],
line1 = ['苹果园', '古城', '八角游乐园', '八宝山', '玉泉路', '五棵松', '万寿路', '公主坟', '军事博物馆', '木樨地', '南礼士路', '复兴门', '西单', '天安门西', '天安门东', '王府井', '东单', '建国门', '永安里', '国贸', '大望路', '四惠', '四惠东'],
line10 = ['巴沟', '苏州街', '海淀黄庄', '知春里', '知春路', '西土城', '牡丹园', '健德门', '北土城', '安贞门', '惠新西街南口', '芍药居', '太阳宫', '三元桥', '亮马桥', '农业展览馆', '团结湖', '呼家楼', '金台夕照', '国贸', '双井', '劲松', '潘家园', '十里河', '分钟寺', '成寿寺', '宋家庄', '石榴庄', '大红门', '角门东', '角门西', '草桥', '纪家庙', '首经贸', '丰台站地铁站', '泥洼', '西局', '六里桥', '莲花桥', '公主坟', '西钓鱼台', '慈寿寺', '车道沟', '长春桥', '火器营', '巴沟'],
line2 = ['积水潭', '鼓楼大街', '安定门', '雍和宫', '东直门', '东四十条', '朝阳门', '建国门', '北京站', '崇文门', '前门', '和平门', '宣武门', '长椿街', '复兴门', '阜成门', '车公庄', '西直门', '积水潭'],
line4 = ['安河桥北', '北宫门', '西苑', '圆明园', '北京大学东门', '中关村', '海淀黄庄', '人民大学', '魏公村', '国家图书馆', '动物园', '西直门', '新街口', '平安里', '西四', '灵境胡同', '西单', '宣武门', '菜市口', '陶然亭', '北京南站', '马家堡', '角门西', '公益西桥', '新宫', '西红门', '高米店北', '高米店南', '枣园', '清源路', '黄村西大街', '黄村火车站', '义和庄', '生物医药基地', '天宫院']
//增加地铁站后缀
// var flag = 1
for(var i = 0; i < line1.length; i++) {
if(line1[i] !== '南礼士路'){
_line1.push(line1[i] + '地铁站')
}
}
for(var i = 0; i < line2.length; i++) {
_line2.push(line2[i] + '地铁站')
}
for(var i = 0; i < line10.length; i++) {
_line10.push(line10[i] + '地铁站')
}
for(var i = 0; i < line4.length; i++) {
_line4.push(line4[i] + '地铁站')
}
var i = 0
// outPut('南礼士路地铁站','复兴门地铁站')
outPut(_line10[i], _line10[i + 1])
// for(var [keys, value] of _line1){
// console.log(keys)
// console.log(value)
// }
//路线line生成
var lineList = []
function outPut(orig, des) {
console.log(orig)
console.log(des)
//折现
var editor = {};
editor._line = function(LineList) {
if(LineList !== []) {
new AMap.Polyline({
map: map, //要显示该polyline的地图对象
path: lineList, //折线的节点坐标数组
strokeColor: "black", //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 1, //线宽
strokeStyle: "solid", //线样式
lineCap: "round", //折线两端线帽的绘制样式,默认值为'butt'无头,其他可选值:'round'圆头、'square'方头
draggable: false, //设置折线是否可拖拽移动,默认为false
});
console.log(line10.length)
if(i < (_line10.length - 2)) {
console.log(i)
console.log(i)
++i
outPut(_line10[i], _line10[i + 1])
} else if(i == (_line10.length-2)) {
console.log(i+'6666666666666666666666666666666')
console.log(lineList)
console.log(LineList)
finished = true
return
}
}
};
//公交线路查询--基本配置
var transOptions = {
//map: map,
city: '北京市',
// panel: 'panel',
//cityd:'乌鲁木齐',
policy: AMap.TransferPolicy.LEAST_TRANSFER,
};
//构造公交换乘类
var transfer = new AMap.Transfer(transOptions);
//根据起、终点坐标查询公交换乘路线
transfer.search([{
keyword: orig //"苹果园地铁站"//orig
}, {
keyword: des //"古城地铁站"//des
}], function(status, result) {
var plans = result.plans
//plans
console.log(result)
// console.log(plans)
if(status === 'complete' && result.info === 'OK') {
for(var i = 0; i < plans.length; i++) {
//path -- segments
if(!plans[i].segments) {
alert(plans[i].segments)
}
if(plans[i].segments) {
for(var j = 0; j < plans[i].segments.length; j++) {
if(plans[i].segments[j].transit_mode === 'SUBWAY') {
// console.log(plans[i].segments[j].transit_mode)
// console.log(plans[i].path)
// lineList = plans[i].segments[j].transit.path
// console.log(lineList)
//合规的描点数据
plans[i].segments[j].transit.path.forEach(function(value, index, arr) {
// console.log(value)
console.log(LineList)
console.log([value.lng,value.lat])
console.log(LineList)
lineList.push([value.lng,value.lat])
LineList.push([value.lng,value.lat])
})
// for(var item = 0; item < plans[i].segments[j].transit.path.length; item++) {
// console.log(plans[i].segments[j].transit.path.length)
//// if(item == 0){
//// lineList.push([plans[i].segments[j].transit.path[0].lng, plans[i].segments[j].transit.path[0].lat])
////
//
// }
// console.log(lineList)
//合规的描点数据-----集合
// for(var keys = 0; keys < lineList.length; keys++) {
// LineList.push([lineList[keys].lng, lineList[keys].lat])
//
// }
editor._line(lineList)
return
}
}
}
}
}
// console.log(flag++)
});
}
setTimeout(console.log(LineList),8000)
//editor._lineEditor= new AMap.PolyEditor(map, editor._line);
//开始 结束 折现编辑
// function startEditLine(){
// editor._lineEditor.open();
// }
// function closeEditLine(){
// editor._lineEditor.close();
// }
</script>
</body>
</html>