]> git.r.bdr.sh - rbdr/canvas/blob - src/lib/components/sensor.svelte
Connect sensor to database
[rbdr/canvas] / src / lib / components / sensor.svelte
1 <script>
2 import { browser } from '$app/env';
3 import { maxSize } from '$lib/config';
4 import { sensor } from '$lib/stores/widgets';
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(() => {
20 sensor.set({ left, top, right, bottom });
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>