react-google-maps icon indicating copy to clipboard operation
react-google-maps copied to clipboard

[Bug] AdvancedMarker onDragEnd event triggers Map's onClick event

Open JosuerBague opened this issue 1 year ago • 3 comments

Description

I have a Map instance with an onClick that sets the position of a marker to the latLng of the clicked position.

This marker is draggable, and onDragEnd shows an InfoWindow with the new position. The problem is that when onDragEnd ends the Map's onClick event fires. Both onClick and onDragEnd sets the position, but since they have a small difference this leads to the marker to jump to a close (but not exactly intended) position.

I expected the onClick event to not fire when AdvancedMarker onDragEnd fires.

Steps to Reproduce

Code SandBox: SandBox

Steps:

  1. Open console
  2. Click on map to relocate marker
  3. Drag marker, pay attention to console.
  4. Drag map.
  5. Drag marker again, pay attention to console

Environment

  • Library version: @vis.gl/[email protected]
  • Google maps version: weekly
  • Browser and Version: 127.0
  • OS: Windows 11

Logs

No response

JosuerBague avatar Jun 17 '24 15:06 JosuerBague

I think this behavior at least matches the behavior of the maps API itself. Not sure right now what can be done about it, but I will have a look.

usefulthink avatar Jun 19 '24 07:06 usefulthink

I just ran into that same issue with a routes/directions feature. The onClick will add a marker, when there are 2 markers the directions service is kicked off. But when there is only 1 marker, and it is dragged, the onDragEnd updates marker 1 AND adds a second marker as the map onClick is fired.

The ugly workaround I'm using now is setting a isDragEvent ref true when the onDragEnd fires, and then in the onClick ignoring the event if the ref is true, and then setting it false. Don't love it but if this is how the maps api works don't see it getting "fixed" anytime soon.

benjaminsinaiko avatar Jun 21 '24 04:06 benjaminsinaiko

@benjaminsinaiko I'll try and give it a go. Thanks for the suggestion.

JosuerBague avatar Jun 24 '24 07:06 JosuerBague