Revize f220395e
Přidáno uživatelem Fantič před více než 1 rok
package.json | ||
---|---|---|
34 | 34 |
"react-native-svg": "13.9.0", |
35 | 35 |
"react-native-tab-view": "^3.5.2", |
36 | 36 |
"react-native-vector-icons": "^9.2.0", |
37 |
"react-native-xml2js": "^1.0.3", |
|
37 | 38 |
"react-redux": "^8.0.5", |
38 | 39 |
"redux": "^4.2.1", |
39 | 40 |
"redux-persist-transform-encrypt": "^5.0.0", |
src/components/plan/CastlePlanView.tsx | ||
---|---|---|
1 | 1 |
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea, useToast } from "native-base"; |
2 | 2 |
import { Note } from "../../types/note"; |
3 | 3 |
import React, { useCallback, useState } from "react"; |
4 |
import { Floor, Room } from "../../types/plan"; |
|
4 |
import { Floor, PlanImage, Room } from "../../types/plan";
|
|
5 | 5 |
|
6 | 6 |
import MapView, { Marker } from 'react-native-maps'; |
7 | 7 |
import Svg, { Image, SvgXml } from 'react-native-svg'; |
8 | 8 |
import SvgImage from "react-native-svg/lib/typescript/elements/Image"; |
9 | 9 |
|
10 |
const CastlePlanView = (props: { mapImage : string, selectedRoom?: Room }) => {
|
|
10 |
const CastlePlanView = (props: { mapImage: PlanImage, selectedRoom?: Room }) => {
|
|
11 | 11 |
|
12 | 12 |
const { mapImage, selectedRoom } = props |
13 | 13 |
|
14 |
console.log(mapImage.substring(0,500)) |
|
14 |
console.log(mapImage.svg.substring(0, 500)) |
|
15 |
|
|
16 |
console.log(selectedRoom?.kx, selectedRoom?.ky, selectedRoom?.svg_path) |
|
17 |
|
|
18 |
console.log(mapImage.viewBox) |
|
15 | 19 |
|
16 | 20 |
return ( |
17 |
<Box h={300}>
|
|
21 |
<Box> |
|
18 | 22 |
{/* Display the background image */} |
19 | 23 |
<SvgXml |
20 |
xml={mapImage} |
|
24 |
xml={mapImage.svg} |
|
25 |
height="300" |
|
26 |
|
|
27 |
preserveAspectRatio="xMidYMid meet" |
|
21 | 28 |
/> |
22 | 29 |
|
23 | 30 |
{/* Display the MapView on top of the background image */} |
src/pages/PlanViewPage.tsx | ||
---|---|---|
297 | 297 |
floorMapImageLoading ? |
298 | 298 |
<LoadingBox text="Loading castle plan" /> |
299 | 299 |
: |
300 |
floorMapImage && <CastlePlanView mapImage={floorMapImage} selectedRoom={selectedRoom} /> |
|
300 |
floorMapImage && |
|
301 |
<Box mt={2.5} ml={2.5}> |
|
302 |
<CastlePlanView mapImage={floorMapImage} selectedRoom={selectedRoom} /> |
|
303 |
</Box> |
|
301 | 304 |
) |
302 | 305 |
} |
303 | 306 |
|
src/stores/actions/planThunks.ts | ||
---|---|---|
2 | 2 |
import { SortOptions } from "../../types/general"; |
3 | 3 |
import { Note } from "../../types/note"; |
4 | 4 |
import { getPlanAllRequest, getPlanFloorImageRequest, getPlanItemsRequest } from "../../api/planservice"; |
5 |
import { Floor, Room } from "../../types/plan"; |
|
5 |
import { Floor, PlanImage, Room } from "../../types/plan";
|
|
6 | 6 |
import { ItemPreviewType } from "../../types/listViewTypes"; |
7 | 7 |
import { StringLiteralType } from "typescript"; |
8 | 8 |
import { Inventory } from "../../types/searchFormTypes"; |
9 | 9 |
|
10 |
// @ts-ignore |
|
11 |
import { parseString } from 'react-native-xml2js'; |
|
12 |
|
|
10 | 13 |
export const getFloorList = createAsyncThunk( |
11 | 14 |
"plan/getFloorList", |
12 | 15 |
async () => { |
... | ... | |
125 | 128 |
const response = await getPlanFloorImageRequest(floorId) |
126 | 129 |
|
127 | 130 |
if (response.status === 200) { |
128 |
return response.data |
|
131 |
|
|
132 |
const svg : string = response.data |
|
133 |
|
|
134 |
const output : PlanImage = { |
|
135 |
svg: svg, |
|
136 |
} |
|
137 |
|
|
138 |
parseString(svg, (err : any, result: any) => { |
|
139 |
if (!err && result && result.svg && result.svg.$.viewBox) { |
|
140 |
const [x, y, width, height] = result.svg.$.viewBox.split(' ').map(Number); |
|
141 |
|
|
142 |
// Set the SVG information in your component's state or use it as needed |
|
143 |
output.viewBox = { x, y, width, height }; |
|
144 |
} |
|
145 |
}); |
|
146 |
|
|
147 |
return output |
|
129 | 148 |
} else { |
130 | 149 |
return Promise.reject(response.data ? response.data : "Get plan floor image request failed") |
131 | 150 |
} |
src/types/plan.ts | ||
---|---|---|
34 | 34 |
label: string |
35 | 35 |
} |
36 | 36 |
|
37 |
export type PlanImage = { |
|
38 |
svg: string, |
|
39 |
|
|
40 |
viewBox?: { |
|
41 |
x: number, |
|
42 |
y: number, |
|
43 |
width: number, |
|
44 |
height: number |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
37 | 48 |
export type PlanViewState = { |
38 | 49 |
|
39 | 50 |
// floorList |
... | ... | |
51 | 62 |
itemList: Record<string, ItemPreviewType[]> |
52 | 63 |
|
53 | 64 |
// plan |
54 |
mapImage?: string
|
|
65 |
mapImage?: PlanImage
|
|
55 | 66 |
mapImageLoading?: boolean |
56 | 67 |
|
57 | 68 |
// last error |
Také k dispozici: Unified diff
re #10871: PlanViewPage: Parse map xml