Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

labels not moving after panTo in Leaflet #142

Open
lehha opened this issue Jan 26, 2016 · 5 comments
Open

labels not moving after panTo in Leaflet #142

lehha opened this issue Jan 26, 2016 · 5 comments

Comments

@lehha
Copy link

lehha commented Jan 26, 2016

If call map.panTo(...) in Leaflet, labels are stays at screen, but map and view are moved.

How tell to labels to update position? Bug?

@mandsch
Copy link

mandsch commented Apr 30, 2016

Hi, we have exactly the same issue. The panTo is triggered from an anchor tag with a data-position attribute. the map pans but the labels not.

@mandsch
Copy link

mandsch commented Apr 30, 2016

Just to add some more details: The data that is labeled is a geojson layer. I just realized, that they don't move if the pan distance is to far to just move the map a bit.

@TranquilAbyss
Copy link

TranquilAbyss commented Aug 27, 2016

I have a similar problem with Leaflet Search plugins moveToLocation. If I zoom in a bit and move to a location far away on the map the labels stay drawn in the previous location as if they were controls. Once I zoom out the labels are updated. This only seems to happen if the camera is moved and zoomed instantaneously by a function like moveToLocation or panTo.

What would the best way to redraw the labels or to get leaflet to redraw the overlay container after a move?

My guess is it is an issue with either the leaflet Label plugin or the Leaflet itself. But I originally made a post on the Leaflet Search Git found at stefanocudini/leaflet-search#127.

@TranquilAbyss
Copy link

TranquilAbyss commented Sep 12, 2016

I think I found a solution.

I found that the labels were being updated in the label sources code using two leaflet event, moveend and viewreset. The event viewreset is suppose to trigger when the map is triggered by something other than the mouse. more info on view reset can be found at http://leafletjs.com/reference-1.0.0.html#map-event.

In the file leaflet.label-src.js around line 197 I commented out the && e.hard.

_onViewReset: function (e) {
        /* if map resets hard, we must update the label */
        if (e)// && e.hard)
            {
            this._update();
        }
    },

I found the orgin of e.hard.
#42

This fixed the problem for moveToLocation using the Leaflet Search plugin. I am not sure if it will fix the panToor flyTo problems others have had. Hopefully someone else can test it.

Hopefully someone can provide a better solution then my hack.

Thanks

@mandsch
Copy link

mandsch commented Sep 13, 2016

Thanks TranquilAbyss, this fix also works for me. I assume it's an issue with the viewReset event not having the hard attribute. Version mismatch?

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

No branches or pull requests

3 participants