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