Skip to content

Commit

Permalink
fix: stop crashing leaflet when map crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 29, 2024
1 parent 728d8f0 commit 45349be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export default function Container() {
ref.attributionControl.setPrefix(attributionPrefix || '')
ref.on('moveend', setLocationZoom)
ref.on('zoomend', setLocationZoom)
useMapStore.setState({ map: ref })
}
useMapStore.setState({ map: ref })
}}
zoom={zoom}
zoomControl={false}
Expand Down
24 changes: 14 additions & 10 deletions src/components/Layers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function ControlledZoomLayer() {
zoom.remove()
}
}
}, [navSetting])
}, [navSetting, map])

return null
}
Expand All @@ -35,21 +35,25 @@ export function ControlledLocate() {
(state) => state.settings.navigationControls === 'leaflet',
)

const lc = React.useMemo(
() =>
control.locate({
position: 'bottomright',
icon: 'fas fa-crosshairs',
keepCurrentZoomLevel: true,
setView: 'untilPan',
}),
[],
)

React.useEffect(() => {
if (navSetting) {
const lc = control
.locate({
position: 'bottomright',
icon: 'fas fa-crosshairs',
keepCurrentZoomLevel: true,
setView: 'untilPan',
})
.addTo(map)
lc.addTo(map)
return () => {
lc.remove()
}
}
}, [navSetting])
}, [navSetting, map, lc])

return null
}

0 comments on commit 45349be

Please sign in to comment.