From 557d10cf90239715ac276f83d76c3da41522e301 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:35:43 -0800 Subject: [PATCH] Add short ID Column for loading, add label to sqlite shapes --- app/src/utils/record-cache/sqlite-cache.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/utils/record-cache/sqlite-cache.ts b/app/src/utils/record-cache/sqlite-cache.ts index 565ab1f76..2c764c04a 100644 --- a/app/src/utils/record-cache/sqlite-cache.ts +++ b/app/src/utils/record-cache/sqlite-cache.ts @@ -34,7 +34,9 @@ const RECORD_CACHE_DB_MIGRATIONS_1 = [ const RECORD_CACHE_DB_MIGRATIONS_2 = [ `ALTER TABLE CACHED_RECORDS - ADD COLUMN GEOJSON TEXT;` + ADD COLUMN GEOJSON TEXT;`, + `ALTER TABLE CACHED_RECORDS + ADD COLUMN SHORT_ID TEXT;` ]; class SQLiteRecordCacheService extends RecordCacheService { @@ -219,14 +221,15 @@ class SQLiteRecordCacheService extends RecordCacheService { throw new Error('cache not available'); } const stringified = JSON.stringify(data); + const short_id = (data as Record)?.short_id; const geometry = (data as Record)?.geometry; const geojson = JSON.stringify(geometry) ?? null; await this.cacheDB.query( //language=SQLite - `INSERT INTO CACHED_RECORDS(ID, DATA, GEOJSON) - VALUES (?, ?, ?) + `INSERT INTO CACHED_RECORDS(ID, DATA, GEOJSON, SHORT_ID) + VALUES (?, ?, ?, ?) ON CONFLICT (ID) DO UPDATE SET DATA=?;`, - [id, stringified, geojson, stringified] + [id, stringified, geojson, short_id, stringified] ); } async loadRecordsetSourceMetadata(ids: string[]): Promise { @@ -237,7 +240,7 @@ class SQLiteRecordCacheService extends RecordCacheService { const geoJsonArr: any[] = []; const results = await this.cacheDB?.query( // language=SQLite - `SELECT GEOJSON, ID + `SELECT GEOJSON, SHORT_ID FROM CACHED_RECORDS WHERE ID IN (${ids.map(() => '?').join(', ')}) AND GEOJSON NOT NULL`, @@ -246,9 +249,11 @@ class SQLiteRecordCacheService extends RecordCacheService { results?.values?.forEach((item) => { try { - JSON.parse(item['GEOJSON'])?.forEach((shape: Feature) => { - centroidArr.push(centroid(shape)); - geoJsonArr.push(shape); + const label = item['SHORT_ID']; + JSON.parse(item['GEOJSON'])?.forEach((feature: Feature) => { + feature.properties = { name: label }; + centroidArr.push(centroid(feature)); + geoJsonArr.push(feature); }); } catch (e) { console.error('Error parsing record:', e);