Skip to content

Commit

Permalink
Sentry 2G - Wait till map load to add map layer and events
Browse files Browse the repository at this point in the history
  • Loading branch information
seadeep42 committed Jan 9, 2024
1 parent ea0a40f commit 0082004
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/components/selected-bus-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,29 @@ const SelectedBusDetails = ({
popup.remove();
};

currentRef.addSource(
"intermediate_stops",
getIntermediateStopsGeoJson(stops),
);
currentRef.addLayer({
id: "intermediate_stops",
source: "intermediate_stops",
...MAP_STYLE_INTERMEDIATE_STOP,
});

// Show bus stop name on hovering on the circle
currentRef.on("mouseenter", "intermediate_stops", showPopup);
currentRef.on("mouseleave", "intermediate_stops", hidePopup);
console.log(currentRef);

const addLayerAndEvents = () => {
currentRef.addSource(
"intermediate_stops",
getIntermediateStopsGeoJson(stops),
);
currentRef.addLayer({
id: "intermediate_stops",
source: "intermediate_stops",
...MAP_STYLE_INTERMEDIATE_STOP,
});

// Show bus stop name on hovering on the circle
currentRef.on("mouseenter", "intermediate_stops", showPopup);
currentRef.on("mouseleave", "intermediate_stops", hidePopup);
}

if(currentRef._loaded) {
addLayerAndEvents();
} else {
currentRef?.on("load", addLayerAndEvents);
}

return () => {
if (!currentRef) {
Expand Down

0 comments on commit 0082004

Please sign in to comment.