Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #223 [Only accepted features should be included in the downloa… #263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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