Skip to content

Commit 38d8b5e

Browse files
committed
improve show/hide layer text
1 parent dbe96b7 commit 38d8b5e

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

app/javascript/controllers/map/layers_controller.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,16 @@ export default class extends Controller {
217217
// update UI (both desktop and mobile visibility buttons)
218218
layerElement.querySelectorAll('button.layer-visibility i, button.layer-visibility-mobile i').forEach(icon => {
219219
if (layer.show) {
220-
icon.classList.replace('bi-eye-slash', 'bi-eye')
221-
} else {
222220
icon.classList.replace('bi-eye', 'bi-eye-slash')
221+
} else {
222+
icon.classList.replace('bi-eye-slash', 'bi-eye')
223223
}
224224
})
225+
const visBtn = layerElement.querySelector('button.layer-visibility')
226+
const visBtnMobile = layerElement.querySelector('button.layer-visibility-mobile')
227+
const newText = layer.show ? 'Hide layer' : 'Show layer'
228+
visBtn.setAttribute('title', newText)
229+
visBtnMobile.querySelector('.layer-visibility-text').textContent = newText
225230
// show/hide refresh and edit buttons based on visibility
226231
const hideAction = layer.show ? 'remove' : 'add'
227232
if (layer.type !== 'geojson') {

app/javascript/maplibre/controls/shared.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,18 @@ export function initLayersModal () {
206206
const visBtnMobile = layerElement.querySelector('button.layer-visibility-mobile')
207207
visBtn.classList.remove('hidden')
208208
visBtnMobile.classList.remove('hidden')
209+
// Icon represents the ACTION (what will happen when clicked)
209210
if (layer.show === false) {
211+
visBtn.querySelector('i').classList.replace('bi-eye-slash', 'bi-eye')
212+
visBtnMobile.querySelector('i').classList.replace('bi-eye-slash', 'bi-eye')
213+
visBtn.setAttribute('title', 'Show layer')
214+
visBtnMobile.querySelector('.layer-visibility-text').textContent = 'Show layer'
215+
layerElement.classList.add('layer-dimmed')
216+
} else {
210217
visBtn.querySelector('i').classList.replace('bi-eye', 'bi-eye-slash')
211218
visBtnMobile.querySelector('i').classList.replace('bi-eye', 'bi-eye-slash')
212-
layerElement.classList.add('layer-dimmed')
219+
visBtn.setAttribute('title', 'Hide layer')
220+
visBtnMobile.querySelector('.layer-visibility-text').textContent = 'Hide layer'
213221
}
214222
const isFirstGeojsonLayer = layer.type === 'geojson' &&
215223
layers.filter(l => l.type === 'geojson').indexOf(layer) === 0

app/views/maps/modals/_layers.haml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
%span.mapforge-font.layer-name.me-2 Layer name
7979
-# Desktop: inline buttons
8080
%span.text-nowrap.d-none.d-sm-inline
81-
%button.hidden.ms-2.btn.btn-secondary.btn-layer-actions.layer-visibility{ data: { action: "click->map--layers#toggleLayerVisibility", "toggle": 'tooltip' }, title: "Toggle visibility" }
82-
%i.bi.bi-eye
81+
%button.hidden.ms-2.btn.btn-secondary.btn-layer-actions.layer-visibility{ data: { action: "click->map--layers#toggleLayerVisibility", "toggle": 'tooltip' }, title: "Hide layer" }
82+
%i.bi.bi-eye-slash
8383
%button.hidden.btn.btn-secondary.btn-layer-actions.layer-refresh{ data: { action: "click->map--layers#refreshLayer", "toggle": 'tooltip' }, title: "Refresh layer for current view" }
8484
%i.bi.bi-arrow-clockwise.reload-icon
8585
%button.hidden.btn.btn-secondary.btn-layer-actions.layer-edit{ data: { action: "click->map--layers#toggleEdit", "toggle": 'tooltip' }, title: "Edit query" }
@@ -93,8 +93,8 @@
9393
%ul.dropdown-menu.dropdown-menu-end
9494
%li
9595
%button.hidden.dropdown-item.layer-visibility-mobile{ type: "button", data: { action: "click->map--layers#toggleLayerVisibility" } }
96-
%i.bi.bi-eye.me-2
97-
Toggle visibility
96+
%i.bi.bi-eye-slash.me-2
97+
%span.layer-visibility-text Hide layer
9898
%li
9999
%button.hidden.dropdown-item.layer-refresh-mobile{ type: "button", data: { action: "click->map--layers#refreshLayer" } }
100100
%i.bi.bi-arrow-clockwise.me-2

0 commit comments

Comments
 (0)