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

Wheel events don`t set originalEvent #5884

Closed
2 tasks done
rshadow opened this issue Oct 27, 2017 · 8 comments
Closed
2 tasks done

Wheel events don`t set originalEvent #5884

rshadow opened this issue Oct 27, 2017 · 8 comments

Comments

@rshadow
Copy link

rshadow commented Oct 27, 2017

How to reproduce

  • Leaflet version I'm using: 1.2.0
  • Browser (with version) I'm using: Firefox 57
  • OS/Platform (with version) I'm using: Debian GNU Linux
  • Add listeners on zoom and move events
  • Scroll mouse whell on map
  • See event object in browser debugger

What behaviour I'm expecting and which behaviour I'm seeing

I expect event.originalEvent field filled of original event object. But it`s missing.

Minimal example reproducing the issue

var m = L.map(...);        
m.addEventListener('zoom', function(event){
    // 'zoom', Object, undefined
    console.debug('zoom', event, event.originalEvent);
});
m.addEventListener('move', function(event){
    // 'move', Object, undefined
    console.debug('move', event, event.originalEvent);
});
  • this example is as simple as possible
  • this example does not rely on any third party code
@rshadow
Copy link
Author

rshadow commented Oct 27, 2017

I want to separate events made by the user from internal events. For example, raise fitBounds when receive new data (markers, tracks, etc.). But if the user himself moved the map, then do not automatically raise fitBounds.

@IvanSanchez
Copy link
Member

This is behaviour as expected.

If you read http://leafletjs.com/reference-1.2.0.html#event-objects carefully, you'll see that only KeyboardEvent and MouseEvent implement the originalEvent property. Check the list of map events at http://leafletjs.com/reference-1.2.0.html#map-event to see that zoom and move are neither a KeyboardEvent nor a MouseEvent.

@IvanSanchez
Copy link
Member

As a feature request, this could be considered a duplicate of #2934 , so no reason to keep this open.

@rshadow
Copy link
Author

rshadow commented Oct 27, 2017

So. Leaflet use mousewhell events but it is not MouseEvent. Maybe need write issue for this?

@rshadow
Copy link
Author

rshadow commented Oct 27, 2017

Ok. Thanks.

@IvanSanchez
Copy link
Member

So. Leaflet use mousewhell events but it is not MouseEvent. Maybe need write issue for this?

Yeah. Leaflet will listen to either mousewheel or wheel depending on browser support. And while currently Leaflet wraps mousedown, touchstart and pointerdown DOM events as a single mousedown event, it does not the same for wheel.

Having a wheel event at L.Map makes some sense. Feel free to open a issue for that. Keep in mind that such a wheel event would not necessarily imply any zoom events.

@gideon-grossman
Copy link

I want to separate events made by the user from internal events. For example, raise fitBounds when receive new data (markers, tracks, etc.). But if the user himself moved the map, then do not automatically raise fitBounds.

@rshadow
Did you ever find a solution. I am in the same exact conundrum.

@rshadow
Copy link
Author

rshadow commented Dec 24, 2019

Did you ever find a solution. I am in the same exact conundrum.

It was a long time ago. But I looked at the code and write about what I was doing.

# contructor:
self.manualzoom = false;
...

MyMap.prototype.fitAll = function( force ){
    var self = this;
    if( ! force &&   self.manualzoom )   return;
    ...
    # self.leaflet.fitBounds(...);
}

self.leaflet.on('zoom move', function( event ){
            if( ! event.originalEvent ) return;
            self.manualzoom = true;
});

and use self.fitAll(true) if user force show all data on map. Or self.fitAll() for background updates.

Sorry I can’t remember exactly the problem. I hope it helped at least something.

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

No branches or pull requests

3 participants