-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (92 loc) · 3.01 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
<!DOCTYPE html>
<html>
<head>
<title>Zehui's Work/Study Location</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="js/maplibre-gl.js"></script>
<link rel="stylesheet" href="css/maplibre-gl.css">
<style>
#map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
.popup {text-align: center;}
</style>
</head>
<body>
<div id="map">
<a href="https://www.maptiler.com" style="position:absolute;left:10px;bottom:10px;z-index:999;"><img src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo"></a>
</div>
<script>
// Initialize map
let map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v2/style.json?key=HKgQAIheuh9EKnXWzGiC',
attributionControl: false,
center: [-79.92051184179995, 43.26181310125515],
zoom: 16,
pitch: 60,
bearing: -45
});
map.addControl(new maplibregl.AttributionControl({
customAttribution: '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>',
compact: true
}));
// Add GeoJSON layer
map.on('load', function() {
map.addControl(new maplibregl.NavigationControl());
map.addControl(new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
}));
map.addSource('mac_data', {
'type': 'geojson',
'data': {
"name":"mac",
"type":"FeatureCollection",
"features":[
{"type": "Feature",
"geometry":{
"type": "Point",
"coordinates": [-79.92051184179995, 43.26181310125515]},
"properties":{
}
}
]}
});
map.addLayer({
'id': 'mac',
'source': 'mac_data',
'type': 'circle',
'paint': {
'circle-radius': {
'base': 1.75, // control interpolate changing rate, more toward higher end
'stops': [
[2, 4],
[16, 7], // zoom level 16, circle radius 7
[22, 240]
]
},
'circle-color': '#7a003c'
}
});
let coordinates = [-79.92051184179995, 43.26181310125515];
let description =
'<div class="popup">' +
'Burke Science Building (BSB)' + '<br>' + 'McMaster University' +
'</div>';
// Display popups on click
map.on('click', 'mac', function(e) {
new maplibregl.Popup({ closeOnClick: true , focusAfterOpen: false})
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
// Display popups on load
const popup = new maplibregl.Popup({ closeOnClick: true , focusAfterOpen: false})
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
</script>
</body>
</html>