1 //= require maplibre-gl/dist/maplibre-gl
2 //= require maplibre.i18n
4 OSM.MapLibre.Styles.Mapnik = {
10 "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
25 OSM.MapLibre.defaultHomeZoom = 11;
26 OSM.MapLibre.defaultSecondaryMapOptions = {
28 style: OSM.MapLibre.Styles.Mapnik,
29 attributionControl: false,
30 locale: OSM.MapLibre.Locale,
33 pitchWithRotate: false,
36 center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
37 zoom: OSM.home ? OSM.MapLibre.defaultHomeZoom : 0
40 // Helper function to create Leaflet style (SVG comes from Leaflet) markers for MapLibre
41 // new maplibregl.Marker({ color: color }) is simpler, but does not have the exact same gradient
42 OSM.MapLibre.getMarker = function ({ icon = "dot", color = "var(--marker-red)", ...options }) {
43 const el = document.createElement("div");
44 el.className = "maplibre-gl-marker";
45 el.style.width = "25px";
46 el.style.height = "40px";
48 const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
49 svg.setAttribute("viewBox", "0 0 25 40");
50 svg.setAttribute("width", "25");
51 svg.setAttribute("height", "40");
52 svg.classList.add("pe-none");
53 svg.style.overflow = "visible";
55 // Use the marker icons from NoteMarker.svg
56 const use1 = document.createElementNS("http://www.w3.org/2000/svg", "use");
57 use1.setAttribute("href", "#pin-shadow");
59 const use2 = document.createElementNS("http://www.w3.org/2000/svg", "use");
60 use2.setAttribute("href", `#pin-${icon}`);
61 use2.setAttribute("color", color);
62 use2.classList.add("pe-auto");
64 svg.appendChild(use1);
65 svg.appendChild(use2);
68 return new maplibregl.Marker({
76 // Helper function to create MapLibre popups that don't overlap with Leaflets' markers
77 OSM.MapLibre.getPopup = function (content) {
78 // General offset 5px for each side, but the offset depends on the popup position:
79 // Popup above the marker -> lift it by height + 5px = 45px
80 // Popup left the marker -> lift it by width/2 + 5px = 22.5px ~= 17px
83 "bottom-left": [0, -45],
84 "bottom-right": [0, -45],
88 // our marker is bigger at the top, but this does not attach there -> tucked 2px more
92 return new maplibregl.Popup({ offset }).setHTML(content);