Saturday, 22 July 2017

openlayers 2 - How to add SLD to a wms layer dynamically from javascript


How to add SLD style which is written in String format and stored in a 'var' variable of javascript and asign it to a WMS layer while creating it.



Answer




All you need to do is replace the styles parameter with an SLD parameter that contains your style. The following code from this example demonstrates the concept.


            theSLD_BODY= '' + 'COUNTRYContinentAfrica#5599DD#000000';
layer2 = new OpenLayers.Layer.WMS( "Africa (SLD_BODY)",
"http://gis.ibbeck.de/include/mapserver/mapserv.exe?map=/daten/mapfiles/world/World.map",
{ "layers": "COUNTRY",
"format": "image/png",
"version": "1.1.1",
"transparent": "TRUE",
"SLD_BODY": theSLD_BODY
});


You may encounter problems if the SLD becomes too long as it may exceed the maximum URL length of your browser. In which case you will need to switch to POST instead of GET requests.


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...