-
Notifications
You must be signed in to change notification settings - Fork 30
/
app.js
91 lines (68 loc) · 2.23 KB
/
app.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
// default map layer
let map = L.map('map', {
layers: MQ.mapLayer(),
center: [35.791188, -78.636755],
zoom: 12
});
function runDirection(start, end) {
// recreating new map layer after removal
map = L.map('map', {
layers: MQ.mapLayer(),
center: [35.791188, -78.636755],
zoom: 12
});
var dir = MQ.routing.directions();
dir.route({
locations: [
start,
end
]
});
CustomRouteLayer = MQ.Routing.RouteLayer.extend({
createStartMarker: (location) => {
var custom_icon;
var marker;
custom_icon = L.icon({
iconUrl: 'img/red.png',
iconSize: [20, 29],
iconAnchor: [10, 29],
popupAnchor: [0, -29]
});
marker = L.marker(location.latLng, {icon: custom_icon}).addTo(map);
return marker;
},
createEndMarker: (location) => {
var custom_icon;
var marker;
custom_icon = L.icon({
iconUrl: 'img/blue.png',
iconSize: [20, 29],
iconAnchor: [10, 29],
popupAnchor: [0, -29]
});
marker = L.marker(location.latLng, {icon: custom_icon}).addTo(map);
return marker;
}
});
map.addLayer(new CustomRouteLayer({
directions: dir,
fitBounds: true
}));
}
// function that runs when form submitted
function submitForm(event) {
event.preventDefault();
// delete current map layer
map.remove();
// getting form data
start = document.getElementById("start").value;
end = document.getElementById("destination").value;
// run directions function
runDirection(start, end);
// reset form
document.getElementById("form").reset();
}
// asign the form to form variable
const form = document.getElementById('form');
// call the submitForm() function when submitting the form
form.addEventListener('submit', submitForm);