From 6edb0e02db273331def65471b851b5ecde314cad Mon Sep 17 00:00:00 2001 From: Maxime Lamer Date: Tue, 12 Nov 2024 15:16:40 -0500 Subject: [PATCH] fix(directions): fixed zoom on route to include stops --- .../lib/directions/directions.component.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/directions/directions.component.ts b/packages/geo/src/lib/directions/directions.component.ts index 8e01e0f43..555d4402c 100644 --- a/packages/geo/src/lib/directions/directions.component.ts +++ b/packages/geo/src/lib/directions/directions.component.ts @@ -205,8 +205,23 @@ export class DirectionsComponent implements OnInit, OnDestroy { .find((route) => route.properties.active); if (activeRoute) { - activeRoute.ol.getGeometry(); - const routeExtent = activeRoute.ol.getGeometry().getExtent(); + const stopsCoordinates = this.stopsStore + .all() + .map((stop) => + olProj.transform(stop.coordinates, 'EPSG:4326', 'EPSG:3857') + ); + const routeCoordinates = activeRoute.geometry + .coordinates as number[][]; + const coordinates = [...stopsCoordinates, ...routeCoordinates]; + const routeExtent = coordinates.reduce( + ([x_min, y_min, x_max, y_max], [x, y]) => [ + Math.min(x_min, x), + Math.min(y_min, y), + Math.max(x_max, x), + Math.max(y_max, y) + ], + [Infinity, Infinity, -Infinity, -Infinity] + ); this.routesFeatureStore.layer.map.viewController.zoomToExtent( routeExtent as [number, number, number, number] );