-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutingmulti.html
184 lines (161 loc) · 4.39 KB
/
routingmulti.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
<html>
<head>
<title>
Demo Map Api-Vietmap
</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>
<style>
body{
margin:0;
padding:0;
overflow:hidden;
}
.top{
position:absolute;
height:50px;
left:0;
right:0;
background:gray;
}
.center{
position:absolute;
right:0;
left:0;
top:50px;
bottom:0
}
#map{
width:100%;
height:100%;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li.nav {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 13px;
text-decoration: none;
}
li a:hover {
background-color: #111111;
}
#left-menu{
height:100%;
overflow-y:scroll;
overflow-x:hidden;
}
#left-menu > .title{
margin-bottom:15px;
}
#left-menu h2,h3,h4{
padding-left:15px;
}
li.list-item{
border-top: dashed 1px darkblue;
padding-left:15px;
}
li.list-item p{
margin-bottom: 5px !important;
}
li.active{
background-color: darkgreen;
font-weight: bold;
}
</style>
</head>
<body>
<div class="top">
<ul>
<li class="nav"><a href="tilemap.html">Bản đồ nền</a></li>
<li class="nav"><a href="routing.html">Dẫn đường qua 2 điểm</a></li>
<li class="nav active"><a href="routingmulti.html">Dẫn đường qua nhiều điểm</a></li>
<li class="nav"><a href="autosearch.html">Auto Search</a></li>
</ul>
</div>
<div class="center row">
<div id="left-menu" class="col col-lg-2 col-md-3"></div>
<div class="col col-lg-10 col-md-9" id="map"></div>
</div>
<script>
var map = L.map('map').setView([10.758810, 106.681450], 14);
L.tileLayer('https://maps.vietmap.vn/tm/{z}/{x}/{y}.png?apikey=9cbf0bc15d3901b7e043d8f76be8d73f370a82fe629a2d46', {
attribution: '© <a href="http://maps.vietmap.vn/copyright">Vietmap</a> contributors'
}).addTo(map);
$(document).ready(function(){
$.ajax({
url:'https://maps.vietmap.vn/api/route?point=10.765963,106.647366&point=10.762927,106.651046&point=10.759144,106.651411&point=10.758258,106.660445&apikey=9cbf0bc15d3901b7e043d8f76be8d73f370a82fe629a2d46',
type:'get',
success:function(res){
var colors=['green','red','blue','green','yellow','orange'];
var html='<h2 class="title">Kết quả lộ trình</h2>';
for(var i =0;i<res.paths.length;i++){
var totalmeter=0;
var num=Number(i+1);
var subhtml='';
subhtml+='<ul class="list">';
var instructions= res.paths[i].instructions;
var points=res.paths[i].points.coordinates;
for(var j=0;j<instructions.length-1;j++ ){
totalmeter+=instructions[j].distance;
subhtml+='<li class="list-item">';
subhtml+='<p><b>Chiều dài: </b>'+instructions[j].distance+' m</p>';
subhtml+='<p><b>Thời gian: </b>'+instructions[j].time+' s</p>';
if(instructions[j].heading){
subhtml+='<p><b>Hướng: </b>'+instructions[j].heading+'<sup>o</sup></p>';
}
subhtml+='<p><i>'+instructions[j].text+'</i></p>';
subhtml+='<p><b>Đường: </b>'+instructions[j].street_name+'</p>';
subhtml+='</li>';
}
subhtml+='</ul>';
subhtml='<h4>Lộ trình thứ '+num+'(tổng '+totalmeter.toFixed(2)+' m)</h4>'+subhtml;
html+=subhtml;
}
$('#left-menu').html(html);
//draw line
var latlngs = [];
for(var j=0;j<points.length;j++){
latlngs.push([points[j][1],points[j][0]]);
}
var colorIdx=5%i;
var polyline = L.polyline(latlngs, {color: colors[colorIdx]}).addTo(map);
// zoom the map to the polyline
map.fitBounds(polyline.getBounds());
var endIcon = L.icon({
iconUrl: 'endmarker.png',
iconAnchor: [32, 32]
});
var startIcon = L.icon({
iconUrl: 'startmarker.png',
iconAnchor: [32, 32]
});
var midIcon = L.icon({
iconUrl: 'pink.png',
iconSize: [40, 40],
iconAnchor: [20, 20]
});
L.marker(latlngs[0],{icon:startIcon}).addTo(map);
L.marker([10.762927,106.651046],{icon:midIcon}).addTo(map);
L.marker([10.759144,106.651411],{icon:midIcon}).addTo(map);
L.marker(latlngs[latlngs.length-1],{icon:endIcon}).addTo(map);
}
})
})
</script>
</body>
</html>