-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
106 lines (91 loc) · 3.1 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Trinity Bus Routes</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log=="
crossorigin=""></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: Arial;
}
#map {
width: 100vw;
height: 100vh;
}
#schedule {
position: absolute;
z-index: 999;
top: 10px;
left: 10px;
background: white;
padding: 10px 15px;
}
a, a:hover, a:visited {
color: rgb(58, 132, 223);
text-decoration: none;
margin-left: 5px;
}
a:hover {
text-decoration: underline;
}
.leaflet-popup-content {
font-size: 16px;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var coordsTrin = [41.7479, -72.6903];
var map = L.map('map').setView(coordsTrin, 15);
var baselayer = L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
maxZoom: 18, attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, ©\
<a href="https://carto.com/attribution">CARTO</a>'
}).addTo(map);
var popup = L.popup().setLatLng(coordsTrin).setContent('🏫 Trinity College');
popup.addTo(map);
/**
* Opens a popup with content
*/
function openPopup(e, content) {
popup.setLatLng(e.latlng);
popup.setContent(content);
popup.addTo(map);
};
/**
* Loads a .geojson file from routes/ and displays it on the map
*/
function addRoute(number, color) {
$.getJSON('routes/' + number + '.geojson', function(data) {
var route = L.geoJSON(data, {style: {
color: color,
weight: 5,
opacity: 0.5
}
}).addTo(map);
route.on('click', function(e) {
L.DomEvent.stopPropagation(e); // this is needed to prevent opening map's (not geojson's) popup
openPopup(e, 'Bus Route ' + number);
});
});
};
addRoute('37-39', '#8000FF');
addRoute('41', '#FF0000');
addRoute('61', '#FF0000');
map.on('click', function(e) {
var coords = e.latlng.lat + ',' + e.latlng.lng;
var content = '🚌 <a href="https://maps.google.com/maps?t=m&hl=en-US&gl=US&mapclient=embed&saddr=Trinity%20College&daddr=' + coords + '&dirflg=r" target="_blank" >Go Here by Bus</a>';
openPopup(e, content);
});
</script>
</body>
</html>