Skip to content

Commit

Permalink
Merge pull request #36 from OneBusAway/enhancement/polyline-arrow-symbol
Browse files Browse the repository at this point in the history
Enhancement/polyline-arrow-symbol
  • Loading branch information
aaronbrethorst authored Aug 23, 2024
2 parents f16738a + 794fdd8 commit 706f226
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/map/RouteMap.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
/* global google */
import { onMount, onDestroy } from 'svelte';
import { createPolyline, loadGoogleMapsLibrary } from '$lib/googleMaps';
import { createPolyline, loadGoogleMapsLibrary, addArrowToPolyline } from '$lib/googleMaps';
export let map;
export let tripId;
Expand Down Expand Up @@ -39,6 +39,7 @@
if (shape) {
polyline = await createPolyline(shape);
addArrowToPolyline(polyline);
polyline.setMap(map);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const COLORS = {
POLYLINE: '#00FF00',
POLYLINE_ARROW: '#8250DF'
};
31 changes: 30 additions & 1 deletion src/lib/googleMaps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { COLORS } from '$lib/colors';

/**
* Loads the Google Maps JavaScript library.
* @param {string} apiKey - The API key for accessing the Google Maps API.
Expand Down Expand Up @@ -154,10 +156,37 @@ export async function createPolyline(shape) {
const polyline = new window.google.maps.Polyline({
path,
geodesic: true,
strokeColor: '#00FF00',
strokeColor: COLORS.POLYLINE,
strokeOpacity: 1.0,
strokeWeight: 4
});

return polyline;
}

/**
* Adds an arrow to the polyline.
* @param {google.maps.Polyline} polyline - The polyline to which the arrow will be added.
*/
export function addArrowToPolyline(polyline) {
if (!(polyline instanceof google.maps.Polyline)) {
console.error('Invalid polyline');
return;
}
const arrowSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 2,
strokeColor: COLORS.POLYLINE_ARROW,
strokeWeight: 3
};

polyline.setOptions({
icons: [
{
icon: arrowSymbol,
offset: '100%',
repeat: '50px'
}
]
});
}
1 change: 0 additions & 1 deletion src/routes/api/oba/shape/[shapeId]/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export async function GET({ params }) {

try {
const response = await fetch(apiURL);
console.log('response:', response);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down

0 comments on commit 706f226

Please sign in to comment.