diff --git a/front-end/components/Editmap.js b/front-end/components/Editmap.js index 88e8ea7..3fcb98c 100755 --- a/front-end/components/Editmap.js +++ b/front-end/components/Editmap.js @@ -15,7 +15,6 @@ import SmallLoadingEffect from "./SmallLoadingEffect"; import { useRouter } from "next/router"; import Swal from 'sweetalert2'; import { backend_url } from "../utils/settings"; -import SelectedPointsContext from "../contexts/SelectedPointsContext"; import SelectedPolygonContext from "../contexts/SelectedPolygonContext"; import SelectedPolygonAreaContext from "../contexts/SelectedPolygonAreaContext.js"; import { useFolder } from "../contexts/FolderContext.js"; @@ -51,7 +50,6 @@ function Editmap() { const selectedPolygonsRef = useRef([]); const selectedSingleMarkersRef = useRef([]); - const { selectedPoints, setSelectedPoints } = useContext(SelectedPointsContext); const { selectedPolygons, setSelectedPolygons } = useContext(SelectedPolygonContext); const { selectedPolygonsArea, setSelectedPolygonsArea } = useContext(SelectedPolygonAreaContext); @@ -221,7 +219,6 @@ function Editmap() { map.current.on("draw.create", (event) => { const polygon = event.features[0]; - console.log(polygon); // Convert drawn polygon to turf polygon const turfPolygon = turf.polygon(polygon.geometry.coordinates); @@ -272,71 +269,8 @@ function Editmap() { content += `

${property}: ${featureProperties[property]}

`; } - const currentFeatureState = map.current.getFeatureState({ - source: "custom", - sourceLayer: "data", - id: featureId, - }); - - if (currentFeatureState.served) { - content += ''; - } else { - content += ''; - } - popup.setHTML(content); - document.getElementById('toggleServe')?.addEventListener('click', function () { - // Toggle the 'served' property - const toggleRes = !currentFeatureState.served; - console.log(toggleRes); - - // Update feature state - map.current.setFeatureState( - { - source: "custom", - sourceLayer: "data", - id: featureId, - }, - { served: toggleRes } - ); - - if (toggleRes) { - // Check if the point exists in selectedSingleMarkersRef - const pointExistsInMarkers = selectedSingleMarkersRef.current.some(location => location.id === featureId); - - if (pointExistsInMarkers) { - // Remove the point from selectedSingleMarkersRef - selectedSingleMarkersRef.current = selectedSingleMarkersRef.current.filter( - location => location.id !== featureId - ); - setSelectedPoints(selectedSingleMarkersRef.current); - } else { - // Remove the point from selectedPolygonRef - selectedPolygonsRef.current = selectedPolygonsRef.current.map(polygon => { - // Remove the point if it exists in this polygon - return polygon.filter(location => location.id !== featureId); - }); - setSelectedPolygons(selectedPolygonsRef.current); - } - } else { - // Add the point to selectedSingleMarkersRef when serving - const locationInfo = { - id: featureId, - latitude: featureCoordinates[1], - longitude: featureCoordinates[0], - address: featureProperties.address, - served: toggleRes - }; - selectedSingleMarkersRef.current.push(locationInfo); - setSelectedPoints(selectedSingleMarkersRef.current); - } - - - - // Update the popup content to reflect changes - updatePopup(); - }); } // Initial popup content setup @@ -349,30 +283,6 @@ function Editmap() { }; - useEffect(() => { - // Loop through the current ref list - selectedSingleMarkersRef.current.forEach((marker) => { - // Check if the marker is not in the selectedPoints - if (!selectedPoints.some(point => point.id === marker.id)) { - marker.served = true; - // If it's not in selectedPoints, set served back to true - map.current.setFeatureState( - { - source: "custom", - sourceLayer: "data", - id: marker.id, - }, - { - served: true, - } - ); - } - }); - - // Sync ref with the current state - selectedSingleMarkersRef.current = [...selectedPoints]; - - }, [selectedPoints]); // Dependency on selectedPoints useEffect(() => { // Loop through each polygon in selectedPolygonsRef @@ -542,6 +452,7 @@ function Editmap() { latitude: item.latitude, longitude: item.longitude, served: item.served, + coveredBy: item.coveredLocations })); setFeatureStateForMarkers(newMarkers); diff --git a/front-end/components/MyEdit.js b/front-end/components/MyEdit.js index 67b06a2..b40b1ca 100644 --- a/front-end/components/MyEdit.js +++ b/front-end/components/MyEdit.js @@ -23,7 +23,6 @@ import SelectedLocationContext from "../contexts/SelectedLocationContext"; import LocationOnIcon from '@mui/icons-material/LocationOn'; import { backend_url } from "../utils/settings"; import UndoIcon from '@mui/icons-material/Undo'; -import SelectedPointsContext from "../contexts/SelectedPointsContext"; import SelectedPolygonContext from "../contexts/SelectedPolygonContext"; import SelectedPolygonAreaContext from "../contexts/SelectedPolygonAreaContext.js"; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; @@ -66,7 +65,6 @@ const MyEdit = () => { const loadingTimeInMs = 3.5 * 60 * 1000; const { setLocation } = useContext(SelectedLocationContext); - const { selectedPoints, setSelectedPoints } = useContext(SelectedPointsContext); const { selectedPolygons, setSelectedPolygons } = useContext(SelectedPolygonContext); const { selectedPolygonsArea, setSelectedPolygonsArea } = useContext(SelectedPolygonAreaContext); @@ -86,12 +84,6 @@ const MyEdit = () => { } } - const handleUndoSingleEdit = (index) => { - // Create a new array without the item at the given index - const updatedPoints = [...selectedPoints]; - updatedPoints.splice(index, 1); - setSelectedPoints(updatedPoints); - }; const handleUndoPolygonEdit = (index) => { const updatedPolygons = [...selectedPolygons]; @@ -144,14 +136,9 @@ const MyEdit = () => { polygon.slice(1) // Skip the first element (timestamp) and take the rest (points) ); - // Merge points from selectedPoints and polygonPoints - const combinedPoints = [...selectedPoints, ...polygonPoints].map((point) => ({ - id: point.id, - served: point.served, - })); const requestBody = { - marker: combinedPoints, + marker: polygonPoints, polygonfeatures: selectedPolygonsArea, folderid: folderID }; @@ -224,11 +211,6 @@ const MyEdit = () => { handleLocateOnMap={handleLocateOnMap} handleUndoSinglePointWithinPolygon={handleUndoSinglePointWithinPolygon} /> -