-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
47 lines (40 loc) · 1.14 KB
/
map.js
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
export function createAndAttachMap(longitude, latitude) {
var map = new maplibregl.Map({
container: "map",
style: "https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL",
center: [longitude, latitude],
zoom: 11,
});
map.scrollZoom.disable();
return map;
}
export function createMarker(
parking,
addPopup,
popupMessage,
callbackOnOpen,
callbackOnClose,
) {
// create DOM element for the marker
let el = document.createElement("div");
if (parking.NumberOfSlots !== undefined) {
el.innerText = parking.NumberOfSlots;
}
el.dataset.id = parking.ID;
el.classList.add("marker");
// create the marker
let marker = new maplibregl.Marker(el)
.setLngLat([parking.Longitude, parking.Latitude])
// add popup
if (addPopup) {
var popup = new maplibregl.Popup({ offset: 25 }).setText(popupMessage);
popup.on("open", () => {
callbackOnOpen();
});
popup.on("close", () => {
callbackOnClose();
});
marker.setPopup(popup)
}
return marker;
}