I would like to control the opacity of a wms layer (using L.tileLayer.wms
) in Leaflet using an opacity slider.
In L.tileLayer.wms
I can control the opacity by setting the opacity:value.
This is my piece of code; The wms layer
var wmsLayer_2 = L.tileLayer.wms('https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php', {
layers: ['CP.CadastralParcel'],
crs: crs_6706,
format: 'image/png',
maxZoom: 21,
transparent: true,
}).addTo(map);
The slider implemented in the leaflet control
function updateOpacity(value) {
wmsLayer_2.setParams({opacity:value});
};
var control = L.control.layers(baseMaps,
{'Opacity_layer <br><input id="range" type="range" min="0" max="1" step="0.1" value="1" class="slider" onchange="updateOpacity(this.value)">':wmsLayer_2},{collapsed: false}).addTo(map);
However I can't manage the opacity.