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

Maplibre-gl-leaflet layer is mis-aligned with map when panning the map off screen #29

Closed
gavinr opened this issue Aug 12, 2022 · 7 comments · Fixed by #31
Closed

Maplibre-gl-leaflet layer is mis-aligned with map when panning the map off screen #29

gavinr opened this issue Aug 12, 2022 · 7 comments · Fixed by #31

Comments

@gavinr
Copy link
Contributor

gavinr commented Aug 12, 2022

If you drag the map out of the window, the maplibre-gl-leaflet layer gets stuck in view while other leaflet layers (like markers) continue to get pulled, causing the two layers not to be aligned correctly.

Replication case

https://jsbin.com/vepuyeqoyo/3/edit?html,output

  1. Open the demo case
  2. Drag the map down
    • Expected: point stays in its place relative the maplibre-gl-leaflet layer (in the ocean above greenland)
    • Actual: when the maplibre-gl-leaflet layer reaches the bottom of the window, as the map continues to be drug down, the point moves relative to the maplibre-gl-leaflet layer, moving all the way off screen.
chrome_t6InO6UcHH.mp4
@gavinr gavinr changed the title Map does not move when panning the map off screen Maplibre-gl-leaflet layer is mis-aligned with map when panning the map off screen Aug 12, 2022
@wipfli
Copy link
Contributor

wipfli commented Aug 12, 2022

Thanks for taking the time to open this issue @gavinr

@gavinr

This comment was marked as outdated.

@wipfli
Copy link
Contributor

wipfli commented Aug 12, 2022

Is there a way to limit the map movement maybe?

@patrickarlt
Copy link
Contributor

@wipfli yes Leaflet supports a maxBounds property and setMaxBounds() method on the Map. Enabling it seems to fix the issues:

https://jsbin.com/yofobup/1/edit?html,output

var map = L.map('map', {
  maxBounds:[[-90,-180], [90,180]] // limit to the defined world bounds
}).setView([0,0 ], 2);

L.marker([179, 0])
    .bindPopup("Hello <b>Leaflet GL</b>!<br>Whoa, it works!")
    .addTo(map)
    .openPopup();

var gl = L.maplibreGL({
    // get your own MapTiler token at https://cloud.maptiler.com/ or use MapBox style
    style: 'https://api.maptiler.com/maps/topo/style.json?key=gbetYLSD5vR8MdtZ88AQ'
}).addTo(map);

I guess the question is do we try to just limit the north/south panning/zooming behavior in _update or _transformGl() or just call map.setMaxBounds([[-90,-180], [90,180]]) and document this behavior.

@wipfli
Copy link
Contributor

wipfli commented Aug 15, 2022

Since it is a north/south problem, I would like to avoid limiting also east/west movement, so map.setMaxBounds([[-90,-180], [90,180]]) seems like a bad option. But could you maybe share the idea of fixing the problem with _update in a pull request? That would be interesting...

@patrickarlt
Copy link
Contributor

@wipfli I can give it a shot but it probably won't be soon.

patrickarlt added a commit to patrickarlt/maplibre-gl-leaflet that referenced this issue Aug 19, 2022
@patrickarlt
Copy link
Contributor

@wipfli @gavinr turns out this was really simple. I put up #31 with a fix.

wipfli pushed a commit that referenced this issue Aug 19, 2022
wipfli added a commit that referenced this issue Aug 19, 2022
* Fix #29

* add changelog entry

* Update CHANGELOG.md

Co-authored-by: Oliver Wipfli <oliver.wipfli@leichteralsluft.ch>
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 a pull request may close this issue.

3 participants