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= '' + 'COUNTRY Continent Africa #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