Revize d4c93958
Přidáno uživatelem Fantič před více než 1 rok
src/components/plan/CastlePlanView.tsx | ||
---|---|---|
22 | 22 |
const DEFAULT_SCALE = 1 |
23 | 23 |
const MIN_SCALE = 0.95 |
24 | 24 |
|
25 |
const MAP_VIEW_SIZE = { |
|
26 |
height: 500, |
|
27 |
width: "100%" |
|
28 |
} |
|
29 |
|
|
30 | 25 |
const { mapImage, roomList, selectedRoom, height, setSelectedRoom } = props; |
31 | 26 |
|
32 |
const [svgDimensions, setSvgDimensions] = useState({ width: 0, height: 0 }); |
|
33 | 27 |
|
34 | 28 |
const [fullScreenMode, setFullScreen] = useState(false); |
35 | 29 |
|
... | ... | |
84 | 78 |
scale.value = MIN_SCALE; |
85 | 79 |
} |
86 | 80 |
// You may add additional logic for maximum scale if needed |
81 |
|
|
82 |
console.log("scale") |
|
83 |
console.log(scale.value) |
|
87 | 84 |
} |
88 | 85 |
}, |
89 | 86 |
}); |
... | ... | |
99 | 96 |
}); |
100 | 97 |
|
101 | 98 |
|
102 |
function calculateStraightLineDistance(x1: number, y1: number, planX: number, planY: number, log?: boolean) {
|
|
99 |
function calculateStraightLineDistance(x1: number, y1: number, planX: number, planY: number) { |
|
103 | 100 |
// Apply scale and translations to both points |
104 | 101 |
|
105 | 102 |
const x2 = planX |
106 | 103 |
const y2 = planY |
107 | 104 |
|
108 |
|
|
109 | 105 |
const x_distance = Math.abs(x1 - x2); |
110 | 106 |
const y_distance = Math.abs(y1 - y2); |
111 | 107 |
|
112 |
if (log) { |
|
113 |
console.log("Original X: ", x1, "Original Y: ", y1); |
|
114 |
console.log("Clicked X: ", planX, "Clicked Y: ", planY); |
|
115 |
console.log("Transformed X: ", x2, "Transformed Y: ", y2); |
|
116 |
console.log("Scale: ", scale.value, "TranslateX: ", translateX.value, "TranslateY: ", translateY.value); |
|
117 |
console.log("X Distance: ", x_distance, "Y Distance: ", y_distance); |
|
118 |
} |
|
119 | 108 |
return x_distance + y_distance; |
120 | 109 |
} |
121 | 110 |
|
... | ... | |
138 | 127 |
} |
139 | 128 |
|
140 | 129 |
const handleFullScreenPressed = () => { |
141 |
console.log("neco") |
|
142 | 130 |
if (scale.value != DEFAULT_SCALE || translateX.value != 0 || translateY.value != 0) { |
143 | 131 |
console.log("todo zoom out") |
144 | 132 |
zoomOut() |
... | ... | |
153 | 141 |
|
154 | 142 |
// TODO ???????????? |
155 | 143 |
|
156 |
// // Check if the touch event is within the bounds of a room |
|
157 |
// let clickedRoom: Room | undefined = undefined |
|
144 |
const locationX = event.nativeEvent.locationX |
|
145 |
const locationY = event.nativeEvent.locationY |
|
146 |
|
|
147 |
// console.log("x " + event.nativeEvent.locationX + " y " + event.nativeEvent.locationY) |
|
148 |
console.log("view size:") |
|
149 |
console.log("x " + viewSize.width + " y " + viewSize.height) |
|
150 |
console.log("svg size:") |
|
151 |
console.log("x " + mapImage.viewBox.width + " y " + mapImage.viewBox.height) |
|
152 |
|
|
153 |
let mapX = (locationX / viewSize.width) * mapImage.viewBox.width |
|
154 |
let mapY = (locationY / viewSize.height) * mapImage.viewBox.height |
|
155 |
|
|
156 |
|
|
157 |
// if() |
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
// console.log("x " + mapX + " y " + mapY) |
|
163 |
// console.log("") |
|
158 | 164 |
|
159 |
// // TODO set accordingaly
|
|
160 |
// const maxNumberDistance = 100
|
|
165 |
// Check if the touch event is within the bounds of a room
|
|
166 |
let clickedRoom: Room | undefined = undefined
|
|
161 | 167 |
|
162 |
// let minDistance = Number.MAX_VALUE |
|
168 |
// TODO set accordingaly |
|
169 |
const maxNumberDistance = 100 |
|
163 | 170 |
|
164 |
// for (let i = 0; i < roomList.length; i++) { |
|
165 |
// const room: Room = roomList[i] |
|
166 |
// if (room.in_plan) { |
|
171 |
let minDistance = Number.MAX_VALUE |
|
167 | 172 |
|
168 |
// // TODO |
|
169 |
// console.log() |
|
170 |
// console.log("Room + " + room.id + " x: " + room.number_x + " y: " + room.number_y) |
|
173 |
for (let i = 0; i < roomList.length; i++) { |
|
174 |
const room: Room = roomList[i] |
|
175 |
if (room.in_plan) { |
|
176 |
// TODO |
|
177 |
// console.log() |
|
178 |
console.log("Room + " + room.id + " x: " + room.number_x + " y: " + room.number_y) |
|
171 | 179 |
|
172 |
// const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, locationX, locationY, false)
|
|
180 |
const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, mapX, mapY)
|
|
173 | 181 |
|
174 |
// if (currentDistance < minDistance) {
|
|
175 |
// minDistance = currentDistance
|
|
176 |
// clickedRoom = room
|
|
177 |
// }
|
|
178 |
// }
|
|
179 |
// };
|
|
182 |
if (currentDistance < minDistance) { |
|
183 |
minDistance = currentDistance |
|
184 |
clickedRoom = room |
|
185 |
} |
|
186 |
} |
|
187 |
}; |
|
180 | 188 |
|
181 |
// console.log() |
|
182 |
// console.log('Room clicked with id:', clickedRoom?.id); |
|
183 |
// console.log(minDistance) |
|
184 |
// if (clickedRoom && minDistance < maxNumberDistance) { |
|
185 |
// // TODO |
|
189 |
console.log() |
|
190 |
console.log('Room clicked with id:', clickedRoom?.id); |
|
191 |
console.log("x " + clickedRoom?.number_x + " y " + clickedRoom?.number_y) |
|
192 |
console.log(minDistance) |
|
193 |
console.log("clicked: x " + locationX + " y " + locationY) |
|
194 |
console.log("translated clicked: x " + mapX + " y " + mapY) |
|
186 | 195 |
|
187 |
// // Perform any actions you need with the clicked room |
|
196 |
if (clickedRoom && minDistance < maxNumberDistance) { |
|
197 |
// TODO |
|
188 | 198 |
|
189 |
// // TODO fix -> point recognition |
|
190 |
// setSelectedRoom && setSelectedRoom(clickedRoom) |
|
191 |
// } else { |
|
192 |
// console.log("no room found") |
|
193 |
// } |
|
199 |
// Perform any actions you need with the clicked room |
|
194 | 200 |
|
201 |
// TODO fix -> point recognition |
|
202 |
setSelectedRoom && setSelectedRoom(clickedRoom) |
|
203 |
} else { |
|
204 |
console.log("no room found") |
|
205 |
} |
|
206 |
console.log("") |
|
195 | 207 |
}; |
196 | 208 |
|
197 |
console.log(Dimensions.get('window').height) |
|
209 |
const [viewSize, setViewSize] = useState({ height: 0, width: 0 }); |
|
210 |
|
|
211 |
useEffect(() => { |
|
212 |
setViewSize({ |
|
213 |
width: fullScreenMode ? |
|
214 |
Dimensions.get('window').width - 20 : // full screen |
|
215 |
Dimensions.get('window').width - 20, // not full screen |
|
216 |
height: fullScreenMode ? |
|
217 |
Dimensions.get('window').height - 122.5 : // full scren |
|
218 |
Dimensions.get('window').height -350, // not full screen |
|
219 |
}) |
|
220 |
}, [fullScreenMode]) |
|
221 |
|
|
198 | 222 |
|
199 | 223 |
return ( |
200 | 224 |
// container |
201 | 225 |
<View |
202 |
width={!fullScreenMode ? MAP_VIEW_SIZE.width : Dimensions.get('window').width - 5 |
|
203 |
} |
|
204 |
height={height ? height : (!fullScreenMode ? MAP_VIEW_SIZE.height : Dimensions.get('window').height - 62.5)} |
|
226 |
height={viewSize.height} |
|
227 |
width={viewSize.width} |
|
205 | 228 |
// @ts-ignore |
206 | 229 |
style={ |
207 | 230 |
fullScreenMode ? { |
208 |
|
|
209 | 231 |
position: "absolute", |
210 | 232 |
top: -230, |
211 | 233 |
left: 0, |
212 | 234 |
zIndex: 1000, |
213 | 235 |
backgroundColor: "white", |
214 |
|
|
215 |
height: Dimensions.get('window').height - 120, |
|
216 |
width: Dimensions.get('window').width - 20, |
|
217 |
|
|
218 |
|
|
219 | 236 |
} |
220 | 237 |
: |
221 | 238 |
{ |
... | ... | |
227 | 244 |
borderWidth={fullScreenMode ? 0 : 1} |
228 | 245 |
> |
229 | 246 |
{/* control panel */} |
230 |
<Flex direction="row" alignItems="center" justify="flex-end" style={{ height: 50, width: 100, top: 5, right: 10, position: "absolute", zIndex: 5 }}>
|
|
247 |
<Flex direction="row" alignItems="center" justify="flex-end" style={{ height: 50, width: 100, top: fullScreenMode? 10 : 0, right: fullScreenMode ? 20 : 15, position: "absolute", zIndex: 5 }}>
|
|
231 | 248 |
<Pressable padding={1.5} backgroundColor={"#654B07"} borderRadius={5} marginRight={selectedRoom ? 1 : -2} onPress={handleFullScreenPressed}> |
232 | 249 |
<FullscreenIcon color="white" /> |
233 | 250 |
</Pressable> |
... | ... | |
245 | 262 |
// @ts-ignore |
246 | 263 |
onGestureEvent={onGestureEvent} |
247 | 264 |
simultaneousHandlers={[svgRef, panRef]}> |
248 |
<Animated.View style={{ flex: 1 }}>
|
|
265 |
<Animated.View style={[{ flex: 1 }, animatedStyle]}>
|
|
249 | 266 |
<PanGestureHandler |
250 | 267 |
ref={panRef} |
251 | 268 |
simultaneousHandlers={[svgRef, pinchRef]} |
... | ... | |
258 | 275 |
> |
259 | 276 |
<Animated.View style={[{ |
260 | 277 |
flex: 1, |
261 |
}, animatedStyle]}>
|
|
278 |
}]}> |
|
262 | 279 |
<Svg |
263 | 280 |
id="svgMap" |
264 |
ref={(ref: any) => (svgRef.current = ref)}
|
|
281 |
onPress={handleSvgPress}
|
|
265 | 282 |
> |
266 | 283 |
{mapImage && mapImage.viewBox && |
267 | 284 |
// background image |
... | ... | |
269 | 286 |
xml={mapImage.svg} |
270 | 287 |
width={"100%"} |
271 | 288 |
height={"100%"} |
272 |
onLayout={(event) => { |
|
273 |
setSvgDimensions({ |
|
274 |
width: event.nativeEvent.layout.width, |
|
275 |
height: event.nativeEvent.layout.height, |
|
276 |
}); |
|
277 |
}} |
|
289 |
viewBox={`${0} ${0} ${mapImage.viewBox.width} ${mapImage.viewBox.height}`} |
|
290 |
// onLayout={(event) => { |
|
291 |
// setSvgDimensions({ |
|
292 |
// width: event.nativeEvent.layout.width, |
|
293 |
// height: event.nativeEvent.layout.height, |
|
294 |
// }); |
|
295 |
// }} |
|
278 | 296 |
> |
279 | 297 |
</SvgXml> |
280 | 298 |
} |
... | ... | |
288 | 306 |
return ( |
289 | 307 |
<Path |
290 | 308 |
id={"roomList_" + index.toString()} |
291 |
key={'room_' + room.id} |
|
292 | 309 |
d={room.svg_path} // The path data defining the shape of the room |
293 | 310 |
fill={selectedRoom && room.id == selectedRoom.id ? "#E6F7FF" : "white"} // Fill the room shape with no color |
294 | 311 |
stroke="#66B2FF" // Outline color |
Také k dispozici: Unified diff
re #10882: PlanViewPage: refactor calculation of tap map coordinates