Skip to content

Commit

Permalink
Use the initial camera in the URL when it's specified, otherwise zoom…
Browse files Browse the repository at this point in the history
… somewhere by default
  • Loading branch information
dabreegster committed Jun 6, 2024
1 parent 4a73c03 commit d94c6a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/lib/common/MapLibreMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
import railwayStation from "../../../assets/railway_station.png?url";
export let style: string;
// startBounds will only be used if the URL doesn't already have a camera set
export let startBounds: LngLatBoundsLike | undefined = undefined;
let styleSpec: string | StyleSpecification | null = null;
let map: Map;
let loaded = false;
// Before creating the map, check if there's a hash, because one will get set below
// TODO Change BoundaryLayer to not do this?
// Before creating the map, record if there's a camera viewport specified. If
// startBounds isn't used, other code can set one dynamically.
setContext("setCamera", !window.location.hash);
if (window.location.hash) {
startBounds = undefined;
}
$: if (loaded) {
// TODO Get rid of mapStore entirely, eventually?
Expand Down
5 changes: 2 additions & 3 deletions src/lib/draw/BoundaryLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
export let boundaryGeojson: FeatureCollection<Polygon | MultiPolygon>;
const setCamera = getContext("setCamera");
if (setCamera) {
// If the URL didn't initially have a viewport set, fit the boundary
if (getContext("setCamera")) {
$map.fitBounds(bbox(boundaryGeojson), {
padding: 20,
animate: false,
Expand Down

0 comments on commit d94c6a9

Please sign in to comment.