forked from wangshanwen001/ChengDuRentManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
267 lines (246 loc) · 9.73 KB
/
index.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
<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>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/jquery.range.css" />
<script src="http://cache.amap.com/lbs/static/jquery-1.9.1.js"></script>
<script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=22d3816e107f199992666d6412fa0691&plugin=AMap.ArrivalRange,AMap.Scale,AMap.Geocoder,AMap.Transfer,AMap.Autocomplete"></script>
<script src="http://cache.amap.com/lbs/static/jquery.range.js"></script>
<style>
.control-panel {
position: absolute;
top: 30px;
right: 20px;
}
.control-entry {
width: 280px;
background-color: rgba(119, 136, 153, 0.8);
font-family: fantasy, sans-serif;
text-align: left;
color: white;
overflow: auto;
padding: 10px;
margin-bottom: 10px;
}
.control-input {
margin-left: 120px;
}
.control-input input[type="text"] {
width: 160px;
}
.control-panel label {
float: left;
width: 120px;
}
#transfer-panel {
position: absolute;
background-color: white;
max-height: 80%;
overflow-y: auto;
top: 30px;
left: 20px;
width: 250px;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="control-panel">
<div class="control-entry">
<label>选择工作地点:</label>
<div class="control-input">
<input id="work-location" type="text">
</div>
</div>
<div class="control-entry">
<label>选择通勤方式:</label>
<div class="control-input">
<input type="radio" name="vehicle" value="SUBWAY,BUS" onClick="takeBus(this)" checked/> 公交+地铁
<input type="radio" name="vehicle" value="SUBWAY" onClick="takeSubway(this)" /> 地铁
</div>
</div>
<div class="control-entry">
<label>导入房源文件:</label>
<div class="control-input">
<input type="file" name="file" onChange="importRentInfo(this)" />
</div>
</div>
</div>
<div id="transfer-panel"></div>
<script>
var map = new AMap.Map("container", {
resizeEnable: true,
zoomEnable: true,
<!--center: [116.397428, 39.90923], 北京-->
<!-- center: [114.286453,30.618107], 武汉-->
center: [104.067777,30.662956],<!--成都-->
zoom: 11
});
var scale = new AMap.Scale();
map.addControl(scale);
//公交到达圈对象
var arrivalRange = new AMap.ArrivalRange();
//经度,纬度,时间(用不到),通勤方式(默认是地铁+公交)
var x, y, t, vehicle = "SUBWAY,BUS";
//工作地点,工作标记
var workAddress, workMarker;
//房源标记队列
var rentMarkerArray = [];
//多边形队列,存储公交到达的计算结果
var polygonArray = [];
//路径规划
var amapTransfer;
//信息窗体对象,点击房源点后出现
var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, -30)
});
var auto = new AMap.Autocomplete({
//通过id指定输入元素
input: "work-location"
});
//添加事件监听,在选择补完的地址后调用workLocationSelected
AMap.event.addListener(auto, "select", workLocationSelected);
//坐公交
function takeBus(radio) {
vehicle = radio.value;
loadWorkLocation()
}
//坐地铁
function takeSubway(radio) {
vehicle = radio.value;
loadWorkLocation()
}
//载入房源文件
function importRentInfo(fileInfo) {
var file = fileInfo.files[0].name;
loadRentLocationByFile(file);
}
//清除已有标记
function delRentLocation() {
if (rentMarkerArray) map.remove(rentMarkerArray);
rentMarkerArray = [];
}
//
function loadRentLocationByFile(fileName) {
//先删除现有的房源标记
delRentLocation();
//所有的地点都记录在集合中
var rent_locations = new Set();
$.get(fileName, function(data) {
data = data.split("\n");
data.forEach(function(item, index) {
rent_locations.add(item.split(",")[1]);
});
rent_locations.forEach(function(element, index) {
//加上房源标记
addMarkerByAddress(element);
});
});
}
//将所有的房源信息以点标记形式展现
function addMarkerByAddress(address) {
var geocoder = new AMap.Geocoder({
city: "成都",
radius: 1000
});
geocoder.getLocation(address, function(status, result) {
if (status === "complete" && result.info === 'OK') {
var geocode = result.geocodes[0];
//点标记是用来标示某个位置点信息的一种地图要素,
rentMarker = new AMap.Marker({
map: map,
title: address,
icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
position: [geocode.location.getLng(), geocode.location.getLat()]
});
rentMarkerArray.push(rentMarker);
rentMarker.content = "<div>房源:<a target = '_blank' href='http://cd.58.com/pinpaigongyu/?key=" + address + "'>" + address + "</a><div>"
rentMarker.on('click', function(e) {
//设置信息体窗口信息
infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
//路线规划
if (amapTransfer) amapTransfer.clear();
//AMap.Transfer公交路线规划对象
amapTransfer = new AMap.Transfer({
map: map,
policy: AMap.TransferPolicy.LEAST_TIME,
city: "成都市",
panel: 'transfer-panel'
});
amapTransfer.search([{
keyword: workAddress
}, {
keyword: address
}], function(status, result) {})
});
}
})
}
// //更新工作地点,加载公交到达圈
// function workLocationSelected(e) {
// workAddress = e.poi.name;
// loadWorkLocation();
// }
// //载入工作地点
// function loadWorkMarker(x, y, locationName) {
// workMarker = new AMap.Marker({
// map: map,
// title: locationName,
// icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png',
// position: [x, y]
// });
// }
// //计算工作地点范围
// function loadWorkRange(x, y, t, color, v) {
// arrivalRange.search([x, y], t, function(status, result) {
// if (result.bounds) {
// for (var i = 0; i < result.bounds.length; i++) {
// var polygon = new AMap.Polygon({
// map: map,
// fillColor: color,
// fillOpacity: "0.4",
// strokeColor: color,
// strokeOpacity: "0.8",
// strokeWeight: 1
// });
// //得到到达圈的多边形路径
// polygon.setPath(result.bounds[i]);
// polygonArray.push(polygon);
// }
// }
// }, {
// policy: v
// });
// }
// //清除之前的工作地点
// function delWorkLocation() {
// if (polygonArray) map.remove(polygonArray);
// if (workMarker) map.remove(workMarker);
// polygonArray = [];
// }
// //工作地点
// function loadWorkLocation() {
// delWorkLocation();
// var geocoder = new AMap.Geocoder({
// city: "成都",
// radius: 1000
// });
// geocoder.getLocation(workAddress, function(status, result) {
// if (status === "complete" && result.info === 'OK') {
// var geocode = result.geocodes[0];
// x = geocode.location.getLng();
// y = geocode.location.getLat();
// loadWorkMarker(x, y);
// loadWorkRange(x, y, 60, "#3f67a5", vehicle);
// map.setZoomAndCenter(12, [x, y]);
// }
// })
// }
</script>
</body>
</html>