-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (78 loc) · 4.04 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Canada Post Box Locator</title>
<meta name="description" content="View Canada Post box locations for Toronto and the GTA.">
<link rel="stylesheet" href="style.css">
<link rel="preload" href="gta_postboxes.geojson" as="fetch" crossorigin="anonymous">
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<meta name="theme-color" content="#CA261A0" />
<link rel="icon" href="postbox.png" type="image/png">
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22>
<text y=%22.9em%22 font-size=%2290%22>
📮
</text>
</svg>">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Leaflet js, must be included after CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js"></script>
</head>
<body>
<div id="map"></div>
<script>
const map = L.map('map').setView([43.678, -79.33], 13);
// Use Google Maps tiles
const tiles = L.tileLayer('https://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 19,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
}).addTo(map);
// OSM tile server, which can't be used in production
/* const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map); */
var userLocationProvided = false;
map.on('locationfound', e => {
userLocationProvided = true;
});
map.locate({ setView: true, maxZoom: 14 });
var markers = L.markerClusterGroup();
// draw featurecollection from static geoJSON file
fetch('gta_postboxes.geojson')
.then(response => response.json())
.then(data => {
L.geoJSON(data, {
onEachFeature: function (feature, layer) {
// convert geoJSON coordinates to leaflet LatLng
var coords = L.GeoJSON.coordsToLatLng(feature.geometry.coordinates);
var elem = `<a href="https://www.google.com/maps/place/${coords.lat},${coords.lng}" target="_blank">Google Maps</a><br>
<a href="https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${coords.lat},${coords.lng}&heading=-45&pitch=38&fov=80" target="_blank">Street View</a>`
layer.bindPopup(elem);
}
}).addTo(markers);
map.addLayer(markers);
// only fit map to markers if user location was not already provided
if (!userLocationProvided) {
map.fitBounds(markers.getBounds());
}
});
var popup = L.popup();
map.on('click', e => {
// construct HTMLElement that links to Google Maps
var elem = `<a href="https://www.google.com/maps/place/${e.latlng.lat},${e.latlng.lng}" target="_blank">Google Maps</a><br>
<a href="https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${e.latlng.lat},${e.latlng.lng}&heading=-45&pitch=38&fov=80" target="_blank">Street View</a>`
popup
.setLatLng(e.latlng)
.setContent(elem)
.openOn(map);
});
</script>
</body>
</html>