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

Provide access mouse/touch events in continuously-updating interaction handlers #6047

Open
anandthakker opened this issue Jan 24, 2018 · 9 comments
Labels

Comments

@anandthakker
Copy link
Contributor

As a consequence of integrating camera easing into the main render loop (#5743), we've changed (#6005 #6029) the way continuously-updating interaction handlers manage the camera so that, during dragging/scrolling action, we accumulate movement from multiple mouse events between one render frame and the next, and then in each frame, we synchronously update the camera and fire move (and rotate, etc.) events.

Right now, when DragPanHandler, DragRotateHandler, and ScrollZoomHandler fire 'move', etc., they attach the last mouse event as originalEvent, even though multiple mouse events may be responsible for this particular 'move'. Instead, we should either (a) omit originalEvent in these cases, or (b) include an originalEvents array with all of the contributing events.

@mourner
Copy link
Member

mourner commented Jan 25, 2018

One tricky thing to note is that this property was often used for things like stopPropagation, and accumulating events will no longer support the use case because most events will propagate by the time you process them in batch.

@anandthakker
Copy link
Contributor Author

Shoot, good point @mourner. We will need to provide a new way to do that

@anandthakker anandthakker changed the title Fix inaccurately-named originalEvent property on movement events fired by continuously-updating interaction handlers Provide access mouse/touch events in continuously-updating interaction handlers Jan 25, 2018
@anandthakker
Copy link
Contributor Author

Initial ideas for how we can expose a way for users to stopPropagation() on these events:

  1. Add a stopEventPropagation: boolean option to the handler settings. Seems hacky, doesn't allow client code to decide on a per-event basis.
  2. Fire a new type of event --move-input or gesture-received or something -- from within the event listener that carries the incoming event as originalEvent payload. Also seems hacky -- the difficulty of finding a good name suggests that may not be a great design choice.
  3. Allow an onInputEvent: (MouseEvent | TouchEvent) => void callback. Inconsistent with our otherwise event-driven API.

@anandthakker
Copy link
Contributor Author

anandthakker commented Jan 25, 2018

I suppose for 2, we could also re-emit the event under its same name (mousemove, wheel, etc.). (It looks like we specifically avoid doing that right now.)

@jfirebaugh
Copy link
Contributor

this property was often used for things like stopPropagation

Any concrete examples of this? I like to have a firmer idea how widespread/essential this is.

@jfirebaugh
Copy link
Contributor

jfirebaugh commented Feb 16, 2018

My thinking is that we shouldn't try to fix this, and in fact, secondary map events like move should never have an originalEvent property -- only map events that directly correspond to a triggering DOM event should (mousedown, etc.)

The use case of preventing default map handler behavior should be covered by #3290. If there are any other use cases, they should be handled by binding native DOM event handlers and stopping propagation of the DOM event before it even reaches the map code, either by using capture: true or binding via children of the canvas container and stopping the event before it bubbles.

@jfirebaugh
Copy link
Contributor

Studio uses originalEvent only on click and mousemove events, so shouldn't be negatively affected by removing originalEvent from secondary events.

@jfirebaugh
Copy link
Contributor

Thanks to @stepankuzmin to calling my attention to one important use of originalEvent in #6175 -- distinguishing user-initiated camera events so they can be debounced in a Reactive context, a use which we recommend in our blog post.

This case could instead be addressed by reversing the check -- looking for a property that's added to programmatically triggered events with the eventData parameter. For handler-triggered events, I think we could also have add an event property that indicate which handler triggered the camera event.

@anandthakker
Copy link
Contributor Author

Yeah, good point. Maybe something like a cause: property -- for handler-triggered events, this could be { handler: Handler }, and for programmatically-triggered events, it could be set via an option to the camera methods (map.flyTo({ center: ..., cause: /* application-specific payload */))

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

No branches or pull requests

3 participants