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){ //TODO } 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: response.fias[0].fieldsanswersvalue ? response.fias[0].fieldsanswersvalue : "", //response.fieldsanswerssituation address: response.fias[1].fieldsanswersvalue ? response.fias[1].fieldsanswersvalue : "",//response.fieldsanswerseventaddress, coordinate: { coordinate }, date: response.fias[2].fieldsanswersvalue + " | " + response.fias[3].fieldsanswersvalue, //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime, description: response.fias[4].fieldsanswersvalue, //response.fielsanswercomment, image: "",//getMarkerImage(answer.name), } markers.set(polygonObject.ID, polygonObject); } function buildMarkerObject(markers, response, name) { var markerObject = { ID: response.formsanswersid, name: name, title: response.fias[0].fieldsanswersvalue ? response.fias[0].fieldsanswersvalue : "", //response.fieldsanswerssituation address: response.fias[1].fieldsanswersvalue ? response.fias[1].fieldsanswersvalue : "",//response.fieldsanswerseventaddress, coordinate: { latitude: response.formsanswerslatitude, longitude: response.formsanswerslongitude, }, date: response.fias[2].fieldsanswersvalue + " | " + response.fias[3].fieldsanswersvalue, //response.fieldsanswerseventdate + " | " + response.fieldsanswerseventtime, description: response.fias[4].fieldsanswersvalue, //response.fielsanswercomment, image: custom_assets_pin.pluviometer,//getMarkerImage(answer.name), } markers.set(markerObject.ID, markerObject); } function verifyResponse(markers, data) { // console.log(data.response); if (data.response) { 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) => { var markers = { markers: new Map() }; const answers = SocketClient(dataOptionObject, focusChanged); // console.log("\n\nAnswers: " + JSON.stringify(answers)); answers.forms.forEach((r) => verifyResponse(markers, r));//buildMarkerObject(markers.markers, r)); //console.log("\n\nMarkers: " + JSON.stringify(markers)); return markers; } export { getFormsAnswers };