Is there any way to style the WMS layer using client side script I use js to style WMS layer. Code is shown below.... but it's not work.

//applying styles for unescap layer

var unescap = new ol.layer.Tile(
        source: new ol.source.TileWMS({url: '',params: {LAYERS: 'unescap:rg_di_any_all'}}),
        style: new ol.style.Style({
                                    stroke: new ol.style.Stroke({color: '#319FD3',width: 1}),
                                    fill: new ol.style.Fill({color: 'rgba(17, 224, 36, 0.66)'}),
                                    text: new ol.style.Text({
                                                              font: '12px Calibri,sans-serif',
                                                              fill: new ol.style.Fill({color: '#ff0'}),
                                                              stroke: new ol.style.Stroke({ color: '#09C',width: 3})
  • WMS is going to give you an image. You can't style that on the client side. – BradHards Dec 12 '14 at 10:12
  • gis.stackexchange.com/questions/123523/… in here i got this as answer is that correct..... [ You can only style features on the client side. A WMS server will send out images with predefined rendering. You can only alter these styles on the server side, in this case in the geoserver layer configuration (you will need admin privileges for this). You can only apply CSS styles to the images, which can be applied on an <img> element. ] – Susantha7 Dec 12 '14 at 10:25
  • So you already know you can only style features (i.e. WFS) not maps (WMS) on the client side. Why ask again? – BradHards Dec 12 '14 at 10:31
  • i didn't understand that answer thoroughly.there fore i dont get how that has done.can you please explain how this has to be done.... – Susantha7 Dec 12 '14 at 10:36
  • If the WMS is SLD enabled (GeoServer and MapServer for example) you can send an external SLD as part of the request and the returned image will have your style – nmtoken Dec 12 '14 at 11:02

A WMS is a service that provides an image according to a request sent by a client such as OpenLayers. A WMS layer has a default style and sometimes other pre-canned styles that can be applied as part of a request by the client. Once an image is received in a client, there is very little styling that can be applied.

Some WMS offer an additional capability to apply a custom made style, that is a style provided by a client (either pre-canned or created on-the-fly). In such a situation the client (for example OpenLayers) creates a style (using SLD) and sends the request (GetMap) to the WMS with the custom style. The WMS applies the custom style on the server and sends back the image with the style applied.

An example of a GetMap request requesting the default style might be:


The same map request with a custom style applied could be:


This example uses an SLD generated on-the-fly by the OneGeology Portal which is a client that uses OpenLayers.

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.