1

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:

 <?xml version="1.0" encoding="UTF-8"?><StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:se="http://www.opengis.net/se"><NamedLayer><se:Name>Village</se:Name><UserStyle>
  <se:Name>Village</se:Name><se:FeatureTypeStyle><se:Rule><se:Name>1 - 92</se:Name><se:Description><se:Title>1 - 92</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Nesda Juna</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ffe5e5</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ffe5e5</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>92 - 183</se:Name><se:Description><se:Title>92 - 183</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Nesda Nava</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ffcccc</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ffcccc</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>183 - 274</se:Name><se:Description><se:Title>183 - 274</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Velavapura</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ffb3b3</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ffb3b3</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>274 - 365</se:Name><se:Description><se:Title>274 - 365</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Samau Nanavas</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ff9999</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ff9999</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>365 - 456</se:Name><se:Description><se:Title>365 - 456</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Varnoda</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ff8080</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ff8080</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>456 - 547</se:Name><se:Description><se:Title>456 - 547</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Laxmipura</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ff6666</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ff6666</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>547 - 638</se:Name><se:Description><se:Title>547 - 638</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Dama</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ff4d4d</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ff4d4d</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>638 - 729</se:Name><se:Description><se:Title>638 - 729</se:Title></se:Description><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>Village</ogc:PropertyName><ogc:Literal>Jorapura</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name="fill">#ff1a1a</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name="stroke">#ff1a1a</se:SvgParameter><se:SvgParameter name="stroke-width">0.26</se:SvgParameter><se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule></se:FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>

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?

  • it appears from the comments that this is now resolved, could you post your comment as an answer, to help those in the future with the same problem. You can accept you own answer as well :) – nmtoken Aug 26 '16 at 10:14
1

try to pass the sld_body uri encoded. like so:SLD_BODY:encodeURIComponent(strSld). If this doesnt work check within geoserver log to see for any errors or identify whether the SLD_BODY parameter is actually reach geoserver or not.

  • Not working actually not showing anything on map.no images are coming. – Mr. P Dec 4 '15 at 11:44
  • The same SLD if I put in geoserver then it is working with no errors.but it becomes static. – Mr. P Dec 4 '15 at 11:46
  • The sld you use seems to be fine. I checked it with geoserver and is correct. This is not the problem. Is the layer you request a GWC tiled layer? From the code you provide seems to be GWC configured. If yes it wonnt work as the images are allready prerendered using the style during GWC layer initilasation. If you want to dynamically change the sld style of your wms layer use the new ol.layer.Image class with ol.source.ImageWMS source. – pavlos Dec 4 '15 at 11:53
  • I did that too but not showing images. – Mr. P Dec 4 '15 at 17:07
  • no error on firebug? no error on geoserver log??? nothing???? Just not showing images? – pavlos Dec 4 '15 at 18:34
0

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}
        } );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.