diff --git a/shared/compute-cluster.ts b/shared/compute-cluster.ts index 370cc551..99de08b5 100644 --- a/shared/compute-cluster.ts +++ b/shared/compute-cluster.ts @@ -4,7 +4,7 @@ import type { Location } from '../types/location.ts' import { toPoint } from './index.ts' export const CLUSTERS_MAX_ZOOM = 17 -export const algorithm = new Supercluster({ radius: 88, maxZoom: CLUSTERS_MAX_ZOOM }) +export const algorithm = (radius: number) => new Supercluster({ radius, maxZoom: CLUSTERS_MAX_ZOOM }) export function computeCluster(algorithm: Supercluster, locations: Location[], { zoom, boundingBox: bbox }: ClusterArea): ComputedClusterSet { const singles: Location[] = [] diff --git a/src/stores/cluster.ts b/src/stores/cluster.ts index 534ee18a..acf22292 100644 --- a/src/stores/cluster.ts +++ b/src/stores/cluster.ts @@ -77,7 +77,7 @@ export const useCluster = defineStore('cluster', () => { async function getClusterFromClient(): Promise { const locations = await getLocations(boundingBox.value!) - return computeCluster(algorithm, locations, { boundingBox: boundingBox.value!, zoom: zoom.value }) + return computeCluster(algorithm(80), locations, { boundingBox: boundingBox.value!, zoom: zoom.value }) } async function getClusterFromDatabase(): Promise { diff --git a/supabase/deno.jsonc b/supabase/deno.jsonc index 6c49bbd0..ab89a09d 100644 --- a/supabase/deno.jsonc +++ b/supabase/deno.jsonc @@ -20,7 +20,7 @@ "lock": false, "tasks": { "run": "deno run --allow-env --allow-read --allow-net ./functions/generate-locations-clusters-set/index.ts", - "deploy": "npx supabase functions deploy generate-locations-clusters-set --import-map supabase/import_map.json --no-verify-jwt", + "deploy": "npx supabase functions deploy generate-locations-clusters-set --import-map supabase/import_map.json", "og:dev": "npx supabase functions serve og-image --no-verify-jwt --env-file .env", "og:deploy": "npx supabase functions deploy og-image --import-map supabase/import_map.json" } diff --git a/supabase/functions/generate-locations-clusters-set/index.ts b/supabase/functions/generate-locations-clusters-set/index.ts index 1838bca1..ae16807c 100644 --- a/supabase/functions/generate-locations-clusters-set/index.ts +++ b/supabase/functions/generate-locations-clusters-set/index.ts @@ -33,9 +33,12 @@ const locations = await getLocations(dbArgs, bbox) const minZoom = Number(Deno.env.get('MIN_ZOOM')) const maxZoom = Number(Deno.env.get('MAX_ZOOM')) +const radius: Record + = Array.from({ length: maxZoom - minZoom + 1 }, (_, i) => 120 + i * 30 / (maxZoom - minZoom)).reduce((acc, radius, i) => ({ ...acc, [minZoom + i]: radius }), {}) + const promises: Promise[] = [] for (let zoom = minZoom; zoom <= maxZoom; zoom++) { - const res = computeCluster(algorithm, locations, { zoom, boundingBox: bbox }) + const res = computeCluster(algorithm(radius[zoom]), locations, { zoom, boundingBox: bbox }) const singles: InsertLocationsClustersSetParamsItem[] = (res.singles as Location[]).map(({ lng, lat, uuid }) => ({ lat, lng, count: 1, locationUuid: uuid })) promises.push(insertLocationsClusterSet(dbArgs, { zoom_level: zoom,