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

panTo() ignores worldCopyJump option #4260

Closed
delner opened this issue Feb 18, 2016 · 5 comments
Closed

panTo() ignores worldCopyJump option #4260

delner opened this issue Feb 18, 2016 · 5 comments

Comments

@delner
Copy link

delner commented Feb 18, 2016

I've been developing a web app using Leaflet where the user locates a city by panning to it, then double clicking to place a marker. After the marker is placed, I call the panTo() function to pan the map to the location of the city.

Through the course of this interaction, the user gets a weird experience if they pan around the entire map before panTo() is called:

  1. It will rubberband the map around the entire world back to the equivalent place where they started.
  2. Any markers on the location in question will 'disappear' (presumably still on a neighboring copy to the center map that Leaflet pans to.)

Here's a video of the interaction I'm seeing. In this case, I'm starting at Los Angeles, scrolling westward around the Earth back to Los Angeles, placing a map marker (the circle that appears before the rubberband), and then calling panTo with the coordinates of Los Angeles. When I call panTo it rubberbands eastward around the world.

panTo oddity

I'm not sure whether it qualifies as a bug, but it definitely doesn't feel like great behavior, especially because it "wipes out" map markers in the process. Thoughts?

EDIT:

This is for Leaflet master (1.0.0beta2 + some recent bugfixes)

I was calling panTo() with the following:

leafletMap.panTo([city.lat, city.lng], { animate: true, duration: 1 });
@IvanSanchez
Copy link
Member

Have you tried the worldCopyJump map option?

@IvanSanchez
Copy link
Member

I've made a playground showing this bug:

    var mad = [40.40, -3.7];

    var map = new L.Map('map', {center: mad, zoom: 2, worldCopyJump: true});

    var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>'
    }).addTo(map);

    var marker = new L.Marker(mad);
    map.addLayer(marker);

    for(var i=1; i<=4; i++) {
        setTimeout((function(a){
            return function(){
                console.log('panning to', [40.40, -3.7 + (90 * a)]);
                map.panTo( [40.40, -3.7 + (90 * a)]);
            }
        })(i), 1000 * i);
    }

    setTimeout(function() {
        map.panTo(mad);
    }, 5000);

@IvanSanchez IvanSanchez changed the title panTo() rubberbands around the Earth panTo() ignores worldCopyJump option Feb 18, 2016
@delner
Copy link
Author

delner commented Feb 19, 2016

Oh, interesting. No I haven't, I'll see if adding the option changes anything.

@pmast
Copy link

pmast commented Dec 9, 2016

Probably dublicate: #2125

@Malvoz
Copy link
Member

Malvoz commented May 22, 2022

Probably dublicate: #2125

Yes.

@Malvoz Malvoz closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants