forked from cemaden-educacao/WPD-MobileApp
GabrielTrettel
3 years ago
12 changed files with 311 additions and 26 deletions
-
3package-lock.json
-
3src/App.js
-
45src/app/api/Websockets/SocketClient.js
-
8src/app/components/MapMarkerList.js
-
1src/app/components/MapModal.js
-
19src/app/components/map/LeafLetMap.js
-
1src/app/components/map/Map.html
-
2src/app/components/map/Map.js
-
32src/app/components/map/OpenStreetMap.js
-
41src/app/hooks/useFiltering.js
-
151src/app/hooks/useFormsAswers.js
-
31src/app/screens/MapFeedScreen.js
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"lockfileVersion": 1 |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
import { useEffect, useState } from 'react'; |
||||
|
import { useFiltering } from '../../hooks/useFiltering'; |
||||
|
|
||||
|
function isRequestedValue(item, renderOptions) { |
||||
|
if ( |
||||
|
(item.name == "pluviometer" && renderOptions.citzen.pluviometer) || |
||||
|
(item.name == "automaticPluviometer" && |
||||
|
renderOptions.oficial.automaticPluviometer) || |
||||
|
(item.name == "rain" && renderOptions.citzen.rain) || |
||||
|
(item.name == "riverFlood" && renderOptions.citzen.riverFlood ) || |
||||
|
(item.name == "floodZones" && renderOptions.citzen.floodRisk) || |
||||
|
(item.name == "susceptibilityAreas" && renderOptions.oficial.susceptibilityAreas) |
||||
|
) { |
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function verify_existingSockets(formType, renderOptions) { |
||||
|
if (formType.response == null && isRequestedValue(formType, renderOptions)) { |
||||
|
console.log("Criou socket: "+formType.name); |
||||
|
const socket = new WebSocket("wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + formType.endpoint); |
||||
|
|
||||
|
socket.onmessage = ({ data }) => { |
||||
|
formType.response = data; |
||||
|
} |
||||
|
} |
||||
|
/* else { |
||||
|
console.log("\nresposta preenchida"); |
||||
|
}*/ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
export default function SocketClient(dataOptionObject, focusChanged, data) { |
||||
|
|
||||
|
|
||||
|
// useEffect(() => {
|
||||
|
data.map((e) => verify_existingSockets(e, dataOptionObject)); |
||||
|
|
||||
|
// }, []);
|
||||
|
console.log("data socket client: "+ JSON.stringify(data)); |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
|
@ -0,0 +1,41 @@ |
|||||
|
function useFiltering() { |
||||
|
const filters = { |
||||
|
"forms": [ |
||||
|
{ |
||||
|
name: "floodZones", |
||||
|
endpoint: "type=FLOODZONES_FORM&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
|
||||
|
}, { |
||||
|
name: "rain", |
||||
|
endpoint: "type=RAIN_FORM&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
}, |
||||
|
{ |
||||
|
name: "riverFlood", |
||||
|
endpoint: "type=RIVERFLOOD_FORM&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
}, |
||||
|
{ |
||||
|
name: "pluviometer", |
||||
|
endpoint: "type=PLUVIOMETER_REGISTRATION&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
}, |
||||
|
{ |
||||
|
name: "susceptibilityAreas", |
||||
|
endpoint: "type=FLOODZONES_OFFICIAL&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
}, |
||||
|
{ |
||||
|
name: "automaticPluviometer", |
||||
|
endpoint: "type=PLUVIOMETERS_OFFICIAL&lat=-9.98132&lon=-67.81544&buffer=5000&limit=5", |
||||
|
response: null, |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return filters; |
||||
|
} |
||||
|
|
||||
|
export { useFiltering }; |
@ -0,0 +1,151 @@ |
|||||
|
import React, { useEffect, useState } from "react"; |
||||
|
import * as Location from 'expo-location'; |
||||
|
import SocketClient from "../api/Websockets/SocketClient"; |
||||
|
import assets from "../config/assets"; |
||||
|
import PinIntransitavel from "../assets/floodZonesAssets/PinIntransitavel"; |
||||
|
import PinTransitavel from "../assets/floodZonesAssets/PinTransitavel"; |
||||
|
|
||||
|
|
||||
|
const custom_assets_pin = { |
||||
|
pluviometer: assets.pluviometer_pin, |
||||
|
officialPluviometer: assets.officialPluviometer_pin, |
||||
|
floodZones: { |
||||
|
passable: PinTransitavel, |
||||
|
not_passable: PinIntransitavel, |
||||
|
}, |
||||
|
riverLevel: ["low_pin", "normal_pin", "high_pin", "flooding_pin"].map( |
||||
|
(key) => { |
||||
|
return assets.riverLevel[key]; |
||||
|
} |
||||
|
), |
||||
|
rainLevel: [ |
||||
|
"rain_0_5_pin", |
||||
|
"rain_1_5_pin", |
||||
|
"rain_2_5_pin", |
||||
|
"rain_3_5_pin", |
||||
|
].map((key) => { |
||||
|
return assets.rainLevel[key]; |
||||
|
}), |
||||
|
}; |
||||
|
|
||||
|
function getImage(name, situation) { |
||||
|
if (name == "automaticPluviometer") { |
||||
|
return custom_assets_pin.pluviometer; |
||||
|
} |
||||
|
|
||||
|
if (name == "pluviometer") { |
||||
|
return custom_assets_pin.pluviometer; |
||||
|
} |
||||
|
|
||||
|
if (name == "rain") { |
||||
|
if (situation == "sem chuva") { |
||||
|
return custom_assets_pin.rainLevel[0]; |
||||
|
} else if (situation == "chuva fraca") { |
||||
|
return custom_assets_pin.rainLevel[1]; |
||||
|
} else if (situation == "chuva moderada") { |
||||
|
return custom_assets_pin.rainLevel[2]; |
||||
|
} else if (situation == "chuva forte") { |
||||
|
return custom_assets_pin.rainLevel[3]; |
||||
|
} |
||||
|
return custom_assets_pin.rainLevel[3]; |
||||
|
} |
||||
|
|
||||
|
if (name == "riverFlood") { |
||||
|
if (situation == "baixo") { |
||||
|
return custom_assets_pin.riverLevel[0]; |
||||
|
} else if (situation == "normal") { |
||||
|
return custom_assets_pin.riverLevel[1]; |
||||
|
} else if (situation == "alto") { |
||||
|
return custom_assets_pin.riverLevel[2]; |
||||
|
} else if (situation == "inundar") { |
||||
|
return custom_assets_pin.riverLevel[3]; |
||||
|
} |
||||
|
return custom_assets_pin.riverLevel[0]; |
||||
|
} |
||||
|
if (name == "floodZones") { |
||||
|
if (situation == "transitavel") { |
||||
|
return custom_assets_pin.floodZones.passable; |
||||
|
} else { |
||||
|
return custom_assets_pin.floodZones.not_passable; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function buildPolygonsObject(markers, response, name) { |
||||
|
var coordinate = []; |
||||
|
var formsanswersgeom = response.formsanswersgeom; |
||||
|
const arrayCoordinates = (JSON.parse(formsanswersgeom)["coordinates"][0]); |
||||
|
var n = Object.keys(arrayCoordinates).length; |
||||
|
|
||||
|
// console.log(arrayCoordinates);
|
||||
|
|
||||
|
for (let i = 0; i < n; i++) { |
||||
|
var lat = arrayCoordinates[i][1]; |
||||
|
var lon = arrayCoordinates[i][0]; |
||||
|
coordinate.push([lat, lon]); |
||||
|
} |
||||
|
// console.log(coordinate);
|
||||
|
var polygonObject = { |
||||
|
ID: response.formsanswersid, |
||||
|
name: name, |
||||
|
title: "Titulo", //response.fieldsanswerssituation
|
||||
|
address: "Endereço",//response.fieldsanswerseventaddress,
|
||||
|
coordinate: { coordinate }, |
||||
|
date: "data" + " | " + "hora", //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime,
|
||||
|
description: "comentário", //response.fielsanswercomment,
|
||||
|
image: "",//getMarkerImage(answer.name),
|
||||
|
} |
||||
|
|
||||
|
markers.set(polygonObject.ID, polygonObject); |
||||
|
} |
||||
|
|
||||
|
function buildMarkerObject(markers, response, name) { |
||||
|
const formsanswersgeom = JSON.parse(response.formsanswersgeom)["coordinates"]; |
||||
|
|
||||
|
var markerObject = { |
||||
|
ID: response.formsanswersid, |
||||
|
name: name, |
||||
|
title: "Titulo", //response.fieldsanswerssituation
|
||||
|
address: "Endereço",//response.fieldsanswerseventaddress,
|
||||
|
coordinate: { |
||||
|
latitude: formsanswersgeom[1], |
||||
|
longitude: formsanswersgeom[0], |
||||
|
}, |
||||
|
date: "data" + " | " + "hora", //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime,
|
||||
|
description: "comentário", //response.fielsanswercomment,
|
||||
|
image: getImage(name, "situação"),//getMarkerImage(answer.name),
|
||||
|
} |
||||
|
|
||||
|
markers.set(markerObject.ID, markerObject); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
function verifyResponse(markers, data) { |
||||
|
// console.log(data.response);
|
||||
|
if (data.response != null) { |
||||
|
const response = JSON.parse(data.response).responseData.array_to_json; |
||||
|
response.forEach((r) => r.formcode == "FLOODZONES_OFFICIAL" ? buildPolygonsObject(markers.markers, r, data.name) : buildMarkerObject(markers.markers, r, data.name)); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
const getFormsAnswers = (dataOptionObject, focusChanged, data) => { |
||||
|
var markers = { markers: new Map() }; |
||||
|
const answers = SocketClient(dataOptionObject, focusChanged, data); |
||||
|
|
||||
|
// console.log("\n\nAnswers: " + JSON.stringify(answers));
|
||||
|
|
||||
|
answers.forEach((r) => verifyResponse(markers, r));//buildMarkerObject(markers.markers, r));
|
||||
|
// console.log("\n\nMarkers: " + JSON.stringify(markers));
|
||||
|
return markers; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
export { getFormsAnswers }; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue