This is the code, the problem is that always print the same png legend even if you select another layer.

function addLeyenda(layer){
        if( layer instanceof L.TileLayer.WMS ){
                var container = document.getElementById("control-leyenda");
                var divleyenda = L.DomUtil.create('div','div-image-leyenda', container);
                divleyenda.id = '_leaflet_id_'+ paradas_bus;
                var imgleyenda = L.DomUtil.create('img','image-leyenda', divleyenda);
                imgleyenda.src = 'http://localhost:8080/geoserver/tfm/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=tfm:paradas_bus';
        function removeLeyenda(layer){
                var divleyenda = L.DomUtil.get('_leaflet_id_'+paradas_bus)

    //Incorporación de los GeoJSON tranvía y aparcabicis en formato JS a las capas de supersposición (Overlay)
      var controlCapas = L.control.groupedLayers(baseLayers, groupedOverlays).addTo(map);

enter image description here

enter image description here

closed as unclear what you're asking by neogeomat, Vince, Jochen Schwarze, TomazicM, Fran Raga Aug 1 at 7:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    A bit of explanation from your side of what you are trying to achieve would be helpful in helping you to achieve it. – TomazicM Jul 31 at 10:44
  • where is addLeyenda and removeLeyenda called? – neogeomat Jul 31 at 21:28
  • Mi problema es que cuando se seleccionan varias capas en el layer control, siempre sale en la leyenda el png de una sola capa, no varían los png. – Héctor SC Aug 1 at 10:20