0

I have a Leaflet WMS Layer

mylayer = new L.tileLayer.wms('https://{s}.url.com/wms?', {
    mylayers: 'Workspace:mylayer',
    format: 'image/png',
    transparent: true,
    styles: 'sld1',
});
mylayer.addTo(map);

I have others styles sld2, sld3, sld4 how can change styles dynamically with a select box. I tried to use .setParams but it does not work:

<select id="styles" onchange="layer.setParams({styles: this.value});">
    <option selected="selected"  value="sld1">sld1</option>
    <option value="sld2">sld2</option>
</select>

This is the code:

<script>
        
    var map = L.map('map', {center: [46.3079204858171, 6.29013173213052 ], zoom: 7});     

    var tilemap = L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);            

mylayer = new L.tileLayer.wms('https://{s}.url.com/wms?', {
    mylayers: 'Workspace:mylayer',
    format: 'image/png',
    transparent: true,
    styles: 'sld1',
});

<select id="styles" onchange="mylayer.setParams({styles: this.value});">
    <option selected="selected"  value="sld1">sld1</option>
    <option value="sld2">sld2</option>
</select>

</script>
4
  • what doesn't work? what requests are sent to the server? – Ian Turton Apr 28 at 10:53
  • now i change styles just by change name sld1 by sld2 , but me i want to change it using select box like when i change layers , i find this methode of .setParams but doesn't work the show me white page. – Kawtar Apr 28 at 11:05
  • Place your select box after the ending </script> tag. – imre Apr 28 at 13:05
  • i tried to place it after </scripte> but the probleme that don't create any select box in the map to switch between styles! – Kawtar 19 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.