Wednesday, 16 December 2015

geoserver - Applying SLD not working in OpenLayers 3


My code is as below and I want to apply custom SLD to layer which is working for all codes in project except this one.


function cusMap(strSld_body,talukaName){
alert(strSld_body);

var query = new ol.layer.Tile({
source : new ol.source.TileWMS({
url : 'http://192.168.6.51:8090/geoserver/VP/wms',
crossOrigin: 'anonymous',
params : {
layers : 'VP:VillageBoundary',
version : '1.1.1',SLD_BODY: strSld_body,transparent : 'true'
}
}),


});
if(query.getSource().getParams().SLD_BODY){
delete query.getSource().getParams().SLD_BODY;
}
query.getSource().updateParams({'SLD_BODY': strSld_body});
if(query.getSource().getParams().CQL_FILTER){
delete query.getSource().getParams().CQL_FILTER;
}

query.getSource().updateParams({'CQL_FILTER': "Taluka='"+talukaName+"'"}); //add the cql filter to the Layer

map.removeLayer(croppedTaluka);
map.addLayer(query);
redrawLegend();
}

Here, my layer shows SLD which is applied in GeoServer, it is not taking SLD which I have applied in code.


The SLD I want apply is as below:


 Village
Village1 - 921 - 92VillageNesda Juna#ffe5e5#ffe5e50.26bevel92 - 18392 - 183VillageNesda Nava#ffcccc#ffcccc0.26bevel183 - 274183 - 274VillageVelavapura#ffb3b3#ffb3b30.26bevel274 - 365274 - 365VillageSamau Nanavas#ff9999#ff99990.26bevel365 - 456365 - 456VillageVarnoda#ff8080#ff80800.26bevel456 - 547456 - 547VillageLaxmipura#ff6666#ff66660.26bevel547 - 638547 - 638VillageDama#ff4d4d#ff4d4d0.26bevel638 - 729638 - 729VillageJorapura#ff1a1a#ff1a1a0.26bevel



Here, I have found that the HTTPRequest GET calls are not reaching GeoServer when large SLD is built dynamically in code. Can I make post calls in ol.source.TileWMS?



Answer



Actually the httprequest is the problem, use Httprequest Post method instead of get method in ol.source.ImageWMS?


Get request can not pass long string parameters. For big parameters we need to pass request with post method.


Now the bottleneck is that the post method is not supported in openlayers 3 whereas in old version it had support for post method.


Note: This is old OpenLayers code


   var query = new OpenLayers.Layer.WMS.Post("My Layer",
'http://192.168.6.51:8090/geoserver/VP/wms', {
LAYERS : 'Namespace:LayerName',
sld_body : strSld_body,

format : 'image/jpeg',
transparent : 'true'
},
{
unsupportedBrowsers: [],
isBaseLayer: false,
yx : {'EPSG:4326' : true}
} );

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