Skip to content

Commit

Permalink
Merge branch 'main' into refactor/sdk-intergration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmedhossamdev committed Aug 24, 2024
2 parents a82174e + 706f226 commit 8a294bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 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'
}
]
});
}

0 comments on commit 8a294bf

Please sign in to comment.