Revize de12c6be
Přidáno uživatelem Václav Honzík před asi 2 roky(ů)
frontend/src/features/TrackingTool/MapMarker.tsx | ||
---|---|---|
1 |
import { LatLngTuple, Marker as MarkerPOJO } from 'leaflet'
|
|
2 |
import { FunctionComponent, ReactNode, useMemo, useRef, useState } from 'react'
|
|
3 |
import { Marker } from 'react-leaflet'
|
|
1 |
import { LatLngTuple, Marker as MarkerPOJO } from "leaflet"
|
|
2 |
import { FunctionComponent, ReactNode, useMemo, useRef, useState } from "react"
|
|
3 |
import { Marker } from "react-leaflet"
|
|
4 | 4 |
|
5 | 5 |
export interface MapMarkerProps { |
6 | 6 |
position: LatLngTuple |
7 | 7 |
children?: ReactNode |
8 |
color?: "external" | "disabled" | "localCatalog" |
|
9 |
updatePositionCallbackFn: (position: LatLngTuple) => void // Callback function to notify MapPath to rerender the path |
|
8 | 10 |
} |
9 | 11 |
|
10 | 12 |
// Custom Map Marker component |
11 |
const MapMarker: FunctionComponent<MapMarkerProps> = ({ position, children }) => { |
|
13 |
const MapMarker: FunctionComponent<MapMarkerProps> = ({ |
|
14 |
position, |
|
15 |
children, |
|
16 |
updatePositionCallbackFn, |
|
17 |
}) => { |
|
12 | 18 |
const [currentPosition, setCurrentPosition] = useState(position) |
13 | 19 |
const markerRef = useRef<MarkerPOJO | null>(null) |
14 | 20 |
const eventHandlers = useMemo( |
... | ... | |
21 | 27 |
} |
22 | 28 |
const latlng = marker.getLatLng() |
23 | 29 |
setCurrentPosition([latlng.lat, latlng.lng]) |
30 |
updatePositionCallbackFn([latlng.lat, latlng.lng]) |
|
24 | 31 |
}, |
25 | 32 |
}), |
26 |
[] |
|
33 |
[updatePositionCallbackFn]
|
|
27 | 34 |
) |
28 | 35 |
|
29 | 36 |
return ( |
Také k dispozici: Unified diff
draggable
re #9741