Skip to content

Close context menu when we click the map#235

Merged
easbar merged 17 commits intomasterfrom
close_menu_on_map_clck
Oct 5, 2022
Merged

Close context menu when we click the map#235
easbar merged 17 commits intomasterfrom
close_menu_on_map_clck

Conversation

@easbar
Copy link
Copy Markdown
Member

@easbar easbar commented Oct 5, 2022

Fixes #135.

Apparently all we need to do is add a click handler to the map, but for some reason we cannot call setMenuCoordinate(null) as @karussell figured out in #232.

When I tried to fix the issue here it never worked as expected:

  • After I added the click handler via map.getTargetElement().addEventListener('click', ... the menu closed when clicking the map, but it also just closed when I clicked on one of the menu entries (without any further action)
  • I was then able to fix this with this workaround in Popup.tsx in 43d28bc
  • ... but on iOS the menu would always close when I let go the long press, unless I was long-pressing and dragging
  • When I tried map.on('click'...) instead it worked in the browser even without the change in Popup.tsx, but I had the same dragging issue on iOS again.
  • What does seem to fix it is not calling setMenuCoordinate(null), but why?

@easbar
Copy link
Copy Markdown
Member Author

easbar commented Oct 5, 2022

I checked again:

            map.on('click', () => {
                overlay?.setPosition(undefined)
            })

works on my laptop, but does not work on iOS: When I do the long press the menu opens, but then closes again as soon as I let go, unless I do an additional drag.

            map.getTargetElement().addEventListener('click', () => {
                overlay?.setPosition(undefined)
                setMenuCoordinate(null)
            })

Does not work on my laptop as clicking on one of the menu entries just closes the menu, at least without the workaround in Popup.tsx

            map.getTargetElement().addEventListener('click', () => {
                overlay?.setPosition(undefined)
            })

Seems to work, so we have to set the event listener on the target element and not call setMenuCoordinate(null).

@karussell
Copy link
Copy Markdown
Member

karussell commented Oct 5, 2022

Thanks :) ... what an adventure. A bit sad that openlayers does not come with it out of the box.

but it also just closed when I clicked on one of the menu entries (without any further action)

Interesting. I had this same behaviour for map.on('click'...) :D

Update: works for me too. On desktop and on Android 11 (chrome+firefox).

@easbar
Copy link
Copy Markdown
Member Author

easbar commented Oct 5, 2022

Can you also try this? http://gh-maps-react.s3-website.eu-central-1.amazonaws.com/cleanup_context_menu
Apparently this also works in strict mode (compared to master and the solution here).

However, for this I had to use the 'singleclick' event, to distinguish between clicking and panning the map. This means there is a short, but noticeable delay between the click and closing the menu. But otherwise the menu also closes when when panning the map which I think is not what we want.

@easbar
Copy link
Copy Markdown
Member Author

easbar commented Oct 5, 2022

Anyway, I'll merge this so you can also merge your context menu changes and the above version is maybe something for #216. But just the fact that here something went wrong when we called setMenuCoordinate(null) and that it does not work in strict mode tells me we are still doing something wrong :)

@easbar easbar merged commit 68319ee into master Oct 5, 2022
@easbar easbar deleted the close_menu_on_map_clck branch October 5, 2022 11:48
@karussell
Copy link
Copy Markdown
Member

Can you also try this? http://gh-maps-react.s3-website.eu-central-1.amazonaws.com/cleanup_context_menu

Unfortunately this does not work in chrome and firefox on Android: the menu always closes (with a small delay) after it opened. Except again, when I drag while opening.

But otherwise the menu also closes when when panning the map which I think is not what we want.

To me this isn't that important :)

@easbar
Copy link
Copy Markdown
Member Author

easbar commented Oct 5, 2022

Unfortunately this does not work in chrome and firefox on Android: the menu always closes (with a small delay) after it opened. Except again, when I drag while opening.

sigh :)

To me this isn't that important :)

I feel like I have to move the map every time I open the menu because it is never full visible, so it would be annoying if it closed every time I move the map.

@karussell
Copy link
Copy Markdown
Member

karussell commented Oct 5, 2022

I feel like I have to move the map every time I open the menu because it is never full visible, so it would be annoying if it closed every time I move the map.

With #232 the map moves automatically (again) if not fully visible - or will it close in these cases too?

@easbar
Copy link
Copy Markdown
Member Author

easbar commented Oct 5, 2022

or will it close in these cases too?

Probably not, but let's just try again when it is merged.

karussell added a commit that referenced this pull request Oct 5, 2022
karussell added a commit that referenced this pull request Oct 5, 2022
* reintroduce LongPressHandler for iOS

* comment

* popup menu above cursor is problematic

* try to improve right-click popup

* a bit tighter

* really no close button necessary?

* css style

* hover should be centered

* remove close button, #235
@easbar easbar mentioned this pull request Oct 7, 2022
ZeroGxMax pushed a commit to minhhpkp/graphhopper-maps that referenced this pull request Nov 12, 2024
ZeroGxMax pushed a commit to minhhpkp/graphhopper-maps that referenced this pull request Nov 12, 2024
…hopper#232)

* reintroduce LongPressHandler for iOS

* comment

* popup menu above cursor is problematic

* try to improve right-click popup

* a bit tighter

* really no close button necessary?

* css style

* hover should be centered

* remove close button, graphhopper#235
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.

A left click in the map should close the context menu

2 participants