From 7a50bec048e0b0df3bb626cc1bbcc199cf86aa45 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 23 Dec 2024 13:44:02 -0800 Subject: [PATCH] implement method to get polyline data --- src/repositoryDataLoader.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/repositoryDataLoader.ts b/src/repositoryDataLoader.ts index 0709227..b3b013b 100644 --- a/src/repositoryDataLoader.ts +++ b/src/repositoryDataLoader.ts @@ -248,6 +248,22 @@ export class RepositoryDataLoader { } private async updatePolylineDataForExistingRoutesAndApiResponse(json: any) { + if (json.routePoints) { + await Promise.all(Object.keys(json.routePoints).map(async (routeId) => { + const routePoints = json.routePoints[routeId][0]; + const existingRoute = await this.repository.getRouteById(routeId); + if (!existingRoute) return; + + existingRoute.polylineCoordinates = routePoints.map((point: any) => { + return { + latitude: parseFloat(point.lat), + longitude: parseFloat(point.lng), + }; + }); + + await this.repository.addOrUpdateRoute(existingRoute); + })) + } } } \ No newline at end of file