From 405be2cd037f57f1663454ade2167cd8e550dbc1 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 5 Jul 2026 22:42:41 +0100 Subject: [PATCH] Split maplibre/dom_util.js into two better named files --- app/assets/javascripts/maplibre/map.js | 3 ++- .../maplibre/{dom_util.js => marker.js} | 20 ------------------- app/assets/javascripts/maplibre/popup.js | 19 ++++++++++++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) rename app/assets/javascripts/maplibre/{dom_util.js => marker.js} (77%) create mode 100644 app/assets/javascripts/maplibre/popup.js diff --git a/app/assets/javascripts/maplibre/map.js b/app/assets/javascripts/maplibre/map.js index 09766ae30..bad769a08 100644 --- a/app/assets/javascripts/maplibre/map.js +++ b/app/assets/javascripts/maplibre/map.js @@ -1,5 +1,6 @@ //= require maplibre/controls -//= require maplibre/dom_util +//= require maplibre/marker +//= require maplibre/popup maplibregl.Map.prototype._getUIString = function (key) { const snakeCaseKey = key.replaceAll(/(?<=\w)[A-Z]/g, "_$&").toLowerCase(); diff --git a/app/assets/javascripts/maplibre/dom_util.js b/app/assets/javascripts/maplibre/marker.js similarity index 77% rename from app/assets/javascripts/maplibre/dom_util.js rename to app/assets/javascripts/maplibre/marker.js index 64692f27f..ffb8c0dce 100644 --- a/app/assets/javascripts/maplibre/dom_util.js +++ b/app/assets/javascripts/maplibre/marker.js @@ -73,23 +73,3 @@ OSM.MapLibre.Marker = class extends maplibregl.Marker { }); } }; - -OSM.MapLibre.Popup = class extends maplibregl.Popup { - constructor(options) { - // General offset 5px for each side, but the offset depends on the popup position: - // Popup above the marker -> lift it by height + 5px = 45px - // Popup left the marker -> lift it by width/2 + 5px = 22.5px ~= 17px - const offset = { - "bottom": [0, -45], - "bottom-left": [0, -45], - "bottom-right": [0, -45], - "top": [0, 5], - "top-left": [0, 5], - "top-right": [0, 5], - // our marker is bigger at the top, but this does not attach there -> tucked 2px more - "right": [-15, -10], - "left": [15, -10] - }; - super({ offset, ...options }); - } -}; diff --git a/app/assets/javascripts/maplibre/popup.js b/app/assets/javascripts/maplibre/popup.js new file mode 100644 index 000000000..f8c8e7b1e --- /dev/null +++ b/app/assets/javascripts/maplibre/popup.js @@ -0,0 +1,19 @@ +OSM.MapLibre.Popup = class extends maplibregl.Popup { + constructor(options) { + // General offset 5px for each side, but the offset depends on the popup position: + // Popup above the marker -> lift it by height + 5px = 45px + // Popup left the marker -> lift it by width/2 + 5px = 22.5px ~= 17px + const offset = { + "bottom": [0, -45], + "bottom-left": [0, -45], + "bottom-right": [0, -45], + "top": [0, 5], + "top-left": [0, 5], + "top-right": [0, 5], + // our marker is bigger at the top, but this does not attach there -> tucked 2px more + "right": [-15, -10], + "left": [15, -10] + }; + super({ offset, ...options }); + } +}; -- 2.47.3