Leaflet.label
Leaflet.label copied to clipboard
labels not moving after panTo in Leaflet
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?
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.
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.
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 https://github.com/stefanocudini/leaflet-search/issues/127.
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
.
https://github.com/Leaflet/Leaflet.label/issues/42
This fixed the problem for moveToLocation
using the Leaflet Search plugin. I am not sure if it will fix the panTo
or flyTo
problems others have had. Hopefully someone else can test it.
Hopefully someone can provide a better solution then my hack.
Thanks
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?