Hiding labels with L.Control.Layers

692 views
Skip to first unread message

Michal Zimmermann

unread,
Feb 11, 2013, 4:03:29 AM2/11/13
to leafl...@googlegroups.com
Hi,
I'm using Leaflet label plugin for displaying static labels for markers, which are grouped in L.layerGroup. However, as I toggle their visibility through the control in the upper right corner, labels stay always switched on. I tried removing them with the following code:
MAP.map.on('layerremove', function(e) {
    e.layer.hideLabel();
});
but I end up with TypeError: layer.layer.hideLabel is not a function and the function stops after the first marker in a layerGroup. Is there any other way to hide labels than using CSS visibility?
The layerGroup consists of 5 markers, but in the console i get six object returned for the layerremove event.

Paulo Vieira

unread,
Feb 12, 2013, 6:22:15 AM2/12/13
to leafl...@googlegroups.com
"hideLabel" is the right method to make the labels invisible. I think the problem is in the line:

e.layer.hideLabel();

Out of my mind, I'd say that "e.layer" is the layer group, not the markers. You have to confirm this in leaflet source (the documentation is not very clear).

If this is true, then you should do something like this:
---------------------------------
myLayerGroup = e.layer;
myLayerGroup.eachLayer( function(myMarker){
  myMarker.hideLabel();
});
---------------------------------

If this doesn't work, you should create a jsfiddle with a stripped down version of your code.


--
 
---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michal Zimmermann

unread,
Feb 12, 2013, 6:31:50 AM2/12/13
to leafl...@googlegroups.com
Got the same error with your code "TypeError: myLayerGroup.eachLayer is not a function". I'll make a jsfiddle asap and send you a link.
--
Michal Zimmermann (zimmi) 
WWW: http://www.zimmi.cz
Reply all
Reply to author
Forward
0 new messages