Skip to content
Merged
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
15 changes: 15 additions & 0 deletions apps/src/components/map-layers/map-legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ const MapLegend: React.FC = () => {

const rootRef = useRef<Root | null> (null);

/**
* Open legend by default when the map container has space for legend.
* Legend max width is 430px (MapLegendOpenControl.MAX_LEGEND_WIDTH)
* Only check on the initial mount, no resize handling needed.
*/
useEffect(() => {
if (!map) {
return;
}
const container = map.getContainer();
const { width } = container.getBoundingClientRect();
const shouldBeOpen = width >= MapLegendOpenControl.maxLegendWidth * 1.5;
setIsOpen(shouldBeOpen);
}, [map]);

/**
* This hook creates the legend control once the map is ready. It only
* creates the control, the content of the legend itself is rendered by
Expand Down