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

2nd call to showLabel() throws error #7

Closed mcassisa closed 11 years ago

mcassisa commented 11 years ago

As per subject: a second call to showLabel() throws an error: showLabel() is not a function. While this works:

var layerForti = L.geoJson( jsonForti, {
    pointToLayer: function (feature, latlng) {
            return L.marker(latlng, {icon: iconForti});
    },
    onEachFeature: function (feature, layer) {
        layer.bindPopup(feature.properties.Name);
        layer.bindLabel(feature.properties.Name).showLabel();     //first call! is needed indeed!
    }
});

var layerFuneRiva = L.geoJson( jsonImpiantiFuneRiva, {
    pointToLayer: function (feature, latlng) {
            return L.marker(latlng);
    },
    onEachFeature: function (feature, layer) {
        layer.bindPopup(feature.properties.Name + '<br />' + feature.properties.Description);
        layer.bindLabel(feature.properties.Name).addTo(lmap);    //<---note this
    }
});

This don't:

var layerForti = L.geoJson( jsonForti, {
    pointToLayer: function (feature, latlng) {
            return L.marker(latlng, {icon: iconForti});
    },
    onEachFeature: function (feature, layer) {
        layer.bindPopup(feature.properties.Name);
        layer.bindLabel(feature.properties.Name).showLabel();    
    }
});

var layerFuneRiva = L.geoJson( jsonImpiantiFuneRiva, {
    pointToLayer: function (feature, latlng) {
            return L.marker(latlng);
    },
    onEachFeature: function (feature, layer) {
        layer.bindPopup(feature.properties.Name + '<br />' + feature.properties.Description);
        layer.bindLabel(feature.properties.Name).showLabel(); //nor this does: layer.bindLabel(feature.properties.Name).addTo(lmap).showLabel(); 
    }
});
[...]
var overlayMaps = { 'Forti Alto Garda': layerForti, 'Impianti a Fune Riva': layerFuneRiva, 'Vie Patrioti Riva-Arco': layerViePatrioti, 'Mandrone': layerMandron };

L.control.layers(null,overlayMaps, {collapsed: false}).addTo(lmap);
jacobtoye commented 11 years ago

Would you mind setting up a jsfiddle that demonstrates the issue.

arnotixe commented 11 years ago

Same error here, look in firebug script console on http://arno.homelinux.org/oslotur/landscape.php

jacobtoye commented 11 years ago

This is because static labels are only available for markers. See #15 for reasons.

Sorry this isn't documented :( I'll update the readme.