From cfac301106b5b068b94084e105d8364e12471707 Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Mon, 19 Jan 2026 16:21:49 +0000 Subject: [PATCH] Move CombinedControlGroup to MapLibre controls extensions --- app/assets/javascripts/dashboard.js | 1 - .../maplibre.combinedcontrolgroup.js | 52 ------------------- app/assets/javascripts/maplibre/controls.js | 51 ++++++++++++++++++ app/assets/javascripts/user.js | 1 - 4 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 app/assets/javascripts/maplibre.combinedcontrolgroup.js diff --git a/app/assets/javascripts/dashboard.js b/app/assets/javascripts/dashboard.js index 26bfdaf03..6971c6637 100644 --- a/app/assets/javascripts/dashboard.js +++ b/app/assets/javascripts/dashboard.js @@ -1,5 +1,4 @@ //= require maplibre.map -//= require maplibre.combinedcontrolgroup //= require maplibre/controls //= require maplibre/dom_util diff --git a/app/assets/javascripts/maplibre.combinedcontrolgroup.js b/app/assets/javascripts/maplibre.combinedcontrolgroup.js deleted file mode 100644 index 5ad0b2ea5..000000000 --- a/app/assets/javascripts/maplibre.combinedcontrolgroup.js +++ /dev/null @@ -1,52 +0,0 @@ -class CombinedControlGroup { - constructor(controls) { - // array of MapLibre controls - this.controls = controls; - // DOM containers returned by onAdd() - this.containers = []; - } - - onAdd(map) { - this._container = document.createElement("div"); - this._container.className = "maplibregl-ctrl maplibregl-ctrl-group"; - - for (const ctrl of this.controls) { - const ctrlContainer = ctrl.onAdd(map); - this.containers.push(ctrlContainer); - - // Extract buttons from the control's container and add to our wrapper - const buttons = ctrlContainer.querySelectorAll("button"); - const iconMap = { - "zoom-in": "plus-lg", - "zoom-out": "dash-lg", - "geolocate": "cursor-fill" - }; - - buttons.forEach(button => { - // Find the type of button (zoom-in, zoom-out, etc.) from its class name - const match = button.className.match(/maplibregl-ctrl-([\w-]+)/); - if (match) { - const type = match[1]; // e.g., "zoom-in" - const icon = iconMap[type]; - - if (icon) { - $(button) - .empty() - .append($("").addClass(`maplibregl-ctrl-icon fs-5 bi bi-${icon}`)); - } - } - this._container.appendChild(button); - }); - } - - return this._container; - } - - onRemove() { - for (const ctrl of this.controls) ctrl.onRemove?.(); - - if (this._container) this._container.remove(); - } -} - -OSM.MapLibre.CombinedControlGroup = CombinedControlGroup; diff --git a/app/assets/javascripts/maplibre/controls.js b/app/assets/javascripts/maplibre/controls.js index b4b398a4a..ea2ea4487 100644 --- a/app/assets/javascripts/maplibre/controls.js +++ b/app/assets/javascripts/maplibre/controls.js @@ -1,3 +1,54 @@ +OSM.MapLibre.CombinedControlGroup = class CombinedControlGroup { + constructor(controls) { + // array of MapLibre controls + this.controls = controls; + // DOM containers returned by onAdd() + this.containers = []; + } + + onAdd(map) { + this._container = document.createElement("div"); + this._container.className = "maplibregl-ctrl maplibregl-ctrl-group"; + + for (const ctrl of this.controls) { + const ctrlContainer = ctrl.onAdd(map); + this.containers.push(ctrlContainer); + + // Extract buttons from the control's container and add to our wrapper + const buttons = ctrlContainer.querySelectorAll("button"); + const iconMap = { + "zoom-in": "plus-lg", + "zoom-out": "dash-lg", + "geolocate": "cursor-fill" + }; + + buttons.forEach(button => { + // Find the type of button (zoom-in, zoom-out, etc.) from its class name + const match = button.className.match(/maplibregl-ctrl-([\w-]+)/); + if (match) { + const type = match[1]; // e.g., "zoom-in" + const icon = iconMap[type]; + + if (icon) { + $(button) + .empty() + .append($("").addClass(`maplibregl-ctrl-icon fs-5 bi bi-${icon}`)); + } + } + this._container.appendChild(button); + }); + } + + return this._container; + } + + onRemove() { + for (const ctrl of this.controls) ctrl.onRemove?.(); + + if (this._container) this._container.remove(); + } +}; + OSM.MapLibre.GeolocateControl = class extends maplibregl.GeolocateControl { constructor({ positionOptions = {}, ...options } = {}) { super({ diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 05f703060..120ba2160 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -1,5 +1,4 @@ //= require maplibre.map -//= require maplibre.combinedcontrolgroup //= require maplibre/controls //= require maplibre/dom_util //= require ./home_location_name-endpoint -- 2.39.5