-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
150 lines (125 loc) · 4.96 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Blvd">
<link rel="apple-touch-icon" href="../../icon.png">
<link rel="icon" type="image/png" href="../../favicon.png" />
<title>Map - Blvd</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.active svg {
fill: #225fff;
}
.leaflet-container {
height: 400px;
width: 600px;
max-width: 100%;
max-height: 100%;
}
body {
padding: 0;
margin: 0;
}
#map {
height: 100%;
width: 100vw;
}
.location {
position: fixed;
z-index: 99999999;
width: 27px;
height: 27px;
background: white;
top: 80px;
left: 13px;
border-radius: 2px;
border: 1px solid #ccc;
box-shadow: -1px 1px 2px #000000c4;
}
</style>
</head>
<body>
<div id="location" class="location" onclick="toggleLocation()">
<svg style=" max-width: 27px; vertical-align: middle; line-height: 0; height: 19px; margin-top: 4px; " height="48" viewBox="0 0 48 48" width="48" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48h-48z" fill="none"/><path d="M24 16c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm17.88 6c-.92-8.34-7.54-14.96-15.88-15.88v-4.12h-4v4.12c-8.34.92-14.96 7.54-15.88 15.88h-4.12v4h4.12c.92 8.34 7.54 14.96 15.88 15.88v4.12h4v-4.12c8.34-.92 14.96-7.54 15.88-15.88h4.12v-4h-4.12zm-17.88 16c-7.73 0-14-6.27-14-14s6.27-14 14-14 14 6.27 14 14-6.27 14-14 14z"/></svg>
</div>
<div id='map'></div>
<script>
const map = L.map('map',{
center: [25.761681, -80.191788],
zoom: 12
})
var tile_server = 'https://map.blvd.to/{s}/{z}/{x}/{y}'
const tiles = L.tileLayer(tile_server, {
maxZoom: 21,
zoom: 18,
attribution: '© <a href="#">Google</a>',
subdomains:['mt0','mt1','mt2','mt3'],
}).addTo(map);
function onLocationFound(e) {
map.panTo(e.latlng)
}
function onLocationError(e) {
alert(e.message);
}
var enabled = false
function toggleLocation() {
enabled = !enabled
var element = document.getElementById("location")
element.classList.toggle("active")
getLocation()
}
function goToLocation(position) {
var iconOptions = {
iconUrl: 'icons/circle.png',
iconSize: [20, 20]
}
// Creating a custom icon
var customIcon = L.icon(iconOptions)
// Options for the marker
var markerOptions = {
// clickable: true,
draggable: true,
icon: customIcon
}
if (window.marker) {
window.marker.setLatLng(new L.LatLng(position.coords.latitude, position.coords.longitude),{ draggable:'true' });
map.panTo(new L.LatLng(position.coords.latitude, position.coords.longitude))
// return
} else {
window.marker = new L.marker([position.coords.latitude, position.coords.longitude], markerOptions)
marker.on('dragend', function(event){
var marker = event.target;
var position = marker.getLatLng();
marker.setLatLng(new L.LatLng(position.lat, position.lng),{draggable:'true'});
map.panTo(new L.LatLng(position.lat, position.lng))
})
// markers.addLayer(marker)
window.marker.addTo(map)
}
last_known = [position.coords.latitude, position.coords.longitude]
console.log("Now at:", position.coords.latitude, position.coords.longitude)
map.flyTo( new L.LatLng(position.coords.latitude, position.coords.longitude), 20)
}
window.getLocation = function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(goToLocation);
return
} else {
alert("Location needed for this to work.")
}
}
setInterval(function() {
if (enabled) getLocation()
}, 10000)
</script>
</body>
</html>