-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
93 lines (82 loc) · 2.36 KB
/
index.js
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
// This example adds an animated symbol to a polyline.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 8.443556,
lng: 76.994161
},
zoom: 13,
mapTypeId: 'terrain'
});
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
fillOpacity: 1,
scale: 3
};
// Define the symbol, using one of the predefined paths ('CIRCLE')
// supplied by the Google Maps JavaScript API.
var myMarker = {
path: google.maps.SymbolPath.CIRCLE,
scale: 5,
strokeColor: '#e53935'
};
var directionsService = new google.maps.DirectionsService();
var start = "Trivandrum International Airport";
var end = "Neyyanttinkara";
var method = 'DRIVING';
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode[method]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var line = new google.maps.Polyline({
path: response.routes[0].overview_path,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '10px'
},
{
icon: myMarker,
offset: '100%'
}],
strokeColor: '#0eb7f6',
map: map
});
//+++++++++++++++++++++User this var line for non dotted path
// var line = new google.maps.Polyline({
// path: response.routes[0].overview_path,
// icons: [
// {
// icon: myMarker,
// offset: '100%'
// }],
// strokeColor: '#0eb7f6',
// map: map
// });
animateCircle(line);
var marker = new google.maps.Marker({
position: response.routes[0].overview_path[0],
map: map,
title: 'Hello World!'
});
var marker = new google.maps.Marker({
position: response.routes[0].overview_path[response.routes[0].overview_path.length - 1],
map: map,
title: 'Hello World!'
});
}
});
}
function animateCircle(line) {
var count = 0;
window.setInterval(function() {
count = (count + 1) % 200;
var icons = line.get('icons');
icons[1].offset = (count / 2) + '%';
// icons[1].offset = (count / 2) + '%'; //+++++++++++++++++++++User this line for non dotted path and comment above line.
line.set('icons', icons);
}, 100);
}