]> git.r.bdr.sh - rbdr/canvas/blame - src/lib/components/sensor.svelte
Connect sensor to database
[rbdr/canvas] / src / lib / components / sensor.svelte
CommitLineData
2df937df
RBR
1<script>
2 import { browser } from '$app/env';
3 import { maxSize } from '$lib/config';
c30e6881 4 import { sensor } from '$lib/stores/widgets';
2df937df
RBR
5
6 export let x;
7 export let y;
8
9 const kSensorSize = 2;
10
11 let left;
12 let right;
13 let top;
14 let bottom;
15
16 let timer;
17 const fetchItems = function fetchItems( left, top, right, bottom ) {
18 clearTimeout(timer);
19 timer = setTimeout(() => {
c30e6881 20 sensor.set({ left, top, right, bottom });
2df937df
RBR
21 }, 50);
22 }
23
24 $: {
25 if (browser) {
26 left = x - window.screen.width * kSensorSize;
27 top = y - window.screen.height * kSensorSize;
28 right = x + window.screen.width * kSensorSize;
29 bottom = y + window.screen.height * kSensorSize;
30
31 fetchItems(left, top, right, bottom);
32 }
33 }
34
35</script>