From 69b35a45e5e894a242d8f5fc584f736f68c02ef4 Mon Sep 17 00:00:00 2001 From: GabrielTrettel Date: Tue, 29 Jun 2021 11:53:33 -0300 Subject: [PATCH] Attempt to solve the problem of markers not being updated on the map as data is entered. --- src/app/components/map/LeafLetMap.js | 6 +++++- src/app/components/map/OpenStreetMap.js | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/app/components/map/LeafLetMap.js b/src/app/components/map/LeafLetMap.js index 0276b6c..2560419 100644 --- a/src/app/components/map/LeafLetMap.js +++ b/src/app/components/map/LeafLetMap.js @@ -25,6 +25,10 @@ function goToRegion(mapRef, position) { setCustomView(${position.lat}, ${position.long}, 16.5);`); } +function setViewCode(lat, long, zoom = 16.5) { + return `setCustomView(${lat}, ${long}, ${zoom});`; +} + const code_to_function = { "1": clickCallback, "2": markerCallback, @@ -80,4 +84,4 @@ async function insertMarker(mapRef, ID, coordinate, icon) { }`); } -export { loadHTMLFile, handleEvent, insertMarker, goToRegion }; +export { loadHTMLFile, handleEvent, insertMarker, goToRegion, setViewCode }; diff --git a/src/app/components/map/OpenStreetMap.js b/src/app/components/map/OpenStreetMap.js index 597f6b5..6bad4b2 100644 --- a/src/app/components/map/OpenStreetMap.js +++ b/src/app/components/map/OpenStreetMap.js @@ -2,13 +2,11 @@ import React, { useState, useEffect } from "react"; import { View, StyleSheet, Text } from "react-native"; import WebView from "react-native-webview"; import { - loadHTMLFile, + setViewCode, handleEvent, insertMarker, - goToRegion, } from "./LeafLetMap"; import MapModal from "../MapModal"; -import { useLocation, getLocation } from "../../hooks/useLocation"; import html_content from "./Map.js"; @@ -43,14 +41,10 @@ export default function OpenStreetMap({ moveEndListener, }) { const [mapRef, setMapRef] = useState(null); - // const [webviewContent, setWebviewContent] = useState(null); const webviewContent = html_content; const [markerListener, setMarkerListener] = useState(null); + const viewFunction = setViewCode(global.location.lat, global.location.long); - const viewFunction = `\ - setCustomView(${global.location.lat}, ${global.location.long}, 16.5);`; - - console.log(global.location); markersList && mapRef && notEmpy(markersList) && @@ -58,9 +52,14 @@ export default function OpenStreetMap({ insertMarker(mapRef, val.ID, val.coordinate, val.image); }); - // loadHTMLFile() - // .then((html) => setWebviewContent(html)) - // .catch((e) => console.warn(e)); + useEffect(() => { + markersList && + mapRef && + notEmpy(markersList) && + markersList.forEach((val, key) => { + insertMarker(mapRef, val.ID, val.coordinate, val.image); + }); + }, [markersList]) return (