Leaflet / Leaflet.label

Leaflet.label is plugin for adding labels to markers & shapes on leaflet powered maps.
MIT License
465 stars 225 forks source link

Zoom level based class #124

Closed a1an77 closed 8 years ago

a1an77 commented 9 years ago

Is there a possibility to have a different class assigned to the labels depending on the map zoom level? It would be useful for having different font sizes or colour at different zoom levels.

the zoom level could be added alongside the specified class name, such as zoom-level-NN

a1an77 commented 9 years ago

Is there no interest at all in such a feature? Any pointer at how to implement it eventually?

IvanSanchez commented 9 years ago

You can just

map.on('zoomend', function(){
    if (  /* calculate if the zoom level change implies a label style change */ ) {
        /* change label style */
    }
});
a1an77 commented 9 years ago

Thanks @IvanSanchez that is indeed an option but it cuts off css, which would be cleaner (even though it might require defining up to 20 subclasses or so. I'll try your workaround meanwhile.

IvanSanchez commented 9 years ago

that is indeed an option but it cuts off css, which would be cleaner

map.on('zoomstart', function(){
    L.DomUtil.removeClass(map.getContainer(), 'zoom-' + map.getZoom());
});
map.on('zoomend', function(){
    L.DomUtil.addClass(map.getContainer(), 'zoom-' + map.getZoom());
});

You were saying? :-)

(Just beware of fractional zoom level support in Leaflet 1)

alexcroox commented 9 years ago

Is there a function for changing className? Like there is setContent for example, but setClassName doesn't work

alexcroox commented 9 years ago

marker.label.options.className = 'test'; does the trick

a1an77 commented 8 years ago

Works like a charm @IvanSanchez thanks