-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SRS-555: Implementing CrossHairToolTip marker and showing Circl…
…e for the specified radius search (#250) * SRS-698: CrossToolTipMarker for Radius Search * Circle implementation for the radius set up by the user * Making SiteMarkers disappear on clicking crosshaircursor * Addressing few review comments
- Loading branch information
1 parent
a916184
commit 5f37d98
Showing
11 changed files
with
222 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Circle, useMap, useMapEvents } from 'react-leaflet'; | ||
import { useState } from 'react'; | ||
import { LatLngTuple, LeafletMouseEvent, Map } from 'leaflet'; | ||
import { useMapCrosshairsCursor } from '../../hooks/useMapCrossHairCursor'; | ||
import { CrosshairsTooltipMarker } from './CrossHairToolTipMarker'; | ||
|
||
interface CircleLayerProps { | ||
radius: number; | ||
onCrossHairClick: () => void; | ||
} | ||
|
||
export function CircleLayer({ | ||
radius, | ||
onCrossHairClick, | ||
}: Readonly<CircleLayerProps>) { | ||
const [center, setCenter] = useState<LatLngTuple | undefined>(undefined); | ||
const map = useMap(); | ||
useMapCrosshairsCursor(map); | ||
|
||
useMapEvents({ | ||
click: (ev: LeafletMouseEvent) => { | ||
const newCenter: LatLngTuple = [ev.latlng.lat, ev.latlng.lng]; | ||
setCenter(newCenter); | ||
onCrossHairClick(); | ||
}, | ||
}); | ||
|
||
const drawCircle = center && radius > 0; | ||
|
||
return ( | ||
<> | ||
<CrosshairsTooltipMarker center={center}> | ||
Click to place center point | ||
</CrosshairsTooltipMarker> | ||
{drawCircle && ( | ||
<Circle | ||
center={center} | ||
radius={radius} | ||
stroke | ||
fill | ||
className="point-search-circle" | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ReactNode, useRef } from 'react'; | ||
import { | ||
LatLngExpression, | ||
LeafletMouseEvent, | ||
Marker as LeafletMarker, | ||
} from 'leaflet'; | ||
import { Tooltip, useMap, useMapEvent } from 'react-leaflet'; | ||
import { IconMarker } from './IconMarker'; | ||
import { crosshairsIcon, emptyIcon } from './siteMarkers/icons'; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
center?: LatLngExpression; | ||
} | ||
|
||
export function CrosshairsTooltipMarker({ children, center }: Readonly<Props>) { | ||
const map = useMap(); | ||
const markerRef = useRef<LeafletMarker>(null); | ||
|
||
useMapEvent('mousemove', (ev: LeafletMouseEvent) => { | ||
if (markerRef.current && !center) { | ||
markerRef.current.setLatLng(ev.latlng); | ||
} | ||
}); | ||
|
||
return ( | ||
<IconMarker | ||
ref={markerRef} | ||
position={center ?? map.getCenter()} | ||
icon={center ? crosshairsIcon : emptyIcon} | ||
interactive={false} | ||
draggable={false} | ||
cursor="crosshair" | ||
> | ||
{!center && ( | ||
<Tooltip | ||
permanent | ||
sticky | ||
direction="right" | ||
offset={[12, 0]} | ||
className="search-layer-tooltip" | ||
interactive={false} | ||
> | ||
{children} | ||
</Tooltip> | ||
)} | ||
</IconMarker> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
frontend/src/app/features/map/layers/RadiusSearchLayer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ActiveToolEnum } from '../../../constants/Constant'; | ||
import { CircleLayer } from '../CircleLayer'; | ||
|
||
interface RadiusSearchLayerProps { | ||
activeTool: ActiveToolEnum | null; | ||
radius: number; | ||
onCrossHairClick: () => void; | ||
} | ||
export function RadiusSearchLayer({ | ||
activeTool, | ||
radius, | ||
onCrossHairClick, | ||
}: Readonly<RadiusSearchLayerProps>) { | ||
if (activeTool === ActiveToolEnum.radiusSearch) { | ||
return <CircleLayer radius={radius} onCrossHairClick={onCrossHairClick} />; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
frontend/src/app/features/map/siteMarkers/assets/crosshairsSvg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect } from 'react'; | ||
import L from 'leaflet'; | ||
|
||
export function useMapCrosshairsCursor(map: L.Map, enabled = true) { | ||
// Show crosshairs cursor | ||
useEffect(() => { | ||
const container = map.getContainer(); | ||
if (container) { | ||
if (enabled) { | ||
L.DomUtil.addClass(container, 'crosshairs-cursor'); | ||
} | ||
return () => { | ||
L.DomUtil.removeClass(container, 'crosshairs-cursor'); | ||
}; | ||
} | ||
}, [map, enabled]); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
declare module '*.png'; | ||
declare module '*.svg'; |