Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/frontend/src/Components/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,35 @@ export default function DriveBCMap(props) {
};
}, []);

// Auto-open panel from URL params on initial load
useEffect(() => {
if (!mapRendered) return;

const type = searchParams.get('type');
const id = searchParams.get('id');

if (!type || !id) return;

if (type === 'advisory') {
// Advisories haven't loaded yet β€” wait for them, don't give up.
if (!filteredAdvisories || !filteredAdvisories.length) return;
const advisoryData = filteredAdvisories?.find(a => a.id === parseInt(id));
if (advisoryData) {
setTimeout(() => {
const olFeature = new Feature();
olFeature.set('type', 'advisory');
olFeature.set('id', advisoryData.id);
olFeature.set('data', advisoryData);
updateClickedFeature(olFeature);
}, 500);
}
else {
// Advisories loaded but this id genuinely doesn't exist
setStaleLinkMessage(true);
}
}
}, [mapRendered, filteredAdvisories]);

/* Map operations on location search */
useEffect(() => {
if (searchLocationFrom && searchLocationFrom.length) {
Expand Down Expand Up @@ -996,9 +1025,11 @@ export default function DriveBCMap(props) {
useEffect(() => {
if (searchParamInitialized.current) {
if (!clickedFeature) {
searchParams.delete('type');
if (searchParams.get('type') !== 'advisory') {
searchParams.delete('type');
searchParams.delete('id');
}
searchParams.delete('display_category');
searchParams.delete('id');
searchParams.delete('camIndex');
setSearchParams(searchParams, { replace: true });
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/Components/map/panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const resizePanel = (panelRef, clickedFeature, setMaximizedPanel) => {

export const togglePanel = (panelRef, resetClickedStates, clickedFeatureRef, updateClickedFeature, pushMargins, searchedRoutes) => {
if (searchedRoutes) {
panelRef.current.classList.remove('maximized');
panelRef.current?.classList.remove('maximized');
resetClickedStates(null, clickedFeatureRef, updateClickedFeature);
return;
}
Expand Down
Loading