Revize 7b864a5c
Přidáno uživatelem Václav Honzík před asi 2 roky(ů)
frontend/src/features/TrackingTool/MapPath.tsx | ||
---|---|---|
3 | 3 |
import { RootState } from "../redux/store" |
4 | 4 |
import { PathVariant, MapPoint } from "./buildPathVariants" |
5 | 5 |
import TextPath from "react-leaflet-textpath" |
6 |
import { setPrimaryIdx, updateMapMarkerPosition } from "./trackingToolSlice"
|
|
6 |
import { setPrimaryIdx, updateMapMarker } from "./trackingToolSlice" |
|
7 | 7 |
import MapMarker from "./MapMarker" |
8 | 8 |
import { LatLngTuple } from "leaflet" |
9 | 9 |
import { Popup } from "react-leaflet" |
... | ... | |
35 | 35 |
useEffect(() => { |
36 | 36 |
// Either set the path if it exists or set it to an empty array |
37 | 37 |
setPath(paths && paths.length > idx ? paths[idx] : []) |
38 |
}, [paths]) |
|
38 |
}, [idx, paths])
|
|
39 | 39 |
|
40 | 40 |
// Primary path index to set the correct color |
41 | 41 |
const primaryPathIdx = useSelector( |
... | ... | |
59 | 59 |
(item) => item.active |
60 | 60 |
) |
61 | 61 |
if (activeMapPoints.length < 2) { |
62 |
setEdges([]) |
|
62 | 63 |
return |
63 | 64 |
} |
64 | 65 |
|
... | ... | |
72 | 73 |
edges.push( |
73 | 74 |
<TextPath |
74 | 75 |
// Somehow this refuses to work so let it rerender everything ... |
75 |
// key={`${start.latitude},${start.longitude}-${end.latitude},${end.longitude}`} |
|
76 |
// key={`${start.id}-${end.id}`} |
|
76 |
key={`${start.id}-${end.id}:${start.latitude},${start.longitude}-${end.latitude},${end.longitude}`} |
|
77 | 77 |
positions={[ |
78 | 78 |
[start.latitude, start.longitude], |
79 | 79 |
[end.latitude, end.longitude], |
... | ... | |
105 | 105 |
setVertices( |
106 | 106 |
displayableMapPoints.map((item) => ( |
107 | 107 |
<MapMarker |
108 |
key={`${item.catalogItem.latitude}${item.catalogItem.latitude}`}
|
|
108 |
key={`${item.catalogItem.latitude}${item.catalogItem.longitude}`}
|
|
109 | 109 |
position={[ |
110 | 110 |
item.catalogItem.latitude as number, |
111 | 111 |
item.catalogItem.longitude as number, |
112 | 112 |
]} |
113 | 113 |
updatePositionCallbackFn={(position: LatLngTuple) => { |
114 |
// Update the position of the map point |
|
115 | 114 |
dispatch( |
116 |
updateMapMarkerPosition({
|
|
115 |
updateMapMarker({ |
|
117 | 116 |
idx, |
118 |
mapPointIdx: item.idx, |
|
119 |
position, |
|
117 |
item: new MapPoint(item.idx, item.active, { |
|
118 |
...item.catalogItem, |
|
119 |
latitude: position[0], |
|
120 |
longitude: position[1], |
|
121 |
}), |
|
120 | 122 |
}) |
121 | 123 |
) |
122 | 124 |
}} |
... | ... | |
138 | 140 |
<Checkbox |
139 | 141 |
checked={item.active} |
140 | 142 |
onChange={() => { |
141 |
item.active = !item.active |
|
142 |
setDisplayableMapPoints([ |
|
143 |
...displayableMapPoints, |
|
144 |
]) |
|
143 |
dispatch( |
|
144 |
updateMapMarker({ |
|
145 |
idx, |
|
146 |
item: new MapPoint( |
|
147 |
item.idx, |
|
148 |
!item.active, |
|
149 |
item.catalogItem |
|
150 |
), |
|
151 |
}) |
|
152 |
) |
|
145 | 153 |
}} |
146 | 154 |
/> |
147 | 155 |
} |
Také k dispozici: Unified diff
path dragging and adjustment seems functional