Added location marker

This commit is contained in:
2023-08-15 23:06:12 +03:00
parent 410931b475
commit 7798b0170d
7 changed files with 63 additions and 4 deletions

View File

@ -0,0 +1,38 @@
import { MouseEventHandler } from 'react'
import { useMapEvent } from 'react-leaflet'
import { LatLng } from 'leaflet'
import Control from 'react-leaflet-custom-control'
import locateIcon from '../assets/locate.svg'
import styles from '../styles/Map.module.css'
import { SetState } from '../utils/types'
type LocaleButtonProps = {
setPosition: SetState<LatLng>
}
function LocateButton({ setPosition }: LocaleButtonProps) {
const map = useMapEvent('locationfound', (e) => {
setPosition(e.latlng)
map.flyTo(e.latlng)
})
const handleLocale: MouseEventHandler<HTMLAnchorElement> = (e) => {
e.preventDefault()
e.stopPropagation()
map.locate()
}
return (
<Control position='topleft'>
<div className='leaflet-bar'>
<a href='#' role='button' onClick={handleLocale}>
<img className={styles.localeIcon} src={locateIcon} alt='locate' />
</a>
</div>
</Control>
)
}
export default LocateButton

View File

@ -16,3 +16,4 @@ export { default as Poetry } from './Poetry'
export { default as SelectDisposalTrashbox } from './SelectDisposalTrashbox'
export { default as StarRating } from './StarRating'
export { default as CardLayout } from './CardLayout'
export { default as LocateButton } from './LocateButton'