Skip to content
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

Add arrival-view and instruction-view for web #162

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/ferrostar/src/navigation_controller/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))]
pub struct TripProgress {
/// The distance to the next maneuver, in meters.
pub distance_to_next_maneuver: f64,
Expand Down
19 changes: 18 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
costingOptions="${{ bicycle: { use_roads: 0.2 } }}"
></ferrostar-core>

<p class="controls">
<p class="controls controls-start">
ianthetechie marked this conversation as resolved.
Show resolved Hide resolved
<input type="text" id="destination" placeholder="Where do you want to go?" />
<span>
<button id="start">Start Navigation</button>
Expand All @@ -26,6 +26,10 @@
</span>
</p>

<p class="controls controls-stop">
ianthetechie marked this conversation as resolved.
Show resolved Hide resolved
<button id="stop">Stop Navigation</button>
</p>

<script type="module">
import { SimulatedLocationProvider, BrowserLocationProvider } from "/src/location.ts";

Expand Down Expand Up @@ -74,6 +78,9 @@

core.locationProvider = locationProvider;
core.startNavigation(route, config);

document.getElementsByClassName("controls-start")[0].style.display = "none";
document.getElementsByClassName("controls-stop")[0].style.display = "block";
ianthetechie marked this conversation as resolved.
Show resolved Hide resolved
});

simulateNavigationButton.addEventListener("click", async () => {
Expand Down Expand Up @@ -101,6 +108,16 @@

core.locationProvider = locationProvider;
core.startNavigation(route, config);

document.getElementsByClassName("controls-start")[0].style.display = "none";
document.getElementsByClassName("controls-stop")[0].style.display = "block";
});

document.getElementById("stop").addEventListener("click", () => {
core.stopNavigation();

document.getElementsByClassName("controls-start")[0].style.display = "block";
document.getElementsByClassName("controls-stop")[0].style.display = "none";
});
});
</script>
Expand Down
58 changes: 58 additions & 0 deletions web/src/arrival-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators.js";

@customElement("arrival-view")
export class ArrivalView extends LitElement {
@property()
tripState: any = null;

static styles = [
css`
.arrival-view-card {
display: flex;
align-items: center;
justify-content: space-around;
padding: 20px;
background-color: white;
border-radius: 50px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.arrival-text {
font-size: x-large;
margin: 0 15px;
}
`,
];

getArrivalTime(seconds: number) {
const now = new Date();
const minutesToAdd = Math.round(seconds / 60);
const arrivalTime = new Date(now.getTime() + minutesToAdd * 60000);
CatMe0w marked this conversation as resolved.
Show resolved Hide resolved
const hours = arrivalTime.getHours();
const minutes = arrivalTime.getMinutes();
return `${hours}:${minutes < 10 ? "0" : ""}${minutes}`;
}

getDistanceRemaining(meters: number) {
return `${Math.round(meters).toLocaleString()}m`;
}

getDurationRemaining(seconds: number) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}m ${remainingSeconds}s`;
}

render() {
if (this.tripState?.Navigating) {
return html`
<div class="arrival-view-card">
<p class="arrival-text">${this.getArrivalTime(this.tripState.Navigating.progress.durationRemaining)}</p>
<p class="arrival-text">${this.getDistanceRemaining(this.tripState.Navigating.progress.distanceRemaining)}</p>
<p class="arrival-text">${this.getDurationRemaining(this.tripState.Navigating.progress.durationRemaining)}</p>
</div>
`;
}
}
}
4 changes: 4 additions & 0 deletions web/src/assets/directions/arrive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/arrive_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/arrive_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/arrive_straight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_slight_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_slight_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_straight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/continue_uturn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/depart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/depart_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/depart_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/depart_straight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/end_of_road_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/end_of_road_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/flag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/fork.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/fork_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/directions/fork_right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading