-
Notifications
You must be signed in to change notification settings - Fork 286
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
added a save button to export JSON saved state of images #1161
Conversation
@jywarren Kindly review and leave corrections, thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start, thank you! I made a bunch of suggestions. Thanks a lot!
examples/archive.html
Outdated
placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button'); | ||
placeButton.innerHTML = 'Place on map'; | ||
|
||
let imageGroup = L.distortableCollection().addTo(map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I'm not sure if we have to add it to the map - i think images will be added to the map when the user clicks "Place", right? Maybe we leave out addTo(map)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve also made this change
examples/archive.html
Outdated
imageRow.classList.add('d-flex', 'justify-content-between', 'align-items-center', 'mb-4', 'pe-5'); | ||
imageRow.append(image, placeButton); | ||
|
||
imageArray.push[image] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this only when the user presses the Place button? Maybe in the click handler down on line 141? https://github.com/publiclab/Leaflet.DistortableImage/pull/1161/files#diff-4e935909ea43d3a9c21496afdeae5865a74c6d7ee77640cf467b6e3911b6c63dL141
examples/archive.html
Outdated
imageContainer.appendChild(imageRow); | ||
imageCount++; | ||
|
||
for(let i=0; i<imageArray.length;i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And likewise, here maybe we don't need to iterate with a for loop - we can just run imageGroup.addLayer(image[i])
down on line 141 when the user clicks "Place" -- does that make sense?
examples/archive.html
Outdated
@@ -65,13 +67,18 @@ <h3 id="offcanvasRightLabel">Images</h3> | |||
</body> | |||
|
|||
<script> | |||
let map; | |||
let map = L.map('map').setView([51.505, -0.09], 13); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I think this may be redundant with line 84, no?
examples/archive.html
Outdated
@@ -11,6 +11,8 @@ | |||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | |||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | |||
|
|||
<script src="../src/DistortableCollection.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I am not sure we need this or the next line in this PR, maybe these are left over from another pull request? Yes - it looks like you are making a PR from your main
branch, so this can happen. It's OK as long as you remove these lines now, but in the future you can avoid this by working in a named branch for each new feature, instead of in your main branch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hii @jywarren
I’ve made all the required changes and the script I added was for the generateExportJson() so the function could be passed down
And yes yes, next time I’d work on a different branch
Thank youu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, so what will happen is if you compile the code (I believe it's grunt build
?) It will automatically include all files in the src directory into the files in /dist/, so you don't need to separately do this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, actually it's "npm run build" as shown here: https://github.com/publiclab/Leaflet.DistortableImage/blob/main/CONTRIBUTING.md#setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh
Alright
I didn’t know that
Thank youu
Let me make the correction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thank youu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script tag below it is for the font awesome icon on the button.
The save icon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a bunch of suggested changes; see what you think! If they make sense, you can commit them, or ask questions!
I also want to admit that I'm not 100% sure this will work. We'll have to try it out to see. It could be that we actually have to wait until the last moment to add them all to the collection, instead of adding them as we go? But let's try getting this attempt running first and we'll be able to see when we try it out.
Thanks!
examples/archive.html
Outdated
@@ -146,6 +156,8 @@ <h3 id="offcanvasRightLabel">Images</h3> | |||
let imageURL = event.target.previousElementSibling.src; | |||
let image = L.distortableImageOverlay(imageURL); | |||
map.imgGroup.addLayer(image); | |||
placedImagesArray.push[image] | |||
imageGroup.addLayer(image[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, i think we can just say image
and not image[i]
anymore, since we aren't in a for loop anymore.
imageGroup.addLayer(image[i]) | |
placedImagesCollection.addLayer(image) |
examples/archive.html
Outdated
@@ -137,6 +145,8 @@ <h3 id="offcanvasRightLabel">Images</h3> | |||
}); | |||
}); | |||
|
|||
saveButton.addEventListener('click',generateExportJson(imageGroup)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very close here! I think we will want to run it like this:
saveButton.addEventListener('click',generateExportJson(imageGroup)) | |
saveButton.addEventListener('click', function() { | |
alert(placedImagesCollection.generateExportJson()); // we'll do something better than alert in the next PR | |
} |
examples/archive.html
Outdated
@@ -72,6 +73,12 @@ <h3 id="offcanvasRightLabel">Images</h3> | |||
let input = document.getElementById('input'); | |||
let responseText = document.getElementById('response'); | |||
let imageContainer = document.getElementById('imgContainer'); | |||
let imageGroup = L.distortableCollection().addTo(map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this "placedImagesCollection" and remove the addTo(map)
!
let imageGroup = L.distortableCollection().addTo(map) | |
let placedImagesCollection = L.distortableCollection() |
examples/archive.html
Outdated
@@ -114,14 +121,15 @@ <h3 id="offcanvasRightLabel">Images</h3> | |||
|
|||
placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button'); | |||
placeButton.innerHTML = 'Place on map'; | |||
|
|||
let imageGroup = L.distortableCollection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we shouldn't have to declare this a second time. Let's remove it!
let imageGroup = L.distortableCollection() |
@jywarren |
This looks great! Thank you for all the changes. Are you able to test it out and upload a video? I'm trying to right now but my connection isn't very good. |
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
To test it, I navigate to /examples/archive.html from the root URL it's already at. |
Thank youu |
Just repeating here: OK, so what I found was that, for some reason, this doesn't work... the images array is empty. But! I also found that we actually already have an distortableImageCollection in this page -- on line 96! So on this line, we can do: alert(JSON.stringify(map.imgGroup.generateExportJson())); // we'll do something better than alert in the next PR And we can also remove the lines on 76 and 77, since we are just going to use the Collection that's already defined in the page. What do you think? |
Hmm. I can't seem to get this to work... it did work for a moment, but I'm not sure what I had changed. Aha! Since there's a check on line 197: Leaflet.DistortableImage/src/DistortableCollection.js Lines 192 to 197 in c80a7c6
...for whether the images have been selected, we actually have to go through and select the images. Hmm, how do we do that? |
Can we just add the "selected" class? We need to research how this is
supposed to be done.
…On Wed, Oct 19, 2022, 10:07 AM Leila Yesufu ***@***.***> wrote:
Thank youu
—
Reply to this email directly, view it on GitHub
<#1161 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J45BR66SJJA3S4UNODWD76A7ANCNFSM6AAAAAARFT547Y>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hii @jywarren |
Also about the line 197 |
Hi @leilayesufu i wonder... what if we make a parameter for |
Hii @jywarren |
Thank you! Yes i had some big work commitments the past week but am catching up now! |
Just noting that I've linked here from #1225 (comment) where there was a parallel effort also requiring this modified |
Solved in #1237, thank you!!! |
Fixes #1139
i created a button in the archive.html, then i used font awesome to add a save icon in it and added it to the sidebar, then i created an array to push every image in, i then put added all the image to a collection then i ran the generateExportJson() on the collection
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
grunt test
If tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Thanks!