-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
61 lines (50 loc) · 1.33 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
var map = L.map('map').setView([-0.2200455, -78.5009917], 10),
wayPoints = [],
myStyle = {
color: '#ff7800',
weight: 5,
opacity: 0.65,
};
L.tileLayer.provider('CartoDB.Voyager').addTo(map);
function generateResult() {
let tempArray = JSON.parse(document.getElementById('coordinates').value);
tempArray.map(function (item) {
wayPoints.push(L.latLng(item.lat, item.lng));
});
let routing = L.Routing.control({
waypoints: wayPoints,
autoRoute: true,
routeWhileDragging: true,
}).addTo(map);
routing.hide();
routing.on('routeselected', function (e) {
let r = e.route,
line = L.Routing.line(r),
bounds = line.getBounds();
var result = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: [],
},
},
],
};
map.fitBounds(bounds);
r.coordinates.map(function (item) {
result.features[0].geometry.coordinates.push([item.lng, item.lat]);
});
document.getElementById('result').value = JSON.stringify(result);
});
}
function cleanTextarea() {
document.getElementById('coordinates').value = '';
}
function SelectAll(id) {
document.getElementById(id).focus();
document.getElementById(id).select();
}