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

Dragging not working with Leaflet 1.9.2 #47

Open
oisact opened this issue Nov 7, 2022 · 7 comments
Open

Dragging not working with Leaflet 1.9.2 #47

oisact opened this issue Nov 7, 2022 · 7 comments

Comments

@oisact
Copy link

oisact commented Nov 7, 2022

With the latest Leaflet (Leaflet 1.9.2) dragging the control is not working correctly. The map itself is being dragged. There is a simple fix. Add:
L.DomEvent.disableClickPropagation(this._container);
To the addTo function (I'm calling it right before the return this). This disables propagation of click events through to the map.

Optionally, the functions cancelMapDrag and uncancelMapDrag are not serving any purpose, and they (and the event hooks to them) can be removed.

I have no idea what Leaflet version this first started manifesting with.

@AhXianGL
Copy link

AhXianGL commented Dec 14, 2022

hi, i met this problem recently too.
in file leaflet-side-by-side.js _addEvents function

// leaflet-side-by-side.js
  _addEvents: function () {
    var range = this._range
    var map = this._map
    if (!map || !range) return
    map.on('move', this._updateClip, this)
    map.on('layeradd layerremove', this._updateLayers, this)
    on(range, getRangeEvent(range), this._updateClip, this)
    on(range, L.Browser.touch ? 'touchstart' : 'mousedown', cancelMapDrag, this)
    on(range, L.Browser.touch ? 'touchend' : 'mouseup', uncancelMapDrag, this)
  },

I found that the L.Browser.touch is always true when i run my App on Chrome, the browser(or event listener) listen the touch instead of mouse events, this is why the 'MapDrag' event is not be canceled when i drag the side-by-side bar,
so i went to leaflet doc L.Browser.touch ref, the L.Browser.touch is the key of the problem. I solve the problem by rewrite the code here in my app to

on(range, 'mousedown', cancelMapDrag, this)
on(range, 'mouseup', uncancelMapDrag, this)

but this way has a drawback that it cannot work on mobile platphone or other touchable instruments.
i have an advice that ** L.Browser.touch ? 'touchstart' : 'mousedown'** may be replaced by other methods work for distinguish
the environment is mobile or PC, or we expect the author explain the code here .
I am not a english native speaker, sorry for that, but hope i can make something about this issue.

@giswqs
Copy link

giswqs commented Mar 6, 2023

Downstream packages (e.g., folium, ipyleaflet) are having the same issue. @oisact Could you submit a PR to fix the issue since you already figured it out?

jupyter-widgets/ipyleaflet#1066
python-visualization/folium#1732

@giswqs
Copy link

giswqs commented Apr 2, 2023

Any updates on this issue? This bug essentially makes this plugin useless.

@rabenojha
Copy link

It is not working with 1.9.3 either. But thanks to the fix from @oisact .

@AHBAdmin
Copy link

Can confirm 1.9.4 still has the same issue. @oisact fix did the trick for now.

@nimchimpski
Copy link

Thanks @oisact! - simple and well explained fix for 1.9.4

@nonchain
Copy link

nonchain commented Jul 13, 2024

I tried this and worked for me. (version 2.2.0)
just before adding the layers to the leaflet write this code to customize the drag event.

function getRangeEvent(range) {
  return 'input';
}
/* your logic */
L.Control.CustomCompare = L.Control.Compare.extend({
  _addEvents: function () {
    const range = this._range;
    const map = this._map;
    if (!map || !range) return;

    map.on("move", this._updateClip, this);
    map.on("layeradd layerremove", this._updateLayers, this);
    L.DomEvent.on(range, getRangeEvent(range), this._updateClip, this);
    L.DomEvent.on(range, "touchstart mousedown", () => {
      map.dragging.disable();
    });
    L.DomEvent.on(range, "touchend mouseup", () => {
      map.dragging.enable();
    });
  }
});
new L.Control.CustomCompare([leftLayer], [rightLayer]).addTo(map);

mattdzugan added a commit to mattdzugan/leaflet-side-by-side that referenced this issue Oct 4, 2024
this is a fix to issue 47
digidem#47
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

7 participants