|
@@ -9,7 +9,7 @@ import { FontAwesome } from "@expo/vector-icons";
|
|
import * as ImagePicker from 'expo-image-picker';
|
|
import * as ImagePicker from 'expo-image-picker';
|
|
import { ImageInfo } from "expo-image-picker/build/ImagePicker.types";
|
|
import { ImageInfo } from "expo-image-picker/build/ImagePicker.types";
|
|
import React, { memo, useEffect, useState } from "react";
|
|
import React, { memo, useEffect, useState } from "react";
|
|
-import { ActivityIndicator, Dimensions, Image, Platform, SafeAreaView, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
|
|
|
|
+import { ActivityIndicator, Dimensions, Image, Platform, SafeAreaView, Text, TextInput, TouchableOpacity, View, ImageSourcePropType} from 'react-native';
|
|
import { ScrollView } from "react-native-gesture-handler";
|
|
import { ScrollView } from "react-native-gesture-handler";
|
|
import Modal from 'react-native-modal';
|
|
import Modal from 'react-native-modal';
|
|
import { checkMultiple, PERMISSIONS, RESULTS } from "react-native-permissions";
|
|
import { checkMultiple, PERMISSIONS, RESULTS } from "react-native-permissions";
|
|
@@ -19,6 +19,10 @@ import { colors, getMediaPermissions, lmTypes } from "../../../utils/GlobalUtils
|
|
import { IconButton, SecondaryButton } from "../../Buttons";
|
|
import { IconButton, SecondaryButton } from "../../Buttons";
|
|
import { PhotoPicker } from "../../PhotoPicker";
|
|
import { PhotoPicker } from "../../PhotoPicker";
|
|
import TouchOpaq from "./LandmarkDetailsPanel/TouchOpaq";
|
|
import TouchOpaq from "./LandmarkDetailsPanel/TouchOpaq";
|
|
|
|
+import {Svg , Rect, Image as ImageSVG} from 'react-native-svg'
|
|
|
|
+import ReactDOMServer from 'react-dom/server'; //npm i --save-dev @types/react-dom
|
|
|
|
+
|
|
|
|
+import IndoorFloor from "../IndoorFloor";
|
|
|
|
|
|
/**
|
|
/**
|
|
* Props for the {@link AddLandmarkPanel} component.
|
|
* Props for the {@link AddLandmarkPanel} component.
|
|
@@ -52,6 +56,10 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({newLandmark, setNewLandma
|
|
const [photos, setPhotos] = useState<LMPhoto[]>([])
|
|
const [photos, setPhotos] = useState<LMPhoto[]>([])
|
|
const [photoSourceMenuOpened, togglePhotoSourceMenu] = useState<boolean>(false)
|
|
const [photoSourceMenuOpened, togglePhotoSourceMenu] = useState<boolean>(false)
|
|
|
|
|
|
|
|
+ const imgWidth = 346
|
|
|
|
+ const imgHeight = 443
|
|
|
|
+ const imageDim = 5
|
|
|
|
+
|
|
const {
|
|
const {
|
|
addLandmarkAsync,
|
|
addLandmarkAsync,
|
|
resetAddLm,
|
|
resetAddLm,
|
|
@@ -76,12 +84,80 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({newLandmark, setNewLandma
|
|
resetAddLm();
|
|
resetAddLm();
|
|
}, [visible]);
|
|
}, [visible]);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ const renderIndoorLandmarkPin = (landmark: Landmark) => {
|
|
|
|
+ return (
|
|
|
|
+ <ImageSVG
|
|
|
|
+ x={landmark.longitude * imgWidth}
|
|
|
|
+ y={landmark.latitude * imgHeight}
|
|
|
|
+ width={imageDim}
|
|
|
|
+ height={imageDim}
|
|
|
|
+ href={lmTypes[landmark.landmark_type]['image'] as ImageSourcePropType} />
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // const renderLandmarkSvg = (floor: number) => {
|
|
|
|
+ // return (
|
|
|
|
+ // <Svg height={imgHeight} width={imgWidth}>
|
|
|
|
+ // <IndoorFloor floorNum={floor} />
|
|
|
|
+ // {renderIndoorLandmarkPin(newLandmark)}
|
|
|
|
+ // </Svg>
|
|
|
|
+ // )
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ const childToWeb = (child: any) => {
|
|
|
|
+ const { type, props } = child;
|
|
|
|
+ const name = type && type.displayName;
|
|
|
|
+ const webName = name && name[0].toLowerCase() + name.slice(1);
|
|
|
|
+ const Tag = webName ? webName : type;
|
|
|
|
+ return <Tag {...props}>{toWeb(props.children)}</Tag>;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const toWeb = (children: any) => React.Children.map(children, childToWeb);
|
|
|
|
+
|
|
|
|
+ function renderLandmarkSvg(floor) {
|
|
|
|
+ return (
|
|
|
|
+ // <svg height="100%" width="100%" style="background-color:#33AAFF" preserveAspectRatio="xMidYMid meet"><rect x="50" y="50" width="50" height="50" fill="#3399ff" stroke-width="3" stroke="rgb(0,0,0)"></rect></svg>
|
|
|
|
+ // style={{backgroundColor:'#33AAFF'}}
|
|
|
|
+ <Svg height="100%" width="100%" style={{ backgroundColor: '#33AAFF' }}>
|
|
|
|
+ <Rect
|
|
|
|
+ x="50"
|
|
|
|
+ y="50"
|
|
|
|
+ width="50"
|
|
|
|
+ height="50"
|
|
|
|
+ fill="#3399ff"
|
|
|
|
+ strokeWidth="3"
|
|
|
|
+ stroke="rgb(0,0,0)"
|
|
|
|
+ />
|
|
|
|
+ </Svg>
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function serialize() {
|
|
|
|
+ const element = renderLandmarkSvg(newLandmark.floor);
|
|
|
|
+ const webJsx = toWeb(element);
|
|
|
|
+ const svgString = ReactDOMServer.renderToStaticMarkup(webJsx);
|
|
|
|
+ console.log(svgString)
|
|
|
|
+ return svgString
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Calls {@link addLandmarkAsync} from {@link useLandmarks} to initate the process of adding a landmark, then closes the modal.
|
|
* Calls {@link addLandmarkAsync} from {@link useLandmarks} to initate the process of adding a landmark, then closes the modal.
|
|
*/
|
|
*/
|
|
const submit = async () => {
|
|
const submit = async () => {
|
|
// create svg content here, then pass it to addLandmarkAsync as the value of indoorLmLocImg
|
|
// create svg content here, then pass it to addLandmarkAsync as the value of indoorLmLocImg
|
|
- await addLandmarkAsync({landmarkValue: newLandmark, photos: photos, indoorLmLocImg: undefined }); // pass it in here
|
|
|
|
|
|
+ if(typeof newLandmark.floor === 'number'){
|
|
|
|
+ let rectangle = serialize()
|
|
|
|
+ await addLandmarkAsync({landmarkValue: newLandmark, photos: photos, indoorLmLocImg: rectangle }); // pass it in here
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ await addLandmarkAsync({landmarkValue: newLandmark, photos: photos });
|
|
|
|
+ }
|
|
|
|
+
|
|
close()
|
|
close()
|
|
}
|
|
}
|
|
|
|
|