Skip to content

Commit 01c8d6a

Browse files
committed
optimize
1 parent f06e798 commit 01c8d6a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/components/Projekte/Karte/ClickListener.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useSetAtom, useAtomValue } from 'jotai'
22
import * as ReactDOMServer from 'react-dom/server'
3-
import { useMapEvent } from 'react-leaflet/hooks'
3+
import { useMapEvent, useMap } from 'react-leaflet/hooks'
44
import { gql } from '@apollo/client'
55
import { useApolloClient } from '@apollo/client/react'
66
import L from 'leaflet'
@@ -24,9 +24,12 @@ export const ClickListener = () => {
2424

2525
const apolloClient = useApolloClient()
2626

27-
const map = useMapEvent('click', async (event) => {
27+
const map = useMap()
28+
29+
const onClick = async (event) => {
2830
const { lat, lng } = event.latlng
2931
const zoom = map.getZoom()
32+
console.log('map clicked', { lat, lng, zoom })
3033
// idea 1:
3134
// get all layers
3235
// run onEachFeature on all layers
@@ -478,7 +481,9 @@ export const ClickListener = () => {
478481
/>,
479482
)
480483
L.popup().setLatLng(event.latlng).setContent(popupContent).openOn(map)
481-
})
484+
}
485+
486+
useMapEvent('click', onClick)
482487

483488
return null
484489
}

0 commit comments

Comments
 (0)