Skip to content

Commit

Permalink
Merge pull request #263 from natrimmer/223-only-accepted-features-dow…
Browse files Browse the repository at this point in the history
…nload

Closes #223 [Only accepted features should be included in the downloa…
  • Loading branch information
kshitijrajsharma authored Sep 3, 2024
2 parents 1aa818c + de5ebef commit e26018a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const EditableGeoJSON = ({
trainingId,
sourceImagery,
refestchFeeedback,
onAcceptFeature,
}) => {
const onPMCreate = (event) => {
console.log("Created");
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 36 additions & 1 deletion frontend/src/components/Layout/Start/Prediction/Prediction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -565,6 +587,7 @@ const Prediction = () => {
refestchFeeedback={() => {
refetchFeedback();
}}
onAcceptFeature={handleAcceptFeature}
/>
)}
</FeatureGroup>
Expand Down Expand Up @@ -813,8 +836,20 @@ const Prediction = () => {
size="small"
sx={{ mt: 1 }}
>
Download as Geojson
Download All Features as Geojson
</LoadingButton>

{acceptedFeatures.length > 0 && (
<LoadingButton
variant="contained"
onClick={downloadAcceptedFeatures}
color="secondary"
size="small"
sx={{ mt: 1 }}
>
Download Accepted Features as Geojson
</LoadingButton>
)}
</Paper>
)}
</Grid>
Expand Down

0 comments on commit e26018a

Please sign in to comment.