Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c768eb

Browse files
committedSep 3, 2024
Merge branch 'main' into feat/map-type-toggle-button
2 parents e245a7d + 3ede900 commit 9c768eb

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed
 

‎src/components/map/GoogleMap.svelte‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
} from '$env/static/public';
1010
1111
import { debounce } from '$lib/utils';
12-
import { pushState } from '$app/navigation';
1312
import { createMap, loadGoogleMapsLibrary, nightModeStyles } from '$lib/googleMaps';
1413
import LocationButton from '$lib/LocationButton/LocationButton.svelte';
1514
import StopMarker from './StopMarker.svelte';
1615
import RouteMap from './RouteMap.svelte';
16+
1717
import MapTypeButton from '$lib/MapTypeButton/MapTypeButton.svelte';
18+
import { faBus } from '@fortawesome/free-solid-svg-icons';
19+
import {
20+
RouteType,
21+
routePriorities,
22+
prioritizedRouteTypeForDisplay
23+
} from '../../config/routeConfig';
1824
1925
export let selectedTrip = null;
2026
export let selectedRoute = null;
@@ -32,6 +38,7 @@
3238
3339
let markers = [];
3440
let allStops = [];
41+
let routeReference = [];
3542
3643
async function loadStopsForLocation(lat, lng) {
3744
const response = await fetch(`/api/oba/stops-for-location?lat=${lat}&lng=${lng}`);
@@ -63,16 +70,17 @@
6370
async function loadStopsAndAddMarkers(lat, lng) {
6471
const json = await loadStopsForLocation(lat, lng);
6572
const newStops = json.data.list;
73+
routeReference = json.data.references?.routes || [];
6674
6775
allStops = [...new Map([...allStops, ...newStops].map((stop) => [stop.id, stop])).values()];
6876
6977
clearAllMarkers();
7078
7179
if (showRoute && selectedRoute) {
7280
const stopsToShow = allStops.filter((s) => s.routeIds.includes(selectedRoute.id));
73-
stopsToShow.forEach((s) => addMarker(s));
81+
stopsToShow.forEach((s) => addMarker(s, routeReference));
7482
} else {
75-
newStops.forEach((s) => addMarker(s));
83+
newStops.forEach((s) => addMarker(s, routeReference));
7684
}
7785
}
7886
@@ -113,17 +121,29 @@
113121
allStops.forEach((s) => addMarker(s));
114122
}
115123
116-
function addMarker(s) {
124+
function addMarker(s, routeReference) {
117125
const container = document.createElement('div');
118126
document.body.appendChild(container);
119127
128+
let icon = faBus;
129+
130+
if (routeReference && routeReference.length > 0) {
131+
const availableRoutes = s.routeIds
132+
.map((id) => routeReference.find((r) => r.id === id))
133+
.filter(Boolean);
134+
const routeTypes = new Set(availableRoutes.map((r) => r.type));
135+
const prioritizedType =
136+
routePriorities.find((type) => routeTypes.has(type)) || RouteType.UNKNOWN;
137+
icon = prioritizedRouteTypeForDisplay(prioritizedType);
138+
}
139+
120140
new StopMarker({
121141
target: container,
122142
props: {
123143
stop: s,
144+
icon,
124145
onClick: () => {
125146
selectedStopID = s.id;
126-
pushState(`/stops/${s.id}`);
127147
dispatch('stopSelected', { stop: s });
128148
}
129149
}

‎src/components/map/StopMarker.svelte‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<script>
2-
import { faBus, faCaretUp } from '@fortawesome/free-solid-svg-icons';
2+
import { faCaretUp } from '@fortawesome/free-solid-svg-icons';
33
import { FontAwesomeIcon } from '@fortawesome/svelte-fontawesome';
44
export let stop;
55
export let onClick;
6+
export let icon;
67
</script>
78

89
<button class="custom-marker dark:border-[#5a2c2c]" on:click={onClick}>
910
<span class="bus-icon dark:text-white">
10-
<FontAwesomeIcon icon={faBus} class="text-black " />
11+
<FontAwesomeIcon {icon} class=" text-black" />
1112
{#if stop.direction}
1213
<span class="direction-arrow {stop.direction.toLowerCase()} dark:text-white">
1314
<FontAwesomeIcon icon={faCaretUp} />

‎src/config/routeConfig.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
faBus,
3+
faFerry,
4+
faTrainSubway,
5+
faTrain,
6+
faCableCar
7+
} from '@fortawesome/free-solid-svg-icons';
8+
9+
const RouteType = {
10+
LIGHT_RAIL: 0,
11+
SUBWAY: 1,
12+
RAIL: 2,
13+
BUS: 3,
14+
FERRY: 4,
15+
CABLE_CAR: 5,
16+
GONDOLA: 6,
17+
FUNICULAR: 7,
18+
UNKNOWN: 999
19+
};
20+
21+
const routePriorities = [
22+
RouteType.FERRY,
23+
RouteType.LIGHT_RAIL,
24+
RouteType.SUBWAY,
25+
RouteType.RAIL,
26+
RouteType.BUS,
27+
RouteType.CABLE_CAR,
28+
RouteType.GONDOLA,
29+
RouteType.FUNICULAR,
30+
RouteType.UNKNOWN
31+
];
32+
33+
const prioritizedRouteTypeForDisplay = (routeType) => {
34+
switch (routeType) {
35+
case RouteType.FERRY:
36+
return faFerry;
37+
case RouteType.LIGHT_RAIL:
38+
case RouteType.SUBWAY:
39+
case RouteType.CABLE_CAR:
40+
return faTrainSubway;
41+
case RouteType.RAIL:
42+
return faTrain;
43+
case RouteType.GONDOLA:
44+
return faCableCar;
45+
default:
46+
return faBus;
47+
}
48+
};
49+
50+
export { RouteType, routePriorities, prioritizedRouteTypeForDisplay };

‎src/routes/+layout.svelte‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<script>
2+
import Header from '$components/navigation/Header.svelte';
23
import '../app.css';
34
import { config } from '@fortawesome/fontawesome-svg-core';
45
import '@fortawesome/fontawesome-svg-core/styles.css';
56
config.autoAddCss = false; // Tell Font Awesome to skip adding the CSS automatically since it's being imported above
67
</script>
78

89
<div class="relative h-dvh w-full">
10+
<div class="absolute w-full">
11+
<Header />
12+
</div>
913
<div>
1014
<slot></slot>
1115
</div>

‎src/routes/+page.svelte‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { pushState } from '$app/navigation';
23
import GoogleMap from '../components/map/GoogleMap.svelte';
34
import Header from '../components/navigation/Header.svelte';
45
import ModalPane from '../components/navigation/ModalPane.svelte';
@@ -15,6 +16,7 @@
1516
1617
function stopSelected(event) {
1718
stop = event.detail.stop;
19+
pushState(`/stops/${stop.id}`);
1820
}
1921
2022
function closePane() {

0 commit comments

Comments
 (0)
Please sign in to comment.