Skip to content

Commit

Permalink
Merge pull request #121 from OneBusAway/fix/marker-creation-on-slow-n…
Browse files Browse the repository at this point in the history
…etwork-connections

fix: prevent multiple location selections by locking the selection
  • Loading branch information
aaronbrethorst authored Nov 14, 2024
2 parents 255db5d + 41f52ef commit 48814b5
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/components/trip-planner/TripPlan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
let fromMarker;
let toMarker;
let loading = false;
let lockSelectLocation = false;
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -74,18 +75,25 @@
}
async function selectLocation(suggestion, isFrom) {
if (isFrom) {
const response = await geocodeLocation(suggestion.text);
selectedFrom = response.location.geometry.location;
fromMarker = mapProvider.addPinMarker(selectedFrom, 'From');
fromPlace = suggestion.text;
fromResults = [];
} else {
if (lockSelectLocation) return;
lockSelectLocation = true;
try {
const response = await geocodeLocation(suggestion.text);
selectedTo = response.location.geometry.location;
toMarker = mapProvider.addPinMarker(selectedTo, 'To');
toPlace = suggestion.text;
toResults = [];
if (isFrom) {
selectedFrom = response.location.geometry.location;
fromMarker = mapProvider.addPinMarker(selectedFrom, 'From');
fromPlace = suggestion.text;
fromResults = [];
} else {
selectedTo = response.location.geometry.location;
toMarker = mapProvider.addPinMarker(selectedTo, 'To');
toPlace = suggestion.text;
toResults = [];
}
} catch (error) {
console.error('Error selecting location:', error);
} finally {
lockSelectLocation = false;
}
}
Expand Down Expand Up @@ -147,7 +155,6 @@
}
}
// clear input fields when the tab is switched
onMount(() => {
if (browser) {
window.addEventListener('tabSwitched', () => {
Expand Down

0 comments on commit 48814b5

Please sign in to comment.