|
|
@ -1,5 +1,4 @@ |
|
|
|
import { useState, useEffect, useReducer, useContext } from "react"; |
|
|
|
|
|
|
|
import assets from "../config/assets"; |
|
|
|
import PinIntransitavel from "../assets/floodZonesAssets/PinIntransitavel"; |
|
|
|
import PinTransitavel from "../assets/floodZonesAssets/PinTransitavel"; |
|
|
@ -15,6 +14,7 @@ const custom_assets = { |
|
|
|
return assets.rainLevel[key]; |
|
|
|
}), |
|
|
|
}; |
|
|
|
|
|
|
|
const custom_assets_pin = { |
|
|
|
pluviometer: assets.pluviometer_pin, |
|
|
|
officialPluviometer: assets.officialPluviometer_pin, |
|
|
@ -36,6 +36,7 @@ const custom_assets_pin = { |
|
|
|
return assets.rainLevel[key]; |
|
|
|
}), |
|
|
|
}; |
|
|
|
|
|
|
|
const initialState = { markers: new Map() }; |
|
|
|
|
|
|
|
function getImage(name, situation) { |
|
|
@ -87,14 +88,11 @@ function buildPolygonsObject(response, name) { |
|
|
|
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, |
|
|
@ -115,9 +113,9 @@ function buildMarkerObject(response, name) { |
|
|
|
const r = JSON.parse(response); |
|
|
|
const resposta = r.formsanswersgeom; |
|
|
|
const formsanswersgeom = JSON.parse(resposta).coordinates; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
ID: 3168, //response.formsanswersid,
|
|
|
|
ID: r.formsanswersid, //response.formsanswersid,
|
|
|
|
name: name, |
|
|
|
title: "Titulo", //response.fieldsanswerssituation
|
|
|
|
address: "Endereço", //response.fieldsanswerseventaddress,
|
|
|
@ -141,27 +139,25 @@ function verifyResponse(response, name) { |
|
|
|
if (answer.success == true) { |
|
|
|
const formAnswer = answer.responseData.array_to_json; |
|
|
|
|
|
|
|
answer.responseData.array_to_json.forEach( |
|
|
|
(r) => |
|
|
|
r.formcode == "FLOODZONES_OFFICIAL" |
|
|
|
? markers.push(buildPolygonsObject(r, name)) |
|
|
|
: markers.push(buildMarkerObject(JSON.stringify(r), name)) |
|
|
|
answer.responseData.array_to_json.forEach((r) => |
|
|
|
r.formcode == "FLOODZONES_OFFICIAL" |
|
|
|
? markers.push(buildPolygonsObject(r, name)) |
|
|
|
: markers.push(buildMarkerObject(JSON.stringify(r), name)) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
//console.log("\n--------------------------------------------\n"+JSON.stringify(markers)+"\n--------------------------------------------\n");
|
|
|
|
return markers; |
|
|
|
} |
|
|
|
|
|
|
|
function getFormsAnswers(socketObject, dispatch) { |
|
|
|
//console.log("\n\n-------------\n"+(socketObject.name +" : " + socketObject.socketUrl.readyState));
|
|
|
|
//const []
|
|
|
|
const [socketResponse, setSocketResponse] = useState(); |
|
|
|
|
|
|
|
socketObject.socketUrl.onmessage = ({ data }) => { |
|
|
|
setSocketResponse(data); |
|
|
|
}; |
|
|
|
useEffect(() => { |
|
|
|
socketObject.socketUrl.onmessage = ({ data }) => { |
|
|
|
// console.log(data)
|
|
|
|
dispatch({ increment: verifyResponse(data, socketObject.name) }); |
|
|
|
}; |
|
|
|
}, []); |
|
|
|
dispatch({ increment: verifyResponse(socketResponse, socketObject.name) }); |
|
|
|
}, [socketResponse]); |
|
|
|
} |
|
|
|
|
|
|
|
function reducer(state = initialState, action) { |
|
|
@ -169,15 +165,12 @@ function reducer(state = initialState, action) { |
|
|
|
state.markers.set(val.ID, val); |
|
|
|
}); |
|
|
|
|
|
|
|
return { |
|
|
|
markers: state.markers, |
|
|
|
}; |
|
|
|
return { markers: state.markers }; |
|
|
|
} |
|
|
|
|
|
|
|
export default function useSocketMarkers() { |
|
|
|
const [state, dispatch] = useReducer(reducer, initialState); |
|
|
|
global.formsSockets.forEach((socket) => getFormsAnswers(socket, dispatch)); |
|
|
|
|
|
|
|
// console.log("\n\n========================================================== STATE:\n"+JSON.stringify(state.markers));
|
|
|
|
|
|
|
|
return state; |
|
|
|
} |