1 //= require maplibre.map
2 //= require maplibre/map
3 //= require maplibre/controls
4 //= require maplibre/dom_util
9 if ($("#map").length) {
10 map = new OSM.MapLibre.SecondaryMap();
12 const position = $("html").attr("dir") === "rtl" ? "top-left" : "top-right";
13 const navigationControl = new OSM.MapLibre.NavigationControl();
14 const geolocateControl = new OSM.MapLibre.GeolocateControl();
15 map.addControl(new OSM.MapLibre.CombinedControlGroup([navigationControl, geolocateControl]), position);
17 const markerObjects = $("[data-user]")
19 const { lat, lon } = $(this).data("user");
23 const { lat, lon, color, description } = $(this).data("user");
25 const marker = new OSM.MapLibre.Marker({ color })
26 .setLngLat([lon, lat])
27 .setPopup(new OSM.MapLibre.Popup().setHTML(description));
29 return { marker, lat, lon };
33 for (const item of markerObjects) {
34 item.marker.addTo(map);
37 const updateZIndex = () => {
38 for (const item of markerObjects) {
39 item.currentY = map.project([item.lon, item.lat]).y;
42 markerObjects.sort((a, b) => a.currentY - b.currentY);
44 for (const [index, item] of markerObjects.entries()) {
45 item.marker.getElement().style.zIndex = index;
49 if (markerObjects.length > 0) {
50 map.on("move", updateZIndex);
51 map.on("rotate", updateZIndex);
52 map.on("pitch", updateZIndex);