Skip to content

Commit

Permalink
Zoom to bounding box specified as bbox=
Browse files Browse the repository at this point in the history
Fixes #11.
  • Loading branch information
simon04 committed Jun 14, 2024
1 parent 0fc07b3 commit 87f1cb3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DANGER_RATINGS, type DangerRatingConfig } from "./danger-ratings";
const searchParams = new URL(location.href).searchParams;
const date = searchParams.get("date") || "";
const regions: Regions = searchParams.get("regions") || "";
const bbox = searchParams.get("bbox") || "";
const details = searchParams.get("details") || "";
if (!date || !regions) {
const now = new Date();
Expand All @@ -56,7 +57,7 @@ function route(date: string | Date, regions: Regions, replace = false) {
if (date instanceof Date) {
date = date.toISOString().slice(0, "2006-01-02".length);
}
const params = new URLSearchParams({ date, regions, details });
const params = new URLSearchParams({ date, regions, bbox, details });
params.forEach((value, key) => value || params.delete(key));
const url = "?" + params;
if (replace) {
Expand Down Expand Up @@ -142,6 +143,13 @@ function initMap() {
],
});

if (bbox) {
// Austria: bbox=9.47996951665,46.4318173285,16.9796667823,49.0390742051
const [left, bottom, right, top] = bbox.split(",").map((v) => +v);
const extent = [...fromLonLat([left, bottom]), ...fromLonLat([right, top])];
map.getView().fit(extent, { size: map.getSize() });
}

map.addInteraction(new ClosePopup());

map.addControl(new GeolocationButton());
Expand Down

0 comments on commit 87f1cb3

Please sign in to comment.