Wednesday, 30 March 2016

openlayers 2 - How to dynamically change SLD style of WMS layer being served by GeoServer from PostGIS?


How can I dynamically change a SLD style of a WMS layer being served by GeoServer from PostGIS?




Answer



I've found an answer in http://osgeo-org.1560.x6.nabble.com/dynamic-SLD-with-openlayers-td3806595.html


It solved my problem. Example:


  var tiled = new OpenLayers.Layer.WMS ("state","http://localhost:8080/geoserver/wms", {......})

tiled.mergeNewParams({SLD :some_sld_url });

If layer already had styles specified by "Styles" property, then you have to set it to null:


tiled.mergeNewParams({ SLD: some_sld_url, STYLES: null });


There is no need to redraw the layer. "mergeNewParams" will do it.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...