-
Notifications
You must be signed in to change notification settings - Fork 4
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
Implemented the Bus Route, Draw polyline feat, and hidden unrelated stops #31
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<script> | ||
/* global google */ | ||
import { onMount, onDestroy } from 'svelte'; | ||
import { createPolyline, loadGoogleMapsLibrary } from '$lib/googleMaps'; | ||
|
||
export let map; | ||
export let tripId; | ||
|
||
let shapeId = null; | ||
let polyline; | ||
let stopMarkers = []; | ||
let infoWindow; | ||
let tripData = null; | ||
let shapeData = null; | ||
|
||
onMount(async () => { | ||
await loadGoogleMapsLibrary(); | ||
await loadRouteData(); | ||
}); | ||
|
||
onDestroy(() => { | ||
polyline?.setMap(null); | ||
stopMarkers.forEach((marker) => marker.setMap(null)); | ||
infoWindow?.close(); | ||
}); | ||
|
||
async function loadRouteData() { | ||
const tripResponse = await fetch(`/api/oba/trip-details/${tripId}`); | ||
tripData = await tripResponse.json(); | ||
|
||
const tripReferences = tripData?.data?.references?.trips; | ||
const moreTripData = tripReferences?.find((t) => t.id == tripId); | ||
shapeId = moreTripData?.shapeId; | ||
|
||
if (shapeId) { | ||
const shapeResponse = await fetch(`/api/oba/shape/${shapeId}`); | ||
shapeData = await shapeResponse.json(); | ||
const shape = shapeData?.data?.entry?.points; | ||
|
||
if (shape) { | ||
polyline = await createPolyline(shape); | ||
polyline.setMap(map); | ||
} | ||
} | ||
|
||
const stopTimes = tripData?.data?.entry?.schedule?.stopTimes ?? []; | ||
const stops = tripData?.data?.references?.stops ?? []; | ||
|
||
for (const stopTime of stopTimes) { | ||
const stop = stops.find((s) => s.id === stopTime.stopId); | ||
if (stop) { | ||
addStopMarker(stopTime, stop); | ||
} | ||
} | ||
} | ||
|
||
function addStopMarker(stopTime, stop) { | ||
const marker = new google.maps.Marker({ | ||
position: { lat: stop.lat, lng: stop.lon }, | ||
map: map, | ||
icon: { | ||
path: google.maps.SymbolPath.CIRCLE, | ||
scale: 5, | ||
fillColor: '#FFFFFF', | ||
fillOpacity: 1, | ||
strokeWeight: 1, | ||
strokeColor: '#000000' | ||
} | ||
}); | ||
|
||
marker.addListener('click', () => { | ||
infoWindow?.close(); | ||
|
||
infoWindow = new google.maps.InfoWindow({ | ||
content: `<div> | ||
<h3>${stop.name}</h3> | ||
<p>Arrival time: ${new Date(stopTime.arrivalTime * 1000).toLocaleTimeString()}</p> | ||
</div>` | ||
}); | ||
infoWindow.open(map, marker); | ||
}); | ||
|
||
stopMarkers.push(marker); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { error, json } from '@sveltejs/kit'; | ||
import { PUBLIC_OBA_SERVER_URL as baseURL } from '$env/static/public'; | ||
import { PRIVATE_OBA_API_KEY as apiKey } from '$env/static/private'; | ||
|
||
export async function GET({ params }) { | ||
const { shapeId } = params; | ||
|
||
let apiURL = `${baseURL}/api/where/shape/${shapeId}.json?key=${apiKey}`; | ||
|
||
try { | ||
const response = await fetch(apiURL); | ||
console.log('response:', response); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
return json(data); | ||
} catch (err) { | ||
console.error('Error fetching shape data:', err); | ||
throw error(500, 'Unable to fetch shape data.'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same here
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.
done