Revize 7652bb26
Přidáno uživatelem Fantič před více než 1 rok
src/components/plan/CastlePlanView.tsx | ||
---|---|---|
1 | 1 |
import { Box, HStack, Pressable, View, Text, Flex, IconButton } from 'native-base'; |
2 | 2 |
import React, { useEffect, useRef, useState } from 'react'; |
3 | 3 |
import { StyleSheet, Dimensions, TouchableOpacity, GestureResponderEvent } from 'react-native'; |
4 |
import { PanGestureHandler, PinchGestureHandler, State, TapGestureHandler } from 'react-native-gesture-handler'; |
|
4 |
import { PanGestureHandler, PinchGestureHandler, State, TapGestureHandler, TouchableWithoutFeedback } from 'react-native-gesture-handler'; |
|
5 |
|
|
6 |
import { findNodeHandle, UIManager } from 'react-native'; |
|
7 |
|
|
5 | 8 |
import Animated, { |
6 | 9 |
useAnimatedGestureHandler, |
7 | 10 |
useAnimatedStyle, |
8 | 11 |
useSharedValue, |
9 | 12 |
} from 'react-native-reanimated'; |
10 | 13 |
import { PlanImage, Room } from '../../types/plan'; |
11 |
import Svg, { Path, SvgXml, Text as SvgText } from 'react-native-svg'; |
|
14 |
import Svg, { Path, SvgXml, Text as SvgText, G, Circle } from 'react-native-svg';
|
|
12 | 15 |
|
13 | 16 |
// @ts-ignore |
14 | 17 |
import pointInSvgPolygon from "point-in-svg-polygon" |
... | ... | |
26 | 29 |
|
27 | 30 |
const { mapImage, roomList, selectedRoom, height, setSelectedRoom } = props; |
28 | 31 |
|
32 |
const [svgDimensions, setSvgDimensions] = useState({ width: 0, height: 0 }); |
|
33 |
|
|
29 | 34 |
const [fullScreenMode, setFullScreen] = useState(false); |
30 | 35 |
|
31 | 36 |
useEffect(() => { |
32 | 37 |
if (props.fullScreenMode) { |
33 | 38 |
setFullScreen(props.fullScreenMode) |
34 | 39 |
} |
35 |
}, [props.fullScreenMode])
|
|
40 |
}, [props.fullScreenMode]) |
|
36 | 41 |
|
37 | 42 |
|
38 | 43 |
const panRef = useRef<React.ReactElement>(); |
... | ... | |
122 | 127 |
|
123 | 128 |
const zoomToRoom = (room: Room) => { |
124 | 129 |
// Todo |
125 |
translateX.value = room.kx; |
|
126 |
translateY.value = room.ky; |
|
127 |
scale.value = DEFAULT_SCALE; |
|
130 |
|
|
131 |
console.log(room) |
|
132 |
|
|
133 |
scale.value = 3; |
|
134 |
|
|
135 |
translateX.value = room.number_x + 100 |
|
136 |
translateY.value = room.number_y + 100 |
|
137 |
|
|
128 | 138 |
} |
129 | 139 |
|
130 | 140 |
const handleFullScreenPressed = () => { |
131 | 141 |
console.log("neco") |
132 |
if (scale.value != DEFAULT_SCALE && translateX.value != 0 && translateY.value != 0) {
|
|
142 |
if (scale.value != DEFAULT_SCALE || translateX.value != 0 || translateY.value != 0) {
|
|
133 | 143 |
console.log("todo zoom out") |
134 | 144 |
zoomOut() |
135 | 145 |
} |
... | ... | |
141 | 151 |
|
142 | 152 |
const handleSvgPress = (event: GestureResponderEvent) => { |
143 | 153 |
|
144 |
// Get the raw event coordinates |
|
145 |
const rawLocationX = event.nativeEvent.locationX; |
|
146 |
const rawLocationY = event.nativeEvent.locationY; |
|
147 |
|
|
148 |
// Log raw coordinates |
|
149 |
console.log("Raw Location X: ", rawLocationX, "Raw Location Y: ", rawLocationY); |
|
154 |
// TODO ???????????? |
|
150 | 155 |
|
151 |
// If needed, you can get the SVG element's dimensions to normalize the coordinates |
|
152 |
const svgWidth = Dimensions.get('window').width |
|
153 |
const svgHeight = height ? height : (!fullScreenMode ? MAP_VIEW_SIZE.height : Dimensions.get('window').height - 62.5) |
|
156 |
// // Check if the touch event is within the bounds of a room |
|
157 |
// let clickedRoom: Room | undefined = undefined |
|
154 | 158 |
|
155 |
// Normalize the coordinates based on the SVG dimensions |
|
156 |
// @ts-ignore |
|
157 |
const locationX = (rawLocationX / svgWidth) * 100; |
|
158 |
const locationY = (rawLocationY / svgHeight) * 100; |
|
159 |
// // TODO set accordingaly |
|
160 |
// const maxNumberDistance = 100 |
|
159 | 161 |
|
162 |
// let minDistance = Number.MAX_VALUE |
|
160 | 163 |
|
161 |
// Check if the touch event is within the bounds of a room |
|
162 |
let clickedRoom: Room | undefined = undefined |
|
164 |
// for (let i = 0; i < roomList.length; i++) { |
|
165 |
// const room: Room = roomList[i] |
|
166 |
// if (room.in_plan) { |
|
163 | 167 |
|
164 |
// TODO set accordingaly |
|
165 |
const maxNumberDistance = 100 |
|
168 |
// // TODO |
|
169 |
// console.log() |
|
170 |
// console.log("Room + " + room.id + " x: " + room.number_x + " y: " + room.number_y) |
|
166 | 171 |
|
167 |
let minDistance = Number.MAX_VALUE
|
|
172 |
// const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, locationX, locationY, false)
|
|
168 | 173 |
|
169 |
for (let i = 0; i < roomList.length; i++) { |
|
170 |
const room: Room = roomList[i] |
|
171 |
if (room.in_plan) { |
|
174 |
// if (currentDistance < minDistance) { |
|
175 |
// minDistance = currentDistance |
|
176 |
// clickedRoom = room |
|
177 |
// } |
|
178 |
// } |
|
179 |
// }; |
|
172 | 180 |
|
173 |
// TODO |
|
174 |
console.log() |
|
175 |
console.log("Room + " + room.id) |
|
181 |
// console.log() |
|
182 |
// console.log('Room clicked with id:', clickedRoom?.id); |
|
183 |
// console.log(minDistance) |
|
184 |
// if (clickedRoom && minDistance < maxNumberDistance) { |
|
185 |
// // TODO |
|
176 | 186 |
|
177 |
const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, locationX, locationY, true)
|
|
187 |
// // Perform any actions you need with the clicked room
|
|
178 | 188 |
|
179 |
if (currentDistance < minDistance) { |
|
180 |
minDistance = currentDistance |
|
181 |
clickedRoom = room |
|
182 |
} |
|
183 |
} |
|
184 |
}; |
|
185 |
|
|
186 |
console.log('Room clicked with id:', clickedRoom?.id); |
|
187 |
console.log(minDistance) |
|
188 |
if (clickedRoom && minDistance < maxNumberDistance) { |
|
189 |
// TODO |
|
190 |
|
|
191 |
// Perform any actions you need with the clicked room |
|
189 |
// // TODO fix -> point recognition |
|
190 |
// setSelectedRoom && setSelectedRoom(clickedRoom) |
|
191 |
// } else { |
|
192 |
// console.log("no room found") |
|
193 |
// } |
|
192 | 194 |
|
193 |
// TODO fix -> point recognition |
|
194 |
setSelectedRoom && setSelectedRoom(clickedRoom) |
|
195 |
} else { |
|
196 |
console.log("no room found") |
|
197 |
} |
|
198 | 195 |
}; |
199 | 196 |
|
200 | 197 |
console.log(Dimensions.get('window').height) |
... | ... | |
213 | 210 |
top: -230, |
214 | 211 |
left: 0, |
215 | 212 |
zIndex: 1000, |
216 |
backgroundColor:"white", |
|
213 |
backgroundColor: "white",
|
|
217 | 214 |
|
218 | 215 |
height: Dimensions.get('window').height - 120, |
219 | 216 |
width: Dimensions.get('window').width - 20, |
... | ... | |
236 | 233 |
</Pressable> |
237 | 234 |
{ |
238 | 235 |
selectedRoom && |
239 |
<Pressable padding={1.5} backgroundColor={"#654B07"} borderRadius={5} marginRight={-2} onPress={() => { zoomToRoom(selectedRoom) }}>
|
|
236 |
<Pressable padding={1.5} backgroundColor={"#654B07"} borderRadius={5} marginRight={-2} onPress={() => { zoomToRoom(selectedRoom) }}> |
|
240 | 237 |
<ExitfullscreenIcon color="white" /> |
241 | 238 |
</Pressable> |
242 | 239 |
} |
... | ... | |
265 | 262 |
<Svg |
266 | 263 |
id="svgMap" |
267 | 264 |
ref={(ref: any) => (svgRef.current = ref)} |
268 |
onPress={handleSvgPress} |
|
269 | 265 |
> |
270 | 266 |
{mapImage && mapImage.viewBox && |
271 | 267 |
// background image |
... | ... | |
273 | 269 |
xml={mapImage.svg} |
274 | 270 |
width={"100%"} |
275 | 271 |
height={"100%"} |
276 |
/> |
|
272 |
onLayout={(event) => { |
|
273 |
setSvgDimensions({ |
|
274 |
width: event.nativeEvent.layout.width, |
|
275 |
height: event.nativeEvent.layout.height, |
|
276 |
}); |
|
277 |
}} |
|
278 |
> |
|
279 |
</SvgXml> |
|
277 | 280 |
} |
278 | 281 |
|
279 | 282 |
{mapImage && roomList && roomList.length > 0 && |
... | ... | |
295 | 298 |
) |
296 | 299 |
})} |
297 | 300 |
|
301 |
|
|
302 |
|
|
298 | 303 |
{mapImage && roomList && roomList.length > 0 && |
299 | 304 |
|
300 | 305 |
roomList.map((room) => { |
... | ... | |
315 | 320 |
</SvgText> |
316 | 321 |
) |
317 | 322 |
})} |
323 |
|
|
318 | 324 |
</Svg> |
319 | 325 |
</Animated.View> |
320 | 326 |
</PanGestureHandler> |
Také k dispozici: Unified diff
Update CastlePlanView.tsx