commit 7652bb267999b3e33dfc6f30c6bd2a56e15e5d29
Author: Fantič <58391275+FantaFantic@users.noreply.github.com>
Date:   Mon Nov 13 21:02:17 2023 +0100

    Update CastlePlanView.tsx

diff --git a/src/components/plan/CastlePlanView.tsx b/src/components/plan/CastlePlanView.tsx
index 201782b..80a6463 100644
--- a/src/components/plan/CastlePlanView.tsx
+++ b/src/components/plan/CastlePlanView.tsx
@@ -1,14 +1,17 @@
 import { Box, HStack, Pressable, View, Text, Flex, IconButton } from 'native-base';
 import React, { useEffect, useRef, useState } from 'react';
 import { StyleSheet, Dimensions, TouchableOpacity, GestureResponderEvent } from 'react-native';
-import { PanGestureHandler, PinchGestureHandler, State, TapGestureHandler } from 'react-native-gesture-handler';
+import { PanGestureHandler, PinchGestureHandler, State, TapGestureHandler, TouchableWithoutFeedback } from 'react-native-gesture-handler';
+
+import { findNodeHandle, UIManager } from 'react-native';
+
 import Animated, {
     useAnimatedGestureHandler,
     useAnimatedStyle,
     useSharedValue,
 } from 'react-native-reanimated';
 import { PlanImage, Room } from '../../types/plan';
-import Svg, { Path, SvgXml, Text as SvgText } from 'react-native-svg';
+import Svg, { Path, SvgXml, Text as SvgText, G, Circle } from 'react-native-svg';
 
 // @ts-ignore
 import pointInSvgPolygon from "point-in-svg-polygon"
@@ -26,13 +29,15 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
 
     const { mapImage, roomList, selectedRoom, height, setSelectedRoom } = props;
 
+    const [svgDimensions, setSvgDimensions] = useState({ width: 0, height: 0 });
+
     const [fullScreenMode, setFullScreen] = useState(false);
 
     useEffect(() => {
         if (props.fullScreenMode) {
             setFullScreen(props.fullScreenMode)
         }
-      }, [props.fullScreenMode])
+    }, [props.fullScreenMode])
 
 
     const panRef = useRef<React.ReactElement>();
@@ -122,14 +127,19 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
 
     const zoomToRoom = (room: Room) => {
         // Todo
-        translateX.value = room.kx;
-        translateY.value = room.ky;
-        scale.value = DEFAULT_SCALE;
+
+        console.log(room)
+
+        scale.value = 3;
+
+        translateX.value = room.number_x + 100
+        translateY.value = room.number_y + 100
+
     }
 
     const handleFullScreenPressed = () => {
         console.log("neco")
-        if (scale.value != DEFAULT_SCALE && translateX.value != 0 && translateY.value != 0) {
+        if (scale.value != DEFAULT_SCALE || translateX.value != 0 || translateY.value != 0) {
             console.log("todo zoom out")
             zoomOut()
         }
@@ -141,60 +151,47 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
 
     const handleSvgPress = (event: GestureResponderEvent) => {
 
-        // Get the raw event coordinates
-        const rawLocationX = event.nativeEvent.locationX;
-        const rawLocationY = event.nativeEvent.locationY;
-
-        // Log raw coordinates
-        console.log("Raw Location X: ", rawLocationX, "Raw Location Y: ", rawLocationY);
+        // TODO ????????????
 
-        // If needed, you can get the SVG element's dimensions to normalize the coordinates
-        const svgWidth = Dimensions.get('window').width
-        const svgHeight = height ? height : (!fullScreenMode ? MAP_VIEW_SIZE.height : Dimensions.get('window').height - 62.5)
+        // // Check if the touch event is within the bounds of a room
+        // let clickedRoom: Room | undefined = undefined
 
-        // Normalize the coordinates based on the SVG dimensions
-        // @ts-ignore
-        const locationX = (rawLocationX / svgWidth) * 100;
-        const locationY = (rawLocationY / svgHeight) * 100;
+        // // TODO set accordingaly
+        // const maxNumberDistance = 100
 
+        // let minDistance = Number.MAX_VALUE
 
-        // Check if the touch event is within the bounds of a room
-        let clickedRoom: Room | undefined = undefined
+        // for (let i = 0; i < roomList.length; i++) {
+        //     const room: Room = roomList[i]
+        //     if (room.in_plan) {
 
-        // TODO set accordingaly
-        const maxNumberDistance = 100
+        //         // TODO
+        //         console.log()
+        //         console.log("Room + " + room.id + " x: " + room.number_x + " y: " + room.number_y)
 
-        let minDistance = Number.MAX_VALUE
+        //         const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, locationX, locationY, false)
 
-        for (let i = 0; i < roomList.length; i++) {
-            const room: Room = roomList[i]
-            if (room.in_plan) {
+        //         if (currentDistance < minDistance) {
+        //             minDistance = currentDistance
+        //             clickedRoom = room
+        //         }
+        //     }
+        // };
 
-                // TODO
-                console.log()
-                console.log("Room + " + room.id)
+        // console.log()
+        // console.log('Room clicked with id:', clickedRoom?.id);
+        // console.log(minDistance)
+        // if (clickedRoom && minDistance < maxNumberDistance) {
+        //     // TODO        
 
-                const currentDistance = calculateStraightLineDistance(room.number_x, room.number_y, locationX, locationY, true)
+        //     // Perform any actions you need with the clicked room
 
-                if (currentDistance < minDistance) {
-                    minDistance = currentDistance
-                    clickedRoom = room
-                }
-            }
-        };
-
-        console.log('Room clicked with id:', clickedRoom?.id);
-        console.log(minDistance)
-        if (clickedRoom && minDistance < maxNumberDistance) {
-            // TODO        
-
-            // Perform any actions you need with the clicked room
+        //     // TODO fix -> point recognition
+        //     setSelectedRoom && setSelectedRoom(clickedRoom)
+        // } else {
+        //     console.log("no room found")
+        // }
 
-            // TODO fix -> point recognition
-            setSelectedRoom && setSelectedRoom(clickedRoom)
-        } else {
-            console.log("no room found")
-        }
     };
 
     console.log(Dimensions.get('window').height)
@@ -213,7 +210,7 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                     top: -230,
                     left: 0,
                     zIndex: 1000,
-                    backgroundColor:"white",
+                    backgroundColor: "white",
 
                     height: Dimensions.get('window').height - 120,
                     width: Dimensions.get('window').width - 20,
@@ -236,7 +233,7 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                 </Pressable>
                 {
                     selectedRoom &&
-                    <Pressable padding={1.5} backgroundColor={"#654B07"} borderRadius={5} marginRight={-2}  onPress={() => { zoomToRoom(selectedRoom) }}>
+                    <Pressable padding={1.5} backgroundColor={"#654B07"} borderRadius={5} marginRight={-2} onPress={() => { zoomToRoom(selectedRoom) }}>
                         <ExitfullscreenIcon color="white" />
                     </Pressable>
                 }
@@ -265,7 +262,6 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                             <Svg
                                 id="svgMap"
                                 ref={(ref: any) => (svgRef.current = ref)}
-                                onPress={handleSvgPress}
                             >
                                 {mapImage && mapImage.viewBox &&
                                     // background image                    
@@ -273,7 +269,14 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                                         xml={mapImage.svg}
                                         width={"100%"}
                                         height={"100%"}
-                                    />
+                                        onLayout={(event) => {
+                                            setSvgDimensions({
+                                                width: event.nativeEvent.layout.width,
+                                                height: event.nativeEvent.layout.height,
+                                            });
+                                        }}
+                                    >
+                                    </SvgXml>
                                 }
 
                                 {mapImage && roomList && roomList.length > 0 &&
@@ -295,6 +298,8 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                                         )
                                     })}
 
+
+
                                 {mapImage && roomList && roomList.length > 0 &&
 
                                     roomList.map((room) => {
@@ -315,6 +320,7 @@ const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selected
                                             </SvgText>
                                         )
                                     })}
+
                             </Svg>
                         </Animated.View>
                     </PanGestureHandler>
