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

Multiple Image Select #158

Merged
merged 63 commits into from
Mar 30, 2019
Merged

Conversation

sashadev-sky
Copy link
Member

@sashadev-sky sashadev-sky commented Feb 26, 2019

references #29, #30, #172, #85, #168, #166, #126, publiclab/mapknitter#60

In this PR:

  • extended L.FeatureGroup to create a new class L.DistortableCollection that holds logic and state for a collection of selected images.

    • for an image to be part of this collection (gaining its UI and functionality) must add it as a layer to the featureGroup
  • created L.Map.BoxSelectHandle to override and extend the default L.Map.BoxZoom setting to zoom into the page by holding down shift and dragging. Instead the L.DistortableCollection class now listens for zoomend event and selects any image with any corner inside the zoombox bounds, passed from L.Map.BoxSelectHandle. Has issues with event propagation, commented out event listener for now

  • deselction and selection

    • on map click: deselect all images, hide toolbars
    • esc key deselects all images and hides toolbars
    • cmd + click on an already selected image toggles selection
      - shift + drag selects all images in the bounding box (most accurate if drag from lower right to upper left and must drag over image corners) (part of commented out event)
    • Resolved: must click images first to select before dragging must click images first to select before dragging #30
    • locked images don't appear as selectable and won't update positions with the rest of the images but the collection class will still keep track of them for the exporter
    • added tests in test/src/DistortableCollectionSpec.js for selection / deselection of locked images
  • image manipulation functionalities:

    • translate. Dragging one image will apply the translations to all other selected images.
  • misc. bugs

  • updates to README

pending: -- these will probably be new issues

@jywarren
Copy link
Member

Wow, this is impressive... how far along is it? I see it clearly relating to publiclab/mapknitter#326 where it'll allow us to initiate an export based on the selected set of images. Great!!!

@sashadev-sky
Copy link
Member Author

@jywarren It's just in initial stage to return an array of all images on the screen since that was mentioned in the original issue. I just wrote over the leaflet source code to change the functionality. I will be adding status updates in the PR description box!

@sashadev-sky
Copy link
Member Author

@jywarren I think I am stuck here. This is what I have done so far:

https://github.com/sashadev-sky/PL-notes/blob/master/giphy.gif

Sorry it is blurry! Basically the zoombox makes it so that the images move into a div element inside the overlay pane. From there, any css transformations applied onto the div effects both elements. The transformations are easy to apply in chrome dev tools in the browser, but when I started actually trying to connect the div to the current distortableImage code I realized I am not sure how to do that. My plan was to move images in there and then when the user is done editing multiple images (or selects different ones), move them out.

@rexagod

@jywarren
Copy link
Member

jywarren commented Mar 12, 2019 via email

@jywarren
Copy link
Member

jywarren commented Mar 12, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren I was thinking of translation as a subset of transform and that is the part I am stuck on. I definitely think they should be moved into a leaflet layer, I was using the div initially to check it works in dev tools and then tried creating a new layer. I couldn't get it working and I think that's just because I am still learning how to use and extend Leaflet. I was trying to create a DistortableImagesOverlay.js file that mimics DistorableImageOverlay.js and then I realized that doesn't make sense because the div is not an image. Where do you suggest I should start? Thank you!

@jywarren
Copy link
Member

jywarren commented Mar 12, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren Under the hood it is all just CSS transformations. Ok I looked at a lot of resources today but I was all over the place because I started second guessing the entire implementation a little. If you agree with this implementation I will continue with it and narrow down my search to your suggestions! This should be a new layer, as in extending L.Layer?

@jywarren
Copy link
Member

jywarren commented Mar 12, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren got it thank you!

examples/select.html Outdated Show resolved Hide resolved
@jywarren
Copy link
Member

I wonder if it's at all useful to think of making a Draggable object using the Leaflet API, to contain and update the whole collection?

https://leafletjs.com/reference-1.4.0.html#draggable

In any case, I am starting to think we want to make a new class, like L.Collection, which can contain any number of items, and manage its internal state. Something like the DistortableImage class itself: https://github.com/publiclab/Leaflet.DistortableImage/blob/master/src/DistortableImageOverlay.js

Oh! Could we use FeatureGroup? https://leafletjs.com/reference-1.4.0.html#featuregroup

@sashadev-sky
Copy link
Member Author

@jywarren Yeah I will consider all of those. I have been reading through the documentation trying to figure out what is most appropriate. For Feature Group I was considering that one but I made a feature group to see how it works and it doesn't seem to create a new layer to group them all into or anything. It just allows you to set things like styling properties on one element that will be applied to all of the elements in the group.

@jywarren
Copy link
Member

jywarren commented Mar 15, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren
test

@sashadev-sky
Copy link
Member Author

@jywarren
test2

@jywarren
Copy link
Member

This is awesome - so what's the current mechanism to select, exactly? How you go into "selection mode" so to speak? Thank you!

@jywarren jywarren requested a review from rexagod March 19, 2019 19:31
@jywarren
Copy link
Member

Looking to the next step, can we add to the README explaining some of this briefly, (esp the architecture a bit and how to initiate selection) and also, a small thing but can we make the selection color yellow and 0.5 opacity?

This is SUPER exciting!!!! Thanks @sashadev-sky !!!

@sashadev-sky
Copy link
Member Author

@jywarren The images currently have a reference to L.DistortableCollection passed in through a group option on their overlay, which allows them to call methods from that class. I want to remove this but the code's required loading order is map -> image overlays -> images editing (which only loads on 'load' - triggered by adding to map) -> add the overlays to the collection dynamically (and removes them from map) using logic in their own class and L.DistortableCollection. It works fine but its not encapsulated so trying to fix it!

For selection -- yes will change to yellow. Those lines are not Polylines yet, but I think that should go in a separate PR.

For README I will push these changes in this PR once everything is done

@sashadev-sky sashadev-sky force-pushed the multiple_image_select branch from d9c8e2d to 44d7ed1 Compare March 23, 2019 10:39
@sashadev-sky
Copy link
Member Author

@jywarren Ok let me know what you think now!
test2

@jywarren
Copy link
Member

It works now with the corner handles appearing in select.html! However, i don't see them working on /examples/index.html -- can you take a look? Thanks for all this tremendous work, @sashadev-sky !!!

@jywarren
Copy link
Member

oh lol i was just testing it 😄 It's incredible Sasha!!!

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This will be so great. One thing we'll be able to do is that DistortableCollection can can have the correct-formatted json file generated from it, as required by our exporter services:

publiclab/mapknitter#326 (comment)

And broken down: publiclab/mapknitter-exporter-sinatra#1 (comment)

It should be able to produce a JSON file to POST up to the exporter, like the one we reference here:

publiclab/mapknitter-exporter-sinatra#1 (comment)

examples/select.html Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@sashadev-sky
Copy link
Member Author

@jywarren Oh it is because I forgot to add it to the featureGroup. Is it okay if the featureGroup is required for the functionality of the plugin, or did you want to keep it optional for people with only one image?

I can either add the image to the group or change a few things around to make DistortableImage.Edit work on its own with all of the UI updates here

@jywarren
Copy link
Member

Hmm, I suppose we better make it optional, or we introduce a breaking change -- isn't that right?

Sorry Sasha, i know you must be eager to get this merged! Thank you!

@sashadev-sky
Copy link
Member Author

@jywarren True! Ok no problem!

@sashadev-sky
Copy link
Member Author

sashadev-sky commented Mar 30, 2019

@jywarren Ok index.html now has markers and all of the UI / small functionality updates too (deselect on map click / esc key)

-- by that I just mean they are available without the featureGroup too

@jywarren
Copy link
Member

Looking really good. I found a few small issues but they aren't necessarily tied to your code, and can be fixed in follow-up:

  1. when an image is in distort mode, and i press r to switch to rotate, then click on it, I don't get a popup menu anymore, although if I then press r again, it seems to get de-selected (no handles) and then when i click on it again, i get a menu (which is to say it's odd but not a blocking bug). Perhaps we could write a test for this scenario?
  2. when i zoom out and in again, the image briefly flickers to an incorrect distortion, which is odd but again not blocking:

image

So, I think this can be merged and we can address these (and any others we find) in follow-up, what do you think?

@jywarren jywarren self-requested a review March 30, 2019 16:01
@@ -20,6 +20,10 @@ describe("L.RotateAndScaleHandle", function() {
});
});

it.skip("Should not distort the image during scaling", function () {
Copy link
Member

@rexagod rexagod Mar 30, 2019

Choose a reason for hiding this comment

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

We can add a test for this, I guess in a seperate issue? This is some amazing work @sashadev-sky! 🙌

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you that's so nice!! yes but I'm not sure it should fully pass yet. because the image size passed in for edgeMinWidth is hardcoded, and the person can make edits to the image and change the shape and then scale. It would be a whole separate issue to work on for sure

@jywarren jywarren merged commit 88fe928 into publiclab:main Mar 30, 2019
@jywarren
Copy link
Member

🎉🎉🎉🙌🏽

@sashadev-sky
Copy link
Member Author

@jywarren Should I save a draft for a new release for this version bump? Are there any specific guidelines I should follow to do that for this repo?

@jywarren
Copy link
Member

jywarren commented Apr 6, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren Oh so repositories that use Bower typically post updated releases on Github and bower pulls in the latest release? Vs with Yarn we would stop publishing releases here and publish on NPM instead?

Just wondering as I am new to this and want to learn!

@jywarren
Copy link
Member

jywarren commented Apr 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Planning issue for next major release of LDI images distort while scaling Rotate and Scale Handle issues
3 participants