From de5ebef457dcc066981c46bc55b405dccf28b2b2 Mon Sep 17 00:00:00 2001 From: natrimmer Date: Wed, 24 Jul 2024 16:07:52 -0700 Subject: [PATCH] Closes #223 [Only accepted features should be included in the download data] --- .../Start/Prediction/EditableGeoJSON.js | 2 + .../Layout/Start/Prediction/Prediction.js | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js index 358a807c..bc696287 100644 --- a/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js +++ b/frontend/src/components/Layout/Start/Prediction/EditableGeoJSON.js @@ -96,6 +96,7 @@ const EditableGeoJSON = ({ trainingId, sourceImagery, refestchFeeedback, + onAcceptFeature, }) => { const onPMCreate = (event) => { console.log("Created"); @@ -258,6 +259,7 @@ const EditableGeoJSON = ({ .querySelector("#rightButton") .addEventListener("click", () => { feature.properties.action = "ACCEPT"; + onAcceptFeature(feature); console.log("popup layer ", layer); // handle submitting feedback mutateSubmitFeedback(layer); diff --git a/frontend/src/components/Layout/Start/Prediction/Prediction.js b/frontend/src/components/Layout/Start/Prediction/Prediction.js index 0716def0..9ee65547 100644 --- a/frontend/src/components/Layout/Start/Prediction/Prediction.js +++ b/frontend/src/components/Layout/Start/Prediction/Prediction.js @@ -85,6 +85,7 @@ const Prediction = () => { const [skewTolerance, setSkewTolerance] = useState(15); const [tolerance, setTolerance] = useState(0.3); const [areaThreshold, setAreaThreshold] = useState(4); + const [acceptedFeatures, setAcceptedFeatures] = useState([]); const fetchData = async () => { setLoading(true); try { @@ -235,6 +236,23 @@ const Prediction = () => { URL.revokeObjectURL(url); }; + const downloadAcceptedFeatures = () => { + if (acceptedFeatures.length === 0) { + return; + } + + const content = JSON.stringify(acceptedFeatures); + const blob = new Blob([content], { type: "application/json" }); + const url = URL.createObjectURL(blob); + + const link = document.createElement("a"); + link.href = url; + link.download = "accepted_predictions.geojson"; + link.click(); + + URL.revokeObjectURL(url); + }; + const { mutate: callPredict, data: returnedpredictions, @@ -297,6 +315,10 @@ const Prediction = () => { return updatedPredictions; }); + const handleAcceptFeature = (feature) => { + setAcceptedFeatures((prev) => [...prev, feature]); + }; + const handleSubmitFeedback = async () => { setFeedbackLoading(true); console.log(predictions.features.length); @@ -565,6 +587,7 @@ const Prediction = () => { refestchFeeedback={() => { refetchFeedback(); }} + onAcceptFeature={handleAcceptFeature} /> )} @@ -813,8 +836,20 @@ const Prediction = () => { size="small" sx={{ mt: 1 }} > - Download as Geojson + Download All Features as Geojson + + {acceptedFeatures.length > 0 && ( + + Download Accepted Features as Geojson + + )} )}