Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (71 loc) · 2.33 KB
/
Copy pathindex.js
File metadata and controls
77 lines (71 loc) · 2.33 KB
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
import maplibregl from "https://cdn.skypack.dev/maplibre-gl@5.12.0";
import { Protocol } from "https://cdn.skypack.dev/pmtiles";
import LayerControl from "./layer-control.js";
import layers from "./layers/index.js";
import bounds from "./bounds.js";
let protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
const map = new maplibregl.Map({
container: "map",
bounds: [
[-77.60330200195314, 37.443790285861574],
[-77.38151550292969, 37.604440246103636],
],
maxBounds: bounds,
hash: "m",
attributionControl: false,
});
map.addControl(new maplibregl.AttributionControl({}), "bottom-left");
map.addControl(new maplibregl.NavigationControl({}), "bottom-right");
map.addControl(new LayerControl({ layers }));
const mouseenter = (e) => {
e.target.getCanvas().style.cursor = "pointer";
};
const mouseleave = (e) => {
e.target.getCanvas().style.cursor = "";
};
map.on("mouseenter", "yesterdays-point", mouseenter);
map.on("mouseleave", "yesterdays-point", mouseleave);
map.on("click", "yesterdays-point", (e) => {
new maplibregl.Popup({ maxWidth: "60vw" })
.setLngLat(e.lngLat)
.setHTML(
`
<img style="max-width:100%;" src="${e.features[0].properties.img_url}">
<br>
Date: ${e.features[0].properties.original_date}
<a style="float:right;" target="_blank" href="https://yesterdays.maprva.org/${e.features[0].properties.id}">
View Details
</a>
`,
)
.addTo(map);
});
map.on("mouseenter", "surveillance-point", mouseenter);
map.on("mouseleave", "surveillance-point", mouseleave);
map.on("click", "surveillance-point", (e) => {
console.log(e.features[0].properties);
new maplibregl.Popup()
.setLngLat(e.lngLat)
.setHTML(
`
<h3>surveillance:type=${e.features[0].properties["surveillance:type"]}</h3>
<a target="_blank" href="https://osm.org/${e.features[0].properties["osm_type"]}/${e.features[0].properties["osm_id"]}">
View on OSM
</a>
`,
)
.addTo(map);
});
// register service worker for PWA
async function initServiceWorker() {
if ("serviceWorker" in navigator) {
try {
const registration = await navigator.serviceWorker.register("./sw.js");
await registration.update();
console.log("Service Worker Registered");
} catch {}
}
}
initServiceWorker();
window.map = map; // for easy debugging