Files
WeatherTool/web/src/pages/harmonie/DrawView.tsx
T

43 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-02-28 13:01:08 +02:00
import { Component, createEffect, Signal } from 'solid-js'
2025-03-14 11:31:47 +02:00
import { LoadingSpinner } from '../../components/spinner/LoadingSpinner'
2025-02-28 13:01:08 +02:00
import { CROP_BOUNDS, DrawOptions, GribMessage } from './interfaces'
import { drawGrib } from './draw/drawGrib'
export const DrawView: Component<{
isLoadingSignal: Signal<boolean>,
options: DrawOptions;
2025-02-21 23:07:49 +02:00
canvasSignal: Signal<HTMLCanvasElement | undefined>,
cachedMessagesSignal: Signal<GribMessage[]>,
cachedBuffersSignal: Signal<Uint8Array[]>,
cachedBitmasksSignal: Signal<Uint8Array[]>,
}> = ({
isLoadingSignal: [getIsLoading, setIsLoading],
options,
2025-02-21 23:07:49 +02:00
canvasSignal: [getCanvas, setCanvas],
cachedMessagesSignal: [getCachedMessages],
cachedBuffersSignal: [getCachedBuffers],
cachedBitmasksSignal: [getCachedBitmasks],
}) => {
createEffect(async () => {
setIsLoading(true)
const canvas = getCanvas()!
2025-07-11 00:00:11 +03:00
canvas.style.width = '100%'
const ctx = canvas.getContext('2d')!
ctx.clearRect(0, 0, canvas.width, canvas.height)
const cropBounds = options.getIsCrop() ? CROP_BOUNDS : undefined
const contour = options.getIsContour()
const isInterpolated = options.getIsInterpolated()
if (getCachedMessages().length === 0) return;
await new Promise(resolve => setTimeout(resolve, 100))
// hack to show loading spinner
drawGrib(canvas, getCachedMessages(), getCachedBuffers(), getCachedBitmasks(), cropBounds, contour, isInterpolated)
setIsLoading(false)
})
return <>
{ getIsLoading() && <LoadingSpinner text='' />}
<canvas ref={setCanvas} style={{ display: getIsLoading() ? 'none' : 'block' }} />
</>
}