Browse Source

Merge branch 'main' of https://github.com/IGSD-UoW/WPD-MobileApp into main

master
analuizaff 3 years ago
parent
commit
99412a99d4
  1. 49
      src/app/components/MapMarkerList.js
  2. 1
      src/app/components/MapModal.js
  3. 24
      src/app/components/map/LeafLetMap.js
  4. 70
      src/app/components/map/OpenStreetMap.js
  5. 3
      src/app/hooks/selectFromDB.js
  6. 62
      src/app/navigation/AppNavigator.js
  7. 1
      src/app/navigation/NewListingButton.js
  8. 2
      src/app/screens/ForecastScreen.js
  9. 5
      src/app/screens/MapFeedScreen.js
  10. 2
      src/app/screens/MessagesScreen.js
  11. 2
      src/app/screens/SharingDataScreen.js
  12. 2
      src/package.json

49
src/app/components/MapMarkerList.js

@ -1,45 +1,20 @@
import useMarkers from "../hooks/selectFromDB";
function isRequestedValue(
item,
renderRain,
renderFlood,
renderRiver,
renderPluviometer,
renderOfficialPluviometer
) {
function isRequestedValue(item, renderOptions) {
return ( return (
(item.name == "pluviometer" && renderPluviometer) ||
(item.name == "officialPluviometer") & renderOfficialPluviometer ||
(item.name == "rain" && renderRain) ||
(item.name == "river" && renderRiver) ||
(item.name == "flood" && renderFlood)
(item.name == "pluviometer" && renderOptions.citzen.pluviometer) ||
(item.name == "officialPluviometer" &&
renderOptions.oficial.automaticPluviometer) ||
(item.name == "rain" && renderOptions.citzen.rain) ||
(item.name == "river" && renderOptions.citzen.riverFlood) ||
(item.name == "flood" && renderOptions.citzen.floodRisk)
); );
} }
function MapMarkerList({
markers,
renderRain = true,
renderFlood = true,
renderRiver = true,
renderPluviometer = true,
renderOfficialPluviometer = true,
}) {
// FIXME: Resolve this later!!!
return markers.markers;
function MapMarkerList({ markers, renderOptions }) {
if (!markers) return null;
// return [...markers.markers].filter(([k, item]) => {
// isRequestedValue(
// item,
// renderRain,
// renderFlood,
// renderRiver,
// renderPluviometer,
// renderOfficialPluviometer
// )
// }
// );
return [...markers.markers].filter(([_, item]) => {
return isRequestedValue(item, renderOptions);
});
} }
export { MapMarkerList }; export { MapMarkerList };

1
src/app/components/MapModal.js

@ -214,6 +214,7 @@ function MapModal({showModal, setShowModal, markers}) {
if (currentMarker != undefined && showModal != null) { if (currentMarker != undefined && showModal != null) {
return ( return (
<SelfClosingModal <SelfClosingModal
style={{ position: "absolute" }}
animationType="slide" animationType="slide"
transparent={true} transparent={true}
showModal={showModal} showModal={showModal}

24
src/app/components/map/LeafLetMap.js

@ -59,6 +59,15 @@ function handleEvent(event) {
return code_to_function[payload.code](payload); return code_to_function[payload.code](payload);
} }
function deleteAllMarkers(mapRef) {
mapRef.injectJavaScript(`
for (const [key, value] of Object.entries(markers)) {
map.removeLayer(value);
}
markers = {};
`);
}
async function insertMarker(mapRef, ID, coordinate, icon) { async function insertMarker(mapRef, ID, coordinate, icon) {
mapRef.injectJavaScript(` mapRef.injectJavaScript(`
var customIcon = L.divIcon({ var customIcon = L.divIcon({
@ -70,13 +79,18 @@ async function insertMarker(mapRef, ID, coordinate, icon) {
// Check if there is no other marker with same ID already in map // Check if there is no other marker with same ID already in map
if (!(${ID} in markers)) { if (!(${ID} in markers)) {
// Creates marker object // Creates marker object
markers[${ID}] = L.marker([${coordinate.latitude}, ${
coordinate.longitude
}], {icon: customIcon, ID: ${ID}});
markers[${ID}] = L.marker([${coordinate.latitude}, ${coordinate.longitude}], {icon: customIcon, ID: ${ID}});
// Add marker to map and bing callback event to its function
// Add marker to map and bind callback event to its function
markers[${ID}].addTo(map).on('click', onPopupClick); markers[${ID}].addTo(map).on('click', onPopupClick);
}`); }`);
} }
export { loadHTMLFile, handleEvent, insertMarker, goToRegion, setViewCode };
export {
loadHTMLFile,
handleEvent,
insertMarker,
goToRegion,
setViewCode,
deleteAllMarkers,
};

70
src/app/components/map/OpenStreetMap.js

@ -1,16 +1,16 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { View, StyleSheet, Text } from "react-native";
import { View } from "react-native";
import WebView from "react-native-webview"; import WebView from "react-native-webview";
import { import {
setViewCode, setViewCode,
handleEvent, handleEvent,
insertMarker, insertMarker,
deleteAllMarkers,
} from "./LeafLetMap"; } from "./LeafLetMap";
import MapModal from "../MapModal"; import MapModal from "../MapModal";
import html_content from "./Map.js"; import html_content from "./Map.js";
import MapDataMenu from "../MapDataMenu"; import MapDataMenu from "../MapDataMenu";
import {MapMarkerList} from "../MapMarkerList";
import { MapMarkerList } from "../MapMarkerList";
function bindEventsToListeners( function bindEventsToListeners(
event, event,
@ -34,14 +34,14 @@ function bindEventsToListeners(
} }
function notEmpy(lista) { function notEmpy(lista) {
return lista && lista.size > 0;
return lista && lista.length > 0;
} }
export default function OpenStreetMap({ export default function OpenStreetMap({
markers, markers,
clickListener, clickListener,
moveEndListener, moveEndListener,
isForm=false
isForm = false,
}) { }) {
const [dataOptionsToShow, setDataOptionsToShow] = useState({ const [dataOptionsToShow, setDataOptionsToShow] = useState({
oficial: { oficial: {
@ -49,7 +49,7 @@ export default function OpenStreetMap({
susceptibilityAreas: false, susceptibilityAreas: false,
}, },
citzen: { citzen: {
floodRisk: false,
floodRisk: true,
pluviometer: true, pluviometer: true,
rain: false, rain: false,
floodZones: true, floodZones: true,
@ -57,31 +57,34 @@ export default function OpenStreetMap({
}, },
}); });
console.log(dataOptionsToShow)
const [mapRef, setMapRef] = useState(null); const [mapRef, setMapRef] = useState(null);
const webviewContent = html_content; const webviewContent = html_content;
const [markerListener, setMarkerListener] = useState(null); const [markerListener, setMarkerListener] = useState(null);
const viewFunction = setViewCode(global.location.lat, global.location.long); const viewFunction = setViewCode(global.location.lat, global.location.long);
const markersList = MapMarkerList({markers: markers, renderRain: true})
const markersList = MapMarkerList({
markers: markers,
renderOptions: dataOptionsToShow,
});
// console.log(markersList)
markersList &&
mapRef &&
notEmpy(markersList) &&
markersList.forEach((val, _) => {
insertMarker(mapRef, val.ID, val.coordinate, val.image);
});
// markersList &&
// mapRef &&
// notEmpy(markersList) &&
// markersList.forEach((val, _) => {
// // console.log(val);
// insertMarker(mapRef, val.ID, val.coordinate, val.image);
// });
useEffect(() => { useEffect(() => {
markersList &&
mapRef &&
notEmpy(markersList) &&
markersList.forEach((val, _) => {
insertMarker(mapRef, val.ID, val.coordinate, val.image);
if (markersList && mapRef && notEmpy(markersList)) {
deleteAllMarkers(mapRef);
markersList.forEach((val, k) => {
insertMarker(mapRef, val[1].ID, val[1].coordinate, val[1].image);
}); });
}, [markersList])
}
}, [markersList, dataOptionsToShow]);
return ( return (
<View flex={1}> <View flex={1}>
@ -104,18 +107,19 @@ export default function OpenStreetMap({
/> />
)} )}
{!isForm && ( {!isForm && (
<View>
<MapModal
showModal={markerListener}
setShowModal={setMarkerListener}
markers={markersList}
/>
<View>
<MapModal
showModal={markerListener}
setShowModal={setMarkerListener}
markers={markers.markers}
/>
<MapDataMenu
dataOptionsToShow={dataOptionsToShow}
setDataOptionsToShow={setDataOptionsToShow}/>
</View>)}
<MapDataMenu
dataOptionsToShow={dataOptionsToShow}
setDataOptionsToShow={setDataOptionsToShow}
/>
</View>
)}
</View> </View>
); );
} }

3
src/app/hooks/selectFromDB.js

@ -99,11 +99,10 @@ function parseFloodZones(row) {
} }
function parseRiverLevel(row) { function parseRiverLevel(row) {
console.log("IDDD " + row["Id"]);
if (!is_valid(row["Id"], "river")) { if (!is_valid(row["Id"], "river")) {
return null; return null;
} }
console.log(JSON.stringify(row));
// console.log(JSON.stringify(row));
// displacement += offset; // displacement += offset;
const riverLevel = ["baixo", "normal", "alto", "transbordando"]; const riverLevel = ["baixo", "normal", "alto", "transbordando"];
const riverIdx = row["RiverIdx"]; const riverIdx = row["RiverIdx"];

62
src/app/navigation/AppNavigator.js

@ -22,30 +22,16 @@ const AppNavigator = () => (
), ),
}} }}
/> />
<Tab.Screen
name="Previsão"
component={ForecastNavigator}
options={{
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons
name="check-circle"
color={color}
size={size}
/>
),
}}
/>
<Tab.Screen <Tab.Screen
name="SharingData" name="SharingData"
component={SharingDataOptionsNavigator} component={SharingDataOptionsNavigator}
options={({ navigation }) => ({ options={({ navigation }) => ({
tabBarButton: () => (
tabBarButton: () => (
<NewListingButton <NewListingButton
onPress={() => onPress={() =>
navigation.navigate("SharingData",{
screen:"Voltar",
initial: false,
navigation.navigate("SharingData", {
screen: "Voltar",
initial: false,
}) })
} }
/> />
@ -59,29 +45,43 @@ const AppNavigator = () => (
), ),
})} })}
/> />
<Tab.Screen <Tab.Screen
name="Notificação"
component={MessagesNavigator}
name="Previsão"
component={ForecastNavigator}
options={{ options={{
tabBarIcon: ({ color, size }) => ( tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons <MaterialCommunityIcons
name="bell"
name="check-circle"
color={color} color={color}
size={size} size={size}
/> />
), ),
}} }}
/> />
<Tab.Screen
name="Perfil"
component={AccountNavigator}
options={{
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="account" color={color} size={size} />
),
}}
/>
{/* <Tab.Screen */}
{/* name="Notificação" */}
{/* component={MessagesNavigator} */}
{/* options={{ */}
{/* tabBarIcon: ({ color, size }) => ( */}
{/* <MaterialCommunityIcons */}
{/* name="bell" */}
{/* color={color} */}
{/* size={size} */}
{/* /> */}
{/* ), */}
{/* }} */}
{/* /> */}
{/* <Tab.Screen */}
{/* name="Perfil" */}
{/* component={AccountNavigator} */}
{/* options={{ */}
{/* tabBarIcon: ({ color, size }) => ( */}
{/* <MaterialCommunityIcons name="account" color={color} size={size} /> */}
{/* ), */}
{/* }} */}
{/* /> */}
</Tab.Navigator> </Tab.Navigator>
); );

1
src/app/navigation/NewListingButton.js

@ -22,6 +22,7 @@ const styles = StyleSheet.create({
container: { container: {
alignItems: "center", alignItems: "center",
backgroundColor: colors.primary, backgroundColor: colors.primary,
marginHorizontal: 60,
borderColor: colors.white, borderColor: colors.white,
borderRadius: 50, borderRadius: 50,
borderWidth: 0, borderWidth: 0,

2
src/app/screens/ForecastScreen.js

@ -7,6 +7,7 @@ import getWeatherForecast from "../api/weather_forecast";
import assets from "../config/assets"; import assets from "../config/assets";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import Swipeable from "react-native-gesture-handler/Swipeable"; import Swipeable from "react-native-gesture-handler/Swipeable";
import HeaderBarMenu from "../components/HeaderBarMenu";
function forecastDay(day, setDay) { function forecastDay(day, setDay) {
return ( return (
@ -297,6 +298,7 @@ function renderErrorScreen() {
} }
function ForecastScreen(props) { function ForecastScreen(props) {
HeaderBarMenu(props.navigation);
const forecast = getWeatherForecast(); const forecast = getWeatherForecast();
return ( return (

5
src/app/screens/MapFeedScreen.js

@ -5,8 +5,11 @@ import attachFocusToQuery from "../hooks/useFocus";
import { MapMarkerList } from "../components/MapMarkerList"; import { MapMarkerList } from "../components/MapMarkerList";
import formsApi from "../api/getforms"; import formsApi from "../api/getforms";
import useMarkers from "../hooks/selectFromDB"; import useMarkers from "../hooks/selectFromDB";
import HeaderBarMenu from "../components/HeaderBarMenu";
export default function MapFeedScreen(props) {
HeaderBarMenu(props.navigation);
export default function MapFeedScreen() {
const focusChanged = attachFocusToQuery(); const focusChanged = attachFocusToQuery();
const [error, setError] = useState(false); const [error, setError] = useState(false);
const markers = useMarkers(focusChanged); const markers = useMarkers(focusChanged);

2
src/app/screens/MessagesScreen.js

@ -1,8 +1,10 @@
import React from "react"; import React from "react";
import Screen from "../components/Screen"; import Screen from "../components/Screen";
import InDevelopment from "../components/InDevelopment"; import InDevelopment from "../components/InDevelopment";
import HeaderBarMenu from "../components/HeaderBarMenu";
function MessageScreen(props) { function MessageScreen(props) {
HeaderBarMenu(props.navigation);
return ( return (
<Screen> <Screen>
<InDevelopment /> <InDevelopment />

2
src/app/screens/SharingDataScreen.js

@ -5,9 +5,11 @@ import { TouchableOpacity, ScrollView } from "react-native";
import assets from "../config/assets"; import assets from "../config/assets";
import { scaleDimsFromWidth, dimensions } from "../config/dimensions"; import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
import SvgLabeledButton from "../components/SvgLabeledButton"; import SvgLabeledButton from "../components/SvgLabeledButton";
import HeaderBarMenu from "../components/HeaderBarMenu";
//1/3 //1/3
function SharingDataScreen({ navigation }) { function SharingDataScreen({ navigation }) {
HeaderBarMenu(navigation);
const dims = scaleDimsFromWidth(93, 106, 35); const dims = scaleDimsFromWidth(93, 106, 35);
// const dims = { width: "100%", height: "100%" }; // const dims = { width: "100%", height: "100%" };

2
src/package.json

@ -59,7 +59,7 @@
"react-native-web": "~0.13.12", "react-native-web": "~0.13.12",
"react-native-webview": "10.7.0", "react-native-webview": "10.7.0",
"react-navigation": "^4.4.3", "react-navigation": "^4.4.3",
"react-navigation-header-buttons": "^7.0.1",
"react-navigation-header-buttons": "^7.0.2",
"react-navigation-tabs": "^2.10.1", "react-navigation-tabs": "^2.10.1",
"rn-checkbox-list": "^0.4.0", "rn-checkbox-list": "^0.4.0",
"searchable-flatlist": "0.0.4", "searchable-flatlist": "0.0.4",

Loading…
Cancel
Save