-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
81 lines (72 loc) · 2.67 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<title>Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="icon" href="/images/favicon.ico" type="image/vnd.microsoft.ico">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.0-rc.3/dist/leaflet.css" />
<link rel="stylesheet" type="text/css" href="./semantic/dist/semantic.min.css">
<script src="https://unpkg.com/leaflet@1.0.0-rc.3/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
<!--<script src="./semantic/dist/semantic.min.js"></script>-->
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([61.215299, -149.895440], 13);;
var userLocation;
var userLocationCircle;
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiYWFyb256aGFvIiwiYSI6ImNpdGQ3YnB6NjAwNXMyc21tNnM4ZHJxemMifQ.zMUs_5i7w3qgXukZhIYLhw', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
var findMe = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function(map) {
var findMeIcon = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom')
findMeIcon.style.backgroundColor = 'white'
findMeIcon.style.width = '26px'
findMeIcon.style.height = '26px'
findMeIcon.style.display ='flex'
findMeIcon.id = 'arrow'
findMeIcon.innerHTML = '<i class="large location arrow icon" style="margin: auto auto;"></i>'
findMeIcon.onclick = function(){
map.locate({setView: true, maxZoom: 16});
}
return findMeIcon;
}
});
map.addControl(new findMe());
function onLocationFound(e) {
var radius = e.accuracy / 2;
if(userLocation !== undefined && userLocation !== null){
map.removeLayer(userLocation);
}
if(userLocationCircle !== undefined && userLocationCircle !== null){
map.removeLayer(userLocationCircle);
}
userLocation = L.marker(e.latlng).addTo(map).bindPopup("You are within " + radius + " meters from this point").openPopup();
userLocationCircle = L.circle(e.latlng, radius).addTo(map);
}
function onLocationError(e) {
alert(e.message);
}
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
</script>
</body>
</html>