Skip to content

Commit

Permalink
fix(directions): fixed zoom on route to include stops
Browse files Browse the repository at this point in the history
  • Loading branch information
LAMM26 committed Nov 12, 2024
1 parent d8297cb commit 6edb0e0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/geo/src/lib/directions/directions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
Expand Down

0 comments on commit 6edb0e0

Please sign in to comment.