-
Notifications
You must be signed in to change notification settings - Fork 26
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
Enhancement/polyline-arrow-symbol #36
Changes from all commits
b117093
3a6be19
59b7e16
a364a89
af6561f
637187c
794fdd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const COLORS = { | ||
POLYLINE: '#00FF00', | ||
POLYLINE_ARROW: '#8250DF' | ||
}; |
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. | ||
|
@@ -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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a check at the beginning of the function to validate the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that’s a great idea for checking the polyline parameter. Moving to TypeScript could also improve type safety and help as the project grows. |
||
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW, | ||
scale: 2, | ||
strokeColor: COLORS.POLYLINE_ARROW, | ||
strokeWeight: 3 | ||
}; | ||
|
||
polyline.setOptions({ | ||
icons: [ | ||
{ | ||
icon: arrowSymbol, | ||
offset: '100%', | ||
repeat: '50px' | ||
} | ||
] | ||
}); | ||
} |
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.
Nice work. Great you created the colors file separately. For better visibility, we can use the polyline arrow color as
#8250DF
.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.
awesome! I will try it