diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/src/App.js b/src/App.js index 9ade42e..5faf779 100644 --- a/src/App.js +++ b/src/App.js @@ -23,7 +23,8 @@ export default function App() { const restoreUser = async () => { const user = await authStorage.getUser(); - global.location = await getLocation(); + global.location ={"lat":-10.0173780726763, + "long": -67.8170775249999} // await getLocation(); if (user) setUser(user); }; diff --git a/src/app/api/Websockets/SocketClient.js b/src/app/api/Websockets/SocketClient.js new file mode 100644 index 0000000..469eaf7 --- /dev/null +++ b/src/app/api/Websockets/SocketClient.js @@ -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; +}; + + diff --git a/src/app/components/MapMarkerList.js b/src/app/components/MapMarkerList.js index 4d7d36c..55f8566 100644 --- a/src/app/components/MapMarkerList.js +++ b/src/app/components/MapMarkerList.js @@ -1,17 +1,19 @@ function isRequestedValue(item, renderOptions) { return ( (item.name == "pluviometer" && renderOptions.citzen.pluviometer) || - (item.name == "officialPluviometer" && + (item.name == "automaticPluviometer" && renderOptions.oficial.automaticPluviometer) || (item.name == "rain" && renderOptions.citzen.rain) || - (item.name == "river" && renderOptions.citzen.riverFlood) || - (item.name == "flood" && renderOptions.citzen.floodRisk) + (item.name == "riverFlood" && renderOptions.citzen.riverFlood) || + (item.name == "floodZones" && renderOptions.citzen.floodRisk) || + (item.name == "susceptibilityAreas" && renderOptions.oficial.susceptibilityAreas) ); } function MapMarkerList({ markers, renderOptions }) { if (!markers) return null; + return [...markers.markers].filter(([_, item]) => { return isRequestedValue(item, renderOptions); }); diff --git a/src/app/components/MapModal.js b/src/app/components/MapModal.js index e3db450..abaf187 100644 --- a/src/app/components/MapModal.js +++ b/src/app/components/MapModal.js @@ -231,6 +231,7 @@ function isPluviometer(name) { function MapModal({ showModal, setShowModal, markers }) { var currentMarker = undefined; + //console.log(markers); if (markers && showModal != null && markers.has(showModal)) { currentMarker = markers.get(showModal); } diff --git a/src/app/components/map/LeafLetMap.js b/src/app/components/map/LeafLetMap.js index d43b0f5..932a912 100644 --- a/src/app/components/map/LeafLetMap.js +++ b/src/app/components/map/LeafLetMap.js @@ -75,21 +75,36 @@ async function insertMarker(mapRef, ID, coordinate, icon) { html: \`${icon}\`, iconSize: 70 }); - // Check if there is no other marker with same ID already in map if (!(${ID} in markers)) { // Creates marker object markers[${ID}] = L.marker([${coordinate.latitude}, ${coordinate.longitude}], {icon: customIcon, ID: ${ID}}); - // Add marker to map and bind callback event to its function markers[${ID}].addTo(map).on('click', onPopupClick); }`); } +async function insertPolygon(mapRef, ID, coordinate) { + // console.log("COORDENADAS: "+JSON.stringify(coordinate.coordinate)); + var coordinates = JSON.stringify(coordinate.coordinate); + // console.log(coordinates); + mapRef.injectJavaScript(` + if (!(${ID} in polygons)) { + polygons[${ID}] = L.polygon(${coordinates}, { ID: ${ID}}); + + polygons[${ID}].addTo(map); + } + `); + /* mapRef.injectJavaScript(` + + var polygon = L.polygon(${coordinates}).addTo(map); + `);*/ +} export { loadHTMLFile, handleEvent, insertMarker, + insertPolygon, goToRegion, setViewCode, deleteAllMarkers, diff --git a/src/app/components/map/Map.html b/src/app/components/map/Map.html index 7d1d8eb..5017ae0 100644 --- a/src/app/components/map/Map.html +++ b/src/app/components/map/Map.html @@ -51,6 +51,7 @@