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

Allow user to upload reference images #60

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

mstone121
Copy link
Contributor

@mstone121 mstone121 commented Sep 7, 2022

Overview

This PR adds the ability for the user to upload their own images. These images will appear as toggleable reference layers in the sidebar.

Closes #54

Demo

Screen.Recording.2022-09-07.at.5.00.04.PM.mov

Notes

This PR updates the ReferenceLayer component to store the individual reference image layers in a mutable react ref. This cuts down on the number of times these layers are re-created; a high number of re-creations has caused unpredictable behavior.

I first tried using L.DistortableImage's distortableCollection to store multiple distortable layers, but this would make the reference images uneditable.

As is evident in the demo video above, if the file names are long, they are cutoff by the end of the sidebar. This should be addressed especially as reference images may come in sets with files that begin with the same prefix (e.g. see demo).

Testing Instructions

  • Go to Welcome page
  • Navigate to last section, File Upload
  • Upload some image files
  • Click Continue
  • The images should show up as reference layers on the map
  • Click the "Upload File" button to add more reference layers
  • See that they show up on the map as well
  • Ensure all layers are toggleable and editable and that they are saving correctly when toggled

Checklist

  • fixup! commits have been squashed
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines
  • README.md updated if necessary to reflect the changes
  • CI passes after rebase

Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! The one issue I've been having is with PDF files. When I select them, they do show up in the list on the sidebar, but not on the map. Are you seeing this on your end as well? Or do I just have bad PDFs?

I would recommend investigating that for a bit, but if it ends up being too complex we should defer it to a follow up card.

src/app/src/components/Layers/ReferenceImageLayer.js Outdated Show resolved Hide resolved
const imageShouldBeAdded = url =>
!(url in referenceImageLayers.current);

const imageShouldBeHidden = url => !(url in visibleImages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of in


const imageShouldBeHidden = url => !(url in visibleImages);

for (const [url, { corners, mode }] of Object.entries(visibleImages)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of for ... of

state.referenceImage = { ...state.referenceImage, ...update };
updateReferenceImage: (state, { payload: { url, update } }) => {
state.referenceImages[url] = {
...(state.referenceImages?.[url] ?? {}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of optional chaining and null coalescing

src/app/src/components/Layers/ReferenceImageLayer.js Outdated Show resolved Hide resolved
@mstone121
Copy link
Contributor Author

The one issue I've been having is with PDF files.

I forgot to test this. I just tried now and it's not working for me either. I don't think DistortableImage supports using PDFs. I think we have a couple of options here:

It seems like it should be possible to convert the PDF to an image with Mozilla's PDF.js. I checked the npmjs page for the distributable, pdfjs-dist, and the unpacked size is 34.7 MB (yes, MB). The package is available from a CDN, but users would still need to download the full library.

The other option would be to add a route to the django server to convert pdfs and send back images. This adds complexity to the pdf upload process, but also doesn't require the user to download any additional libraries.

@rajadain rajadain mentioned this pull request Sep 12, 2022
@rajadain
Copy link
Contributor

Nice investigation. I made #62 for adding PDF support in a follow up card. We can prioritize it later. Going to give this a final look.

@rajadain
Copy link
Contributor

For the long file names that are cutoff, let's add a native tooltip on hover which shows the full file name for now.

Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 tested, this looks really good. Even tried uploading the same file twice, and the sidebar, despite having two same named files, did not get confused between them.

Let's add a tooltip for the long file names here, and then this will be ready to go.

Please hold off on merging until after the client demo ends at 1pm.

@mstone121
Copy link
Contributor Author

mstone121 commented Sep 12, 2022

PDF removed as a accepted file type in d883110. @rajadain Should I also remove it from the list here? We're still showing shape files as a possible upload type despite not having this functionality yet.

I added a tooltip in e302948.

@rajadain
Copy link
Contributor

Taking another look

Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 tested, tooltips look good:

image

Let's also remove PDF from the welcome modal for now, and add it back in #62.

@mstone121
Copy link
Contributor Author

ba7215e removes Progress import and PDF from accepted files. I also removed tiff because it does not work.

@mstone121 mstone121 assigned rajadain and mstone121 and unassigned mstone121 and rajadain Sep 14, 2022
This commit updates the ReferenceLayer component to store the individual
reference image layers in a mutable react ref. This cuts down on the
number of times these layers are re-created; a high number of
re-creations has caused unpredictable behavior. I first tried using
L.DistortableImage's distortableCollection, but this would make the
reference images uneditable.
@mstone121 mstone121 merged commit 2c5cbd2 into develop Sep 14, 2022
@mstone121 mstone121 deleted the ms/implement-user-image-upload branch September 14, 2022 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow User Uploaded Reference Image
2 participants