Skip to content

Commit

Permalink
Add fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijos committed Jan 13, 2024
1 parent 120a846 commit 18ded4b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/routes/(protected)/admin/map/live/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@
import type { PageData } from './$types';
import type { CityPolygonFeature } from '$lib/types/CityPolygonFeature';
import type { ZonePolygonFeature } from '$lib/types/ZonePolygonFeature';
import type { Bike } from '$lib/types/Bike';
export let data: PageData;
interface BikePoint {
id: number;
coords: [number, number];
charge_perc: number;
}
let map: MaplibreMap;
mapStore.subscribe((value) => (map = value));
Expand Down Expand Up @@ -53,12 +48,12 @@
// Cache popups
let popups: { [key: number]: maplibregl.Popup } = {};
let updateBuffer: BikePoint[] = [];
let updateBuffer: Bike[] = [];
// Set a threshold for the batch size
let BATCH_SIZE = 500;
const updateBikePositionsBatched = (batch: BikePoint[]) => {
const updateBikePositionsBatched = (batch: Bike[]) => {
// Update the bikePointFeatures array in bulk
data.bikes = data.bikes.map((feature: BikePointFeature) => {
const update = batch.find((u) => u.id === feature.properties.id);
Expand All @@ -69,6 +64,13 @@
geometry: {
...feature.geometry,
coordinates: update.coords
},
properties: {
...feature.properties,
charge_perc: update.charge_perc,
active: update.active,
status_descr: update.status_descr,
status_id: update.status_id
}
};
}
Expand Down Expand Up @@ -100,7 +102,7 @@
};
// Function to handle a new point received from the event source
const handleNewPoint = (point: BikePoint) => {
const handleNewPoint = (point: Bike) => {
// Add the update to the buffer
updateBuffer.push(point);
Expand Down

0 comments on commit 18ded4b

Please sign in to comment.