Skip to content

Commit

Permalink
Reset highlighted geometry when mouse leaves map
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 15, 2024
1 parent d2b1d5c commit a08e491
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend/src/containers/map/content/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ const MainMap: FCWithMessages = () => {
layersInteractive.length &&
layersInteractiveData.some((l) => {
const attributes = l.attributes as LayerTyped;
console.log(l);
return attributes?.interaction_config?.events.some((ev) => ev.type === 'click');
})
) {
Expand Down Expand Up @@ -239,11 +238,15 @@ const MainMap: FCWithMessages = () => {
[setPopup, drawState.active, safelySetFeatureState]
);

const handleMouseLeave = useCallback(() => {
if (popup?.features?.length) return;
const handleMouseOut = useCallback(() => {
safelyResetFeatureState();
setPopup({});
}, [popup?.features?.length, safelyResetFeatureState, setPopup]);

if (popup?.type !== 'click') {
// If the popup was opened through a click, we keep it open so that the user can eventually
// interact with it's content
setPopup({});
}
}, [safelyResetFeatureState, popup, setPopup]);

const initialViewState: ComponentProps<typeof Map>['initialViewState'] = useMemo(() => {
if (URLBbox) {
Expand Down Expand Up @@ -325,7 +328,7 @@ const MainMap: FCWithMessages = () => {
onClick={handleMapClick}
onMoveEnd={handleMoveEnd}
onMouseMove={!disableMouseMove && handleMouseMove}
onMouseLeave={handleMouseLeave}
onMouseOut={handleMouseOut}
attributionControl={false}
cursor={cursor}
>
Expand Down

0 comments on commit a08e491

Please sign in to comment.