-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
132 lines (110 loc) · 3.58 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
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.css" />
<style>
body {
margin: 0;
padding: 0;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
display: none !important;
}
.pointers,
.taxi-pointers {
display: block !important;
}
</style>
</head>
<body>
<div id="map" style="width:100%; height: 100vh"></div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.js"></script>
<script>
// Personalizar css no mapa
let myCustomColourUser = 'background-color: red;'
const markerHtml = `
width: 3rem;
height: 3rem;
display: block;
left: -1.5rem;
top: -1.5rem;
position: relative;
border-radius: 3rem 3rem 0;
transform: rotate(45deg);
border: 3px solid #FFFFFF;`
// Coordenadas do Ponta A - Táxi
const coordTaxi = [-11.732997565990585, -61.78596675395966];
// Coordenadas do Ponta B - Usuário
const coordUser = [-11.73094, -61.7925];
// Iniciar o mapa com coordenadas do ponto A
const map = L.map('map').setView(coordTaxi, 40);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
// Personalizar Ponto na mapa com imagem do táxi.
const taxiIcon = L.icon({
className: "taxi-pointers",
iconUrl: 'taxi.png',
iconSize: [45, 45]
})
const marker = L.marker(coordTaxi, { icon: taxiIcon }).addTo(map);
function startService () {
// Array de coordenadas. Simula o táxi enviando a localização para o APP.
const latlng = [
{ lat: -11.733, lng: -61.78595 },
{ lat: -11.73379, lng: -61.78597 },
{ lat: -11.73379, lng: -61.78597 },
{ lat: -11.73381, lng: -61.78605 },
{ lat: -11.73383, lng: -61.78613 },
{ lat: -11.7338, lng: -61.78649 },
{ lat: -11.7338, lng: -61.78659 },
{ lat: -11.73383, lng: -61.78687 },
{ lat: -11.7338, lng: -61.78715 },
{ lat: -11.7338, lng: -61.78724 },
{ lat: -11.73381, lng: -61.78808 },
{ lat: -11.7338, lng: -61.79009 },
{ lat: -11.73378, lng: -61.79223 },
{ lat: -11.73378, lng: -61.79223 },
{ lat: -11.73291, lng: -61.79224 },
{ lat: -11.73291, lng: -61.79224 },
{ lat: -11.7328, lng: -61.79223 },
{ lat: -11.73279, lng: -61.79303 },
{ lat: -11.73279, lng: -61.79303 },
{ lat: -11.73094, lng: -61.79298 },
{ lat: -11.73094, lng: -61.79298 },
{ lat: -11.73094, lng: -61.7925 }
]
// Personalizar Ponto na mapa com imagem do Usuário.
const icon = L.divIcon({
className: "pointers",
iconAnchor: [0, 24],
labelAnchor: [-6, 0],
popupAnchor: [0, -36],
html: `<span style="${markerHtml}${myCustomColourUser}" />`
})
var newMarker = L.marker([coordUser[0], coordUser[1]], { icon }).addTo(map);
// Identifica a melhor rota para iniciar a viagem.
L.Routing.control({
waypoints: [
L.latLng(coordTaxi[0], coordTaxi[1]),
L.latLng(coordUser[0], coordUser[1])
]
}).on('routesfound', function (e) {
// Loop de coordenadas. Simula o táxi enviando a localização para o APP.
latlng.forEach(function (coord, index) {
setTimeout(function () {
marker.setLatLng([coord.lat, coord.lng]);
// Identifica o final da viagem.
if (coord.lat === coordUser[0] && coord.lng === coordUser[1]) {
alert('Seu táxi acabou de chegar!')
}
}, 1000 * index)
})
}).addTo(map);
};
startService()
</script>
</body>
</html>