Skip to content

Commit

Permalink
fix: tilelayer background
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Dec 29, 2023
1 parent b1e873c commit 4ad64ca
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/hooks/useTileLayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// @ts-check
import * as React from 'react'

import { useStatic, useStore } from '@hooks/useStore'

/**
*
* @param {Record<string, { name: string, style: 'light' | 'dark', attribution?: string, url?: string }>} tileServers
* @param {string} tileServer
* @param {'day' | 'night' | 'dusk' | 'dawn'} timeOfDay
* @returns
*/
const getTileLayer = (tileServers, tileServer, timeOfDay) => {
const fallbackTs = Object.values(tileServers).find(
(server) => server.name !== 'auto',
Expand All @@ -17,8 +25,8 @@ const getTileLayer = (tileServers, tileServer, timeOfDay) => {
}

export default function useTileLayer() {
const timeOfDay = useStatic((state) => state.timeOfDay)
const userTileLayer = useStore((state) => state.settings.tileServers)
const timeOfDay = useStatic((s) => s.timeOfDay)
const userTileLayer = useStore((s) => s.settings.tileServers)
const online = useStatic((s) => s.online)

const tileLayer = React.useMemo(() => {
Expand All @@ -44,6 +52,13 @@ export default function useTileLayer() {

React.useEffect(() => {
useStatic.setState({ tileStyle: tileLayer.style })
const leafletContainerEl = document
.getElementsByClassName('leaflet-container')
.item(0)
if (leafletContainerEl instanceof HTMLElement) {
leafletContainerEl.style.background =
tileLayer.style === 'dark' ? '#0F0D0D' : '#ddd'
}
}, [tileLayer.style])

return tileLayer
Expand Down

0 comments on commit 4ad64ca

Please sign in to comment.