Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 08be9ecd

Přidáno uživatelem Fantič před více než 1 rok

re #10871: PlanViewPage: Populate rooms and labels, highlight selected room

Zobrazit rozdíly:

src/components/plan/CastlePlanView.tsx
8 8
    useSharedValue,
9 9
} from 'react-native-reanimated';
10 10
import { PlanImage, Room } from '../../types/plan';
11
import Svg, { SvgXml } from 'react-native-svg';
11
import Svg, { Path, SvgXml, Text } from 'react-native-svg';
12 12

  
13 13
const CastlePlanView = (props: { mapImage: PlanImage, roomList: Room[], selectedRoom?: Room, fullScreenMode?: boolean, height?: number }) => {
14 14

  
......
45 45
    });
46 46

  
47 47
    const onGestureEvent = useAnimatedGestureHandler({
48
        onActive: (event: any) => {
49
            // handle two fingers -> zoom  + - 
48
        onStart: (_, ctx: any) => {
49
            ctx.startScale = scale.value;
50
        },
51
        onActive: (event: any, ctx: any) => {
52
            // handle two fingers -> zoom + -
50 53
            if (event.numberOfPointers === 2) {
51
                if (event.scale < MIN_SCALE) {
52
                    scale.value = MIN_SCALE
53
                }
54
                else {
55
                    scale.value = event.scale;
54
                scale.value = ctx.startScale * event.scale;
55
            }
56
        },
57
        onEnd: (event) => {
58
            // handle two fingers -> zoom + -
59
            if (event.numberOfPointers === 2) {
60
                if (scale.value < MIN_SCALE) {
61
                    scale.value = MIN_SCALE;
56 62
                }
63
                // You may add additional logic for maximum scale if needed
57 64
            }
58 65
        },
59 66
    });
......
76 83
    return (
77 84
        // container
78 85
        <Box
79
            width={!fullScreenMode ? MAP_VIEW_SIZE.width : Dimensions.get('window').width - 5}
86
            width={!fullScreenMode ? MAP_VIEW_SIZE.width : Dimensions.get('window').width - 5
87
            }
80 88
            height={height ? height : (!fullScreenMode ? MAP_VIEW_SIZE.height : Dimensions.get('window').height - 62.5)}
81 89
            // @ts-ignore
82 90
            style={
......
90 98
            }
91 99
            borderColor={"light.300"}
92 100
            borderRadius={10}
93
            borderWidth={1}>
101
            borderWidth={1}
102
        >
103

  
94 104
            <PinchGestureHandler
95 105
                ref={pinchRef}
96 106
                // @ts-ignore
......
115 125
                                        width={"100%"}
116 126
                                        height={"100%"}
117 127

  
118
                                    />}
128
                                    />
129
                                }
130

  
119 131
                                {mapImage && roomList && roomList.length > 0 &&
120
                                    <></>}
132
                                    roomList.map((room) => {
133
                                        if (!room.in_plan) {
134
                                            return
135
                                        }
136
                                        return (
137
                                            <React.Fragment key={room.id}>
138
                                                <Path
139

  
140
                                                    d={room.svg_path}  // The path data defining the shape of the room
141
                                                    fill={selectedRoom && room.id == selectedRoom.id ? "#E6F7FF" : "none"}        // Fill the room shape with no color
142
                                                    stroke="#66B2FF"       // Outline color
143
                                                    strokeWidth={0.3}     // Outline width
144
                                                />
145
                                                {/* Text label in the middle of the room */}
146
                                                <Text
147
                                                    x={room.number_x}     // Adjust the x-coordinate based on your room data
148
                                                    y={room.number_y}     // Adjust the y-coordinate based on your room data
149
                                                    fill="red"      // Text color
150
                                                    fontSize={8}       // Font size
151
                                                    textAnchor="middle"  // Center the text horizontally
152
                                                    fontStyle='italic'
153
                                                    vectorEffect='non-scaling-stroke' // Helps prevent stroke from scaling
154
                                                >
155
                                                    {room.id}
156
                                                </Text>
157
                                            </React.Fragment>
158

  
159
                                        )
160
                                    })
161
                                }
121 162

  
122 163
                            </Svg>
123 164
                        </Animated.View>
124 165
                    </PanGestureHandler>
125 166
                </Animated.View>
126 167
            </PinchGestureHandler>
127
        </Box>
168
        </Box >
128 169
    );
129 170
};
130 171

  
src/pages/PlanViewPage.tsx
323 323
                  inventoriesLoading ?
324 324
                    <LoadingBox text="Loading available inventories..." />
325 325
                    :
326
                    <Box mt={2.5} ml={2.5} mr={2.5}>
326
                    <Box mt={5} ml={2.5} mr={2.5}>
327 327
                      <ListView
328 328

  
329 329
                        navigation={navigation}
src/stores/actions/planThunks.ts
28 28

  
29 29
                    unstructeredRoomList.map((room) => {
30 30
                        if (room.floor in floorsDict) {
31

  
32
                            // TODO handle on backend transformations :-)
33
                            if (room.floor == "first_floor") {
34
                                room.number_x = room.number_x - 1044.46
35
                                room.number_y = room.number_y - 1088.65
36
                            }
37
                            else if (room.floor == "second_floor") {
38
                                room.number_x = room.number_x - 2088.7
39
                                room.number_y = room.number_y - 1088.58
40
                            }
41

  
31 42
                            floorsDict[room.floor].roomList.push(room)
32 43
                        }
33 44
                        else {
......
128 139
                const response = await getPlanFloorImageRequest(floorId)
129 140

  
130 141
                if (response.status === 200) {
131
                    
132
                    const svg : string = response.data 
133 142

  
134
                    const output : PlanImage = {
143
                    const svg: string = response.data
144

  
145
                    const output: PlanImage = {
135 146
                        svg: svg,
136
                        viewBox :{ x:0, y:0, width:0, height:0 }
147
                        viewBox: { x: 0, y: 0, width: 0, height: 0 }
137 148
                    }
138 149

  
139
                    parseString(svg, (err : any, result: any) => {
150
                    parseString(svg, (err: any, result: any) => {
140 151
                        if (!err && result && result.svg && result.svg.$.viewBox) {
141
                          const [x, y, width, height] = result.svg.$.viewBox.split(' ').map(Number);
142
                    
143
                          // Set the SVG information in your component's state or use it as needed
144
                          output.viewBox =  { x, y, width, height };
152
                            const [x, y, width, height] = result.svg.$.viewBox.split(' ').map(Number);
153

  
154
                            // Set the SVG information in your component's state or use it as needed
155
                            output.viewBox = { x, y, width, height };
145 156
                        }
146
                      });
157
                    });
147 158

  
148 159
                    return output
149 160
                } else {

Také k dispozici: Unified diff