-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset map viewport when returning to Choose project and opening a pro… #211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { Feature, Polygon } from "geojson"; | ||
import { LngLat, type Map } from "maplibre-gl"; | ||
import { LngLat, type LngLatBoundsLike, type Map } from "maplibre-gl"; | ||
import { type AreaProps } from "route-snapper-ts"; | ||
import { get, writable, type Writable } from "svelte/store"; | ||
import type { Backend } from "./wasm"; | ||
|
@@ -65,6 +65,8 @@ export let currentProjectKey: Writable<string> = writable(""); | |
// False until user activates | ||
export let showAbout: Writable<boolean> = writable(false); | ||
|
||
export let appFocus: Writable<"global" | "cnt"> = writable("global"); | ||
|
||
export let backend: Writable<Backend | null> = writable(null); | ||
export let route_pt_a: Writable<LngLat> = writable(new LngLat(0, 0)); | ||
export let route_pt_b: Writable<LngLat> = writable(new LngLat(0, 0)); | ||
|
@@ -97,3 +99,13 @@ export let useLocalVite: Writable<boolean> = writable(false); | |
export function assetUrl(path: string): string { | ||
return get(useLocalVite) ? `/${path}` : `https://assets.od2net.org/${path}`; | ||
} | ||
|
||
export function returnToChooseProject() { | ||
mode.set({ mode: "title", firstLoad: false }); | ||
|
||
let bounds = [-180, -90, 180, 90] as LngLatBoundsLike; | ||
if (get(appFocus) == "cnt") { | ||
bounds = [-8.943, 54.631, -0.901, 59.489]; | ||
} | ||
get(map)?.fitBounds(bounds, { duration: 500 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 500 is maybe a little fast, but anything too long gets annoying. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels maybe a little fast (definitely not too slow!), but not unreasonable. Let's go with it and we can always tweak it later. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ export function afterProjectLoaded() { | |
writable(0), | ||
), | ||
); | ||
get(map)!.fitBounds(get(backend)!.getBounds(), { animate: false }); | ||
get(map)!.fitBounds(get(backend)!.getBounds(), { duration: 500 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the other way: when you open a project, animate the zoom in a bit -- again, quickly. This zoom happens after the load screen. I wanted to do this during the load screen, but we'd have to mimic the backend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing it during loading rather than after would be nice, but I think that could be a low priority followup task. |
||
route_pt_a.set(randomPoint()); | ||
route_pt_b.set(randomPoint()); | ||
one_destination.set(randomPoint()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context is hard to access outside of a component, so I moved it to a store. If you prefer, we could instead try a
ChooseProjectLink
component, so that context is visibleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A store seems fine!