-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Hydrometeorological tab
- Loading branch information
Showing
18 changed files
with
1,366 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { createContext, PropsWithChildren, useCallback, useMemo, useRef } from "react"; | ||
|
||
import useDeckGLMapboxOverlay from "@/hooks/use-deckgl-mapbox-overlay"; | ||
|
||
import type { Layer } from "@deck.gl/core"; | ||
|
||
interface IDeckGLMapboxOverlayContext { | ||
addLayer: (layer: Layer) => void; | ||
removeLayer: (layerId: string) => void; | ||
} | ||
|
||
export const DeckGLMapboxOverlayContext = createContext<IDeckGLMapboxOverlayContext>({ | ||
addLayer: () => { | ||
throw new Error( | ||
"DeckGLMapboxOverlayContext must be used within <DeckGLMapboxOverlayContext.Provider />.", | ||
); | ||
}, | ||
removeLayer: () => { | ||
throw new Error( | ||
"DeckGLMapboxOverlayContext must be used within <DeckGLMapboxOverlayContext.Provider />.", | ||
); | ||
}, | ||
}); | ||
|
||
const DeckglMapboxProvider = ({ children }: PropsWithChildren) => { | ||
const layersRef = useRef<Layer[]>([]); | ||
const deckGLMapboxOverlay = useDeckGLMapboxOverlay(); | ||
|
||
const addLayer = useCallback( | ||
(layer: Layer) => { | ||
layersRef.current = [...layersRef.current, layer]; | ||
deckGLMapboxOverlay.setProps({ layers: layersRef.current }); | ||
}, | ||
[deckGLMapboxOverlay], | ||
); | ||
|
||
const removeLayer = useCallback( | ||
(layerId: string) => { | ||
layersRef.current = layersRef.current.filter(({ id }) => id !== layerId); | ||
deckGLMapboxOverlay.setProps({ layers: layersRef.current }); | ||
}, | ||
[deckGLMapboxOverlay], | ||
); | ||
|
||
const value = useMemo(() => ({ addLayer, removeLayer }), [addLayer, removeLayer]); | ||
|
||
return ( | ||
<DeckGLMapboxOverlayContext.Provider value={value}> | ||
{children} | ||
</DeckGLMapboxOverlayContext.Provider> | ||
); | ||
}; | ||
|
||
export default DeckglMapboxProvider; |
Oops, something went wrong.