Toggle selected button style (#3)

This commit is contained in:
Aphanite
2024-01-20 00:55:53 +01:00
committed by GitHub
parent 2fc98de48f
commit 4b2de6aeeb
3 changed files with 22 additions and 10 deletions

View File

@@ -40,14 +40,22 @@ const mapDiv = document.getElementById('map-container')
initMap()
function selectStyle(style) {
// initMap()
function selectStyle(event, style) {
toggleButtonSelection(event.target)
const styleUrl = 'https://tiles.openfreemap.org/styles/' + style
map.setStyle(styleUrl)
map.setPitch(0)
map.setBearing(0)
map.setZoom(12.5)
const spans = document.querySelectorAll('#style-url-code span')
spans[2].innerText = '/' + style
document.getElementById('style-url-code').innerText = styleUrl
}
function toggleButtonSelection(clickedButton) {
clickedButton.classList.add('selected')
Array.from(clickedButton.parentElement.children)
.filter(child => child !== clickedButton)
.forEach(button => button.classList.remove('selected'))
}

View File

@@ -185,6 +185,10 @@ code {
align-items: center;
}
.btn.selected {
background: #4892d9;
}
.button-container {
margin: 0 auto 0.6em;
max-width: 600px;