Revize 08be9ecd
Přidáno uživatelem Fantič před více než 1 rok
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 |
|
Také k dispozici: Unified diff
re #10871: PlanViewPage: Populate rooms and labels, highlight selected room