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

Area selection by ctrl key with mouse for SAM #897

Merged
merged 8 commits into from
Mar 21, 2024
Merged

Conversation

moontrip
Copy link
Contributor

This will address #863. A couple of notes are provided in the following and a video capture is attached in the end:

  • The main area-select is taken from 'leaflet-area-select' library. I couldn't figure out why the lib did not work with our repo, even if it just worked fine with simple react env (after running create-react-app). Thus, I modified the lib and directly loaded it instead of installing (i.e., yarn add).

  • The 'leaflet-area-select' is quite old library and does not have a typescript definition. Since it is not trivial task to type a leaflet-plugin, I just used // @ts-nocheck to ignore typescript (AreaSelect.tsx)

  • After thinking over and trying several cases, the best place to use marker selection logic I found is each marker's MapType (e.g., DonutMarkerMapType, etc.) and a useEffect is utilized to update selectedMarkers. However, since MapType involves conditions (checking errors for marker response, etc.), thus some duplicate codes were utilized inside the useEffect, (markers & selectedMarkers).

  • Overall, it seems to work fine: a video shot is attached in the next

map.area.selection.by.ctrl.key.with.mouse.mp4

@moontrip moontrip requested a review from bobular February 28, 2024 15:19
@moontrip moontrip linked an issue Feb 28, 2024 that may be closed by this pull request
useEffect(() => {
if (!markersData.error && !markersData.isFetching) {
// convert marker data into markers
const markers = markersData.data?.markersData?.map((markerProps) => (
Copy link
Member

Choose a reason for hiding this comment

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

Had a quick look (not tested yet!) and markersData seems missing from the dependencies and there's no need to convert markersData into markers. You can do the bounds check below with markerData instead of markers (so it's data.position.lat instead of marker.props.position.lat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bobular Thank you for your feedbacks 👍 As for markersData-related one, yes it can be simplified so I made a new commit to address them. For the dependency, I checked that markersData-related one causes infinite loop so I didn't add it to the dependency array.

@bobular
Copy link
Member

bobular commented Feb 29, 2024

Hi @moontrip - it looks like Mac command key is going to be a problem for us

w8r/leaflet-area-select#15

@moontrip
Copy link
Contributor Author

Hi @moontrip - it looks like Mac command key is going to be a problem for us

w8r/leaflet-area-select#15

@bobular Thank you for your information 👍 It is quite interesting. I didn't know that as a Windows/Ubuntu user 😅 I will try to find a way, probably next week when I am working for VEuPathDB.

Copy link
Member

@bobular bobular left a 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.

A few things are of concern though.

  1. The installation issues of leaflet-area-select - I haven't investigated but combined with
  2. The lack of Apple Cmd key support I think that
  3. We should consider better maintained alternatives such as https://github.com/Leaflet/Leaflet.draw or https://www.npmjs.com/package/@geoman-io/leaflet-geoman-free
  4. Leaving out essential hook dependencies to avoid loops
  5. I think we can avoid tracking state of boxCoord at MapAnalysis.tsx and repetition of code within the map types and instead deploy a custom hook in each MapType that returns a handler for the selected bounds, and do something like this in DonutMarkerMapType.MapLayerComponent:
  const handleSelectedArea = useAreaSelectedMarkers({
    selectedMarkers,
    setSelectedMarkers,
    markerDataResponse,
  });

  return (
    <>
      {markerDataResponse.isFetching && <Spinner />}
      {markers && (
        <AreaSelect onSelectedArea={handleSelectedArea} />
        <SemanticMarkers
          markers={markers}
          // no changes to any props here
        />
      )}
    </>
  );

We probably want to check markerDataResponse.pending inside the hook and have the handler do nothing if the markers are pending.

@bobular
Copy link
Member

bobular commented Mar 4, 2024

FYI: Stories are fixed with #901 (merged)

@bobular
Copy link
Member

bobular commented Mar 4, 2024

I think for now, all the story needs to do is call the callback which prints the bounds to the console. No need to actually do any marker-selection logic.

@moontrip
Copy link
Contributor Author

moontrip commented Mar 6, 2024

@bobular Thank you for your comments. I didn't have much time to work for VEuPathDB this week as I needed to do other project. I will check your feedbacks carefully, but I could manage to enable Mac's Command key for current area selection. Although I am using Windows/Ubuntu, I could test it works as Window key is essentially the same with Mac's Command key in the key mapping: metaKey.

@bobular
Copy link
Member

bobular commented Mar 8, 2024

Hi @moontrip - I wasn't able to use the windows key on Ubuntu Linux unfortunately. Not without remapping keys in X11 anyway, which I'm not going to do at this point.

Assuming your fix is good, then let's continue with the "hacked (not) import" - I had a closer look and realise it's not interfering with any other Leaflet internals. No need to look at the other libraries (though we might need them one day for polygon/lasso support - though I think I remember you already started looking at that some time ago?)

If you could take the logic out of MapAnalysis and make a hook/handler as suggested, that would be great.

I also wonder if ctrl-rectangle select should add to the marker selection?

@moontrip
Copy link
Contributor Author

moontrip commented Mar 8, 2024

Hi @bobular Thank you for your comments 👍 You can find my reply (if necessary) in the following starting from DK: with bold style.

Hi @moontrip - I wasn't able to use the windows key on Ubuntu Linux unfortunately. Not without remapping keys in X11 anyway, which I'm not going to do at this point.

DK: Actually, I am also using Ubuntu in the VM. Unfortunately, Ubuntu assigned the windows key as a Super key for their purpose, so certainly it cannot be tested under Ubuntu. What I did for test was that I used ngrok, which, in short, delivers traffics from local services to public domain, to open SAM at Windows (my main OS) web browser. Then, I could test windows key in there.

Assuming your fix is good, then let's continue with the "hacked (not) import" - I had a closer look and realise it's not interfering with any other Leaflet internals. No need to look at the other libraries (though we might need them one day for polygon/lasso support - though I think I remember you already started looking at that some time ago?)

DK: Sounds great. Yes IIRC I did look at react-leaflet-draw a couple of years ago. Not quite sure how much it was upgraded since then.

If you could take the logic out of MapAnalysis and make a hook/handler as suggested, that would be great.

DK: I will test it next Monday when I will work for VEuPathDB

I also wonder if ctrl-rectangle select should add to the marker selection?

DK: I'm sorry that I cannot fully understand your question. Can you please elaborate it more?

@bobular
Copy link
Member

bobular commented Mar 8, 2024

I also wonder if ctrl-rectangle select should add to the marker selection?

DK: I'm sorry that I cannot fully understand your question. Can you please elaborate it more?

At the moment, the rectangle selection is replacing the current selected markers. I think it should add the markers in the rectangle to whatever previous selected markers existed (if any).

@moontrip
Copy link
Contributor Author

moontrip commented Mar 8, 2024

@bobular Ah I got your point 👍 I am not quite sure if it is doable due to a couple of reasons, e.g., mouse click event, etc., but I will check

I also wonder if ctrl-rectangle select should add to the marker selection?

DK: I'm sorry that I cannot fully understand your question. Can you please elaborate it more?

At the moment, the rectangle selection is replacing the current selected markers. I think it should add the markers in the rectangle to whatever previous selected markers existed (if any).

@moontrip
Copy link
Contributor Author

@bobular couple of updates are made:

a) Area selection can add markers with pre-existing selected markers
b) Also changed change logic to avoid duplicate markers
c) Made a custom hook to simplify codes: typing and adjusting for different marker responses
d) tested to move area selection to AreaSelect component, but it did not work correctly. So, I will leave it as a future technical debt as it seems not to be trivial

@bobular bobular merged commit 15c0e0a into main Mar 21, 2024
1 check passed
@bobular bobular deleted the 863-area-select branch March 21, 2024 16:14
@bobular
Copy link
Member

bobular commented Mar 21, 2024

Hi @moontrip Looks like these changes got merged when I merged the child PR. Nice.

@moontrip
Copy link
Contributor Author

Hi @moontrip Looks like these changes got merged when I merged the child PR. Nice.

Yes because you branched out from this PR. Thank you for enhancing this work 👍 👍

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.

Map - rectangular marquee marker-selection with Ctrl-drag on map
2 participants