5

I am attempting to draw a WMS layer consisting of multiple polygons of different colours and an opacity of 0.4.

The relevant part of my SLD is

      <PolygonSymbolizer>
        <Fill>
          <CssParameter name="fill"><ogc:PropertyName>colour</ogc:PropertyName></CssParameter>
          <CssParameter name="fill-opacity">0.4</CssParameter>
        </Fill>
        <Stroke>
          <CssParameter name="stroke">#000000</CssParameter>
          <CssParameter name="stroke-width">1</CssParameter>
        </Stroke>
      </PolygonSymbolizer>

Which draws the layer using the correct colours, but completely opaque.

The layer is being created with OpenLayers 2 as follows:

self.createBoundingAreaLayer = function (typeCode, boundingAreaIdentifier) {
    return new OpenLayers.Layer.WMS(
        typeCode,
        esd.pathUtility.geoServerUrl + "/ESD/wms",
        {
            LAYERS: 'ESD:areas',
            viewparams: 'parent:' + boundingAreaIdentifier + ';typecode:' + typeCode,
            format_options: 'antialias:none',
            format: 'image/gif',
            transparent: true
        },
        {
            singleTile: true,
            //opacity: 0.4,
            ratio: 1,
            isBaseLayer: false,
            transitionEffect: 'resize',
            yx: { 'EPSG:4326': false }
        }
    );
};

and if I uncomment the opacity: 0.4 line from there then it works. However, that isn't exactly what I want because it also changes the opacity of the stroke making it hard to see.

Is my SLD syntax correct for setting the opacity of the fill only? If so then why is this not working? Everything is currently running locally and I've rebooted my PC, so I don't think it's a caching issue.

Possibly relevant information: The style already existed and I added the fill-opacity parameter. I select the SLD by setting the default style for the layer in GeoServer. I never specify it in code.

2

Found this page where someone else had the same problem. Format image/gif does not support opacity. Changing my format to image/png solved the problem.

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.