Skip to content

Conversation

@renoirb
Copy link
Contributor

@renoirb renoirb commented Dec 12, 2025

Description

Opens the map legend by default when the map container has sufficient width to accommodate it.

Changes:

  • Legend now opens automatically on page load when map container width ≥ 430px (the legend's max width)
  • Uses map container's actual width rather than window width for better accuracy in comparison view
  • No resize handling per requirements - state set only on initial mount

Implementation:

  • Added useEffect in MapLegend component to check map container width on mount
  • References existing MapLegendOpenControl.maxLegendWidth constant (430px)
  • Uses Leaflet's map.getContainer().getBoundingClientRect() for precise measurement

Rationale

Why 430px instead of 768px:
The original requirement specified 768px screen width, but using the legend's actual max width (430px) is more semantically correct and provides better behavior:

  • Checks if there's actual space for the legend itself
  • Self-documenting code that references the legend's own width constant
  • Automatically adjusts if MAX_LEGEND_WIDTH changes in future

Why map container width instead of window width:

  • More accurate in comparison view where two maps sit side-by-side
  • Each map's legend state becomes independent
  • Uses Leaflet API properly via map.getContainer()

Testing

Manual testing needed:

  • Regular map view: legend opens when container ≥ 430px
  • Regular map view: legend closed when container < 430px
  • Comparison map view: each legend opens/closes independently based on its map's width
  • Behavior at exactly 430px boundary
  • No resize handling - legend state persists after window resize

Related ticket

  • CLIM-1233

Related PRs

Screenshots

@renoirb renoirb self-assigned this Dec 12, 2025
@renoirb
Copy link
Contributor Author

renoirb commented Dec 12, 2025

Screenshots 2025-12-11

CLIM-1233_Progress_2025-12-11_21-48-32

Opens automatically based on available space, even when resized.

CLIM-1233_Progress_2025-12-11_22-08-13

We might want to bring a little bit down the spacing between the opened legend box and the search bar

@renoirb renoirb force-pushed the CLIM-1233_Map-legend-opened-by-default branch from 25b46bb to 4ebff88 Compare December 12, 2025 03:22
@renoirb renoirb force-pushed the CLIM-1233_Map-legend-opened-by-default branch from 4ebff88 to 5bbddcd Compare December 15, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants