1

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)
                document.getElementById("control-leyenda").removeChild(divleyenda);
        }

    //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);
      document.getElementById("control-capas").appendChild(controlCapas.getContainer()
    );

enter image description here

enter image description here

  • 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 '19 at 10:44
  • where is addLeyenda and removeLeyenda called? – neogeomat Jul 31 '19 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 '19 at 10:20