Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/features/home/VenueMap.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
:global(.leaflet-container) {
font-family: var(--font-body);
}

:global(:root[data-theme='dark']) .map :global(.leaflet-bar a),
:global(:root[data-theme='dark']) .map :global(.leaflet-popup-content-wrapper),
:global(:root[data-theme='dark']) .map :global(.leaflet-popup-tip),
:global(:root[data-theme='dark']) .map :global(.leaflet-control-attribution) {
color: var(--ink);
background: var(--control-bg);
}

:global(:root[data-theme='dark']) .map :global(.leaflet-bar a) {
border-bottom-color: var(--rule);
}

:global(:root[data-theme='dark']) .map :global(.leaflet-bar a:hover) {
color: var(--ink);
background: var(--surface-hover);
}

:global(:root[data-theme='dark']) .map :global(.leaflet-control-attribution a) {
color: var(--blue-deep);
}
28 changes: 27 additions & 1 deletion src/features/home/VenueMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ const venueIcon = L.icon({
const ATTRIBUTION =
'&copy; <a href="https://carto.com/">CARTO</a> &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'

const TILE_URLS = {
light: 'https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png',
dark: 'https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',
} as const

function getTileUrl() {
return document.documentElement.dataset.theme === 'dark'
? TILE_URLS.dark
: TILE_URLS.light
}

export function VenueMap() {
const containerRef = useRef<HTMLDivElement>(null)

Expand All @@ -34,10 +45,24 @@ export function VenueMap() {
scrollWheelZoom: false,
}).setView([lat, lng], 14)

L.tileLayer('https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
let currentTileUrl = getTileUrl()
const tileLayer = L.tileLayer(currentTileUrl, {
attribution: '',
}).addTo(map)

const themeObserver = new MutationObserver(() => {
const nextTileUrl = getTileUrl()
if (nextTileUrl === currentTileUrl) return

currentTileUrl = nextTileUrl
tileLayer.setUrl(currentTileUrl)
})

themeObserver.observe(document.documentElement, {
attributes: true,
attributeFilter: ['data-theme'],
})

L.control
.attribution({ position: 'bottomright', prefix: false })
.addAttribution(ATTRIBUTION)
Expand All @@ -49,6 +74,7 @@ export function VenueMap() {
.openPopup()

return () => {
themeObserver.disconnect()
map.remove()
}
}, [])
Expand Down