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

Label doesnt move if L.Marker gets moved by .setLatLng(LatLng) #1

Closed
Lukas-bw opened this issue Oct 4, 2012 · 3 comments
Closed

Label doesnt move if L.Marker gets moved by .setLatLng(LatLng) #1

Lukas-bw opened this issue Oct 4, 2012 · 3 comments

Comments

@Lukas-bw
Copy link

Lukas-bw commented Oct 4, 2012

Hello,

on my map I need to show static Labels on my markers. These markers are moving every 20 seconds by the L.Marker.setLatLng(LatLng) method, but the static label stays in place.

In addition to that, if I remove that marker from the map (removeLayer(myMarker)), the label is still there.

I have found a workaround which seems to be very complicated:

                        myMarker.hideLabel();
                        myMarker.unbindLabel();
                        myMarker.setLatLng(new L.LatLng(myNewLatLog));
                        myMarker.bindLabel(myLabeLText,{noHide: true});
                        myMarker.showLabel();
@jacobtoye
Copy link
Member

Ah nice find! I had not thought about this. I'll have a look into it.

@jacobtoye
Copy link
Member

The reason this is happening is because the Label has no idea when the marker has moved or been removed. L.Popup (in Leaflet core) has similar requirements.

I'll submit a fix to Leaflet core and when it is merged I'll update Leaflet.label.

@jacobtoye
Copy link
Member

Fixed in commits 0ca7e1c and d9fb815.

This change is dependent on Leaflet master. Draggable makers currently do not update the label position. I'll submit a fix to Leaflet core which will fix this issue.

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

2 participants