1

I want to style WMS layer using SLD in OpenLayers 3. written part of code shown below. There are not any console error messages shown but no styles are applied to the layer...

var sld = '<StyledLayerDescriptor version="1.0.0">';
                sld+= '<NamedLayer>';
                sld+= '<Name>topp:tasmania_roads</Name>';
                sld+= '<UserStyle>';
                sld+= '<IsDefault>1</IsDefault>';
                sld+= '<FeatureTypeStyle>';
                sld+= '<Rule>';
                sld+= '<LineSymbolizer>';
                sld+= '<Stroke>';
                sld+= '<CssParameter name="stroke">';
                sld+= '<Literal>#787878</Literal>';
                sld+= '</CssParameter>';
                sld+= '<CssParameter name="stroke-width">';
                sld+= '<Literal>2</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Stroke>';
                sld+= '</LineSymbolizer>';
                sld+= '</Rule>';
                sld+= '</FeatureTypeStyle>';
                sld+= '</UserStyle>';
                sld+= '</NamedLayer>';

                sld+= '<NamedLayer>';
                sld+= '<Name>topp:tasmania_water_bodies</Name>';
                sld+= '<UserStyle>';
                sld+= '<IsDefault>1</IsDefault>';
                sld+= '<FeatureTypeStyle>';
                sld+= '<Rule>';
                sld+= '<LineSymbolizer>';
                sld+= '<Stroke>';
                sld+= '<CssParameter name="stroke">';
                sld+= '<Literal>#4F94CD</Literal>';
                sld+= '</CssParameter>';
                sld+= '<CssParameter name="stroke-width">';
                sld+= '<Literal>3</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Stroke>';
                sld+= '</LineSymbolizer>';
                sld+= '<PolygonSymbolizer>';
                sld+= '<Fill>';
                sld+= '<CssParameter name="fill">';
                sld+= '<Literal>#63B8FF</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Fill>';
                sld+= '</PolygonSymbolizer>';
                sld+= '</Rule>';
                sld+= '</FeatureTypeStyle>';
                sld+= '</UserStyle>';
                sld+= '</NamedLayer>';

                sld+= '<NamedLayer>';
                sld+= '<Name>topp:tasmania_cities</Name>';
                sld+= '<UserStyle>';
                sld+= '<IsDefault>1</IsDefault>';
                sld+= '<FeatureTypeStyle>';
                sld+= '<Rule>';
                sld+= '<PointSymbolizer>';
                sld+= '<Graphic>';
                sld+= '<Mark>';
                sld+= '<WellKnownName>cross</WellKnownName>';
                sld+= '<Fill>';
                sld+= '<CssParameter name="fill">';
                sld+= '<Literal>#00FF00</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Fill>';
                sld+= '</Mark>';
                sld+= '<Size>15</Size>';
                sld+= '</Graphic>';
                sld+= '</PointSymbolizer>';
                sld+= '<TextSymbolizer>';
                sld+= '<Label><PropertyName>CITY_NAME</PropertyName></Label>';
                sld+= '<Font>';
                sld+= '<SvgParameter name="font-size">15</SvgParameter>';
                sld+= '</Font>';
                sld+= '</TextSymbolizer>';
                sld+= '</Rule>';
                sld+= '</FeatureTypeStyle>';
                sld+= '</UserStyle>';
                sld+= '</NamedLayer>';

                sld+= '<NamedLayer>';
                sld+= '<Name>topp:tasmania_state_boundaries</Name>';
                sld+= '<UserStyle>';
                sld+= '<IsDefault>1</IsDefault>';
                sld+= '<FeatureTypeStyle>';
                sld+= '<Rule>';
                sld+= '<PolygonSymbolizer>';
                sld+= '<Fill>';
                sld+= '<CssParameter name="fill">';
                sld+= '<Literal>#8B8989</Literal>';
                sld+= '</CssParameter>';
                sld+= '<CssParameter name="fill-opacity">';
                sld+= '<Literal>0.2</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Fill>';
                sld+= '<Stroke>';
                sld+= '<CssParameter name="stroke">';
                sld+= '<Literal>#FF4040</Literal>';
                sld+= '</CssParameter>';
                sld+= '<CssParameter name="stroke-width">';
                sld+= '<Literal>2</Literal>';
                sld+= '</CssParameter>';
                sld+= '</Stroke>';
                sld+= '</PolygonSymbolizer>';
                sld+= '</Rule>';
                sld+= '</FeatureTypeStyle>';
                sld+= '</UserStyle>';
                sld+= '</NamedLayer>';

                sld+= '</StyledLayerDescriptor>';

var wms = new ol.layer.Tile(
    {
        source: new ol.source.TileWMS({title: "Population Density",url: 'http://sedac.ciesin.columbia.edu/geoserver/wms',params: {LAYERS: 'gpw-v3:gpw-v3-population-density_2000',STYLES: undefined,SLD_BODY: sld}}),
        style: styles,


    });

Your Answer

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

Browse other questions tagged or ask your own question.