From 138a79b5027a3b15fc93485902b715884a8c91fa Mon Sep 17 00:00:00 2001 From: analuizaff Date: Tue, 7 Sep 2021 20:31:42 -0300 Subject: [PATCH] solving polygons issue --- src/App.js | 3 +- src/app/api/Websockets/SocketClient.js | 20 +++--- src/app/components/MapModal.js | 1 + src/app/components/map/LeafLetMap.js | 8 ++- src/app/components/map/Map.js | 2 + src/app/components/map/OpenStreetMap.js | 3 +- src/app/hooks/useFiltering.js | 8 +-- src/app/hooks/useFormsAswers.js | 87 +++++++++++++++++++------ src/app/screens/MapFeedScreen.js | 10 ++- 9 files changed, 99 insertions(+), 43 deletions(-) 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 index ae10469..469eaf7 100644 --- a/src/app/api/Websockets/SocketClient.js +++ b/src/app/api/Websockets/SocketClient.js @@ -4,10 +4,10 @@ import { useFiltering } from '../../hooks/useFiltering'; function isRequestedValue(item, renderOptions) { if ( (item.name == "pluviometer" && renderOptions.citzen.pluviometer) || - /*(item.name == "automaticPluviometer" && - renderOptions.oficial.automaticPluviometer) ||*/ + (item.name == "automaticPluviometer" && + renderOptions.oficial.automaticPluviometer) || (item.name == "rain" && renderOptions.citzen.rain) || - (item.name == "riverFlood" && renderOptions.citzen.riverFlood) || + (item.name == "riverFlood" && renderOptions.citzen.riverFlood ) || (item.name == "floodZones" && renderOptions.citzen.floodRisk) || (item.name == "susceptibilityAreas" && renderOptions.oficial.susceptibilityAreas) ) { @@ -18,7 +18,7 @@ function isRequestedValue(item, renderOptions) { function verify_existingSockets(formType, renderOptions) { if (formType.response == null && isRequestedValue(formType, renderOptions)) { - // console.log("Resposta é null"); + console.log("Criou socket: "+formType.name); const socket = new WebSocket("wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + formType.endpoint); socket.onmessage = ({ data }) => { @@ -31,14 +31,14 @@ function verify_existingSockets(formType, renderOptions) { } -export default function SocketClient(dataOptionObject, focusChanged) { - const [data, setData] = useState(useFiltering()); +export default function SocketClient(dataOptionObject, focusChanged, data) { + - useEffect(() => { - data.forms.map((e) => verify_existingSockets(e, dataOptionObject)); - - }, [dataOptionObject, focusChanged]); + // useEffect(() => { + data.map((e) => verify_existingSockets(e, dataOptionObject)); +// }, []); + console.log("data socket client: "+ JSON.stringify(data)); return data; }; 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 1046e13..932a912 100644 --- a/src/app/components/map/LeafLetMap.js +++ b/src/app/components/map/LeafLetMap.js @@ -86,11 +86,13 @@ async function insertMarker(mapRef, ID, coordinate, icon) { async function insertPolygon(mapRef, ID, coordinate) { // console.log("COORDENADAS: "+JSON.stringify(coordinate.coordinate)); var coordinates = JSON.stringify(coordinate.coordinate); - // console.log(ID); + // console.log(coordinates); mapRef.injectJavaScript(` - polygons = (L.polygon(${coordinates}, { ID: ${ID}})); + if (!(${ID} in polygons)) { + polygons[${ID}] = L.polygon(${coordinates}, { ID: ${ID}}); - polygons.addTo(map); + polygons[${ID}].addTo(map); + } `); /* mapRef.injectJavaScript(` diff --git a/src/app/components/map/Map.js b/src/app/components/map/Map.js index 337e94d..b22423f 100644 --- a/src/app/components/map/Map.js +++ b/src/app/components/map/Map.js @@ -52,6 +52,8 @@ export default html_content = `