1 //= require maplibre.map
2 //= require maplibre.combinedcontrolgroup
7 if ($("#map").length) {
8 map = new maplibregl.Map(OSM.MapLibre.defaultSecondaryMapOptions);
10 const position = $("html").attr("dir") === "rtl" ? "top-left" : "top-right";
11 const navigationControl = new maplibregl.NavigationControl({ showCompass: false });
12 const geolocateControl = new maplibregl.GeolocateControl({
14 enableHighAccuracy: true
16 trackUserLocation: true
18 map.addControl(new OSM.MapLibre.CombinedControlGroup([navigationControl, geolocateControl]), position);
19 map.touchZoomRotate.disableRotation();
20 map.keyboard.disableRotation();
22 const markerObjects = $("[data-user]")
24 const { lat, lon } = $(this).data("user");
28 const { lat, lon, color, description } = $(this).data("user");
30 const marker = OSM.MapLibre.getMarker({ icon: "dot", color })
31 .setLngLat([lon, lat])
32 .setPopup(OSM.MapLibre.getPopup(description));
34 return { marker, lat, lon };
38 for (const item of markerObjects) {
39 item.marker.addTo(map);
42 const updateZIndex = () => {
43 for (const item of markerObjects) {
44 item.currentY = map.project([item.lon, item.lat]).y;
47 markerObjects.sort((a, b) => a.currentY - b.currentY);
49 for (const [index, item] of markerObjects.entries()) {
50 item.marker.getElement().style.zIndex = index;
54 if (markerObjects.length > 0) {
55 map.on("move", updateZIndex);
56 map.on("rotate", updateZIndex);
57 map.on("pitch", updateZIndex);