Opened 12 years ago

Last modified 12 years ago

#4153 new defect

C# Mapscript problem setting opacity on style object

Reported by: woodbri Owned by: tamas
Priority: normal Milestone:
Component: MapScript-C# Version: 6.0
Severity: normal Keywords:
Cc:

Description

The mapfile STYLE block[1] has OPACITY [integer|attribute] but I do not see this attribute listed in the SWIG mapscript [2] styleObj Attributes list.

And I have a report that when trying to use this via .NET mapscript that it does not seem to work.

layerObj opacity seems to work just fine.

If I go the

my_style.opacity = 50

route, it looks like it's being completely ignored in the resulting map.

If I go the

my_style.updateFromString("STYLE OPACITY 50 END")

route, then this also is sometimes ignored. It is ignored if after having set the opacity I set the color with

my_style.color = New colorObj(0, 255, 0, 0)

but if I rearrange my statements such that the color is set before instead of after I set the opacity (opacity set with updateFromString) then all works just fine. The other properties I set (symbol, width, outlinecolor) don't seem to have any similar order dependency as the transparency works just fine with them occurring either before or after the updateFromString call.

Stepping through the following snippet of code

Dim fieldStyle As New OSGeo.MapServer.styleObj(fieldClass) With fieldStyle

.color = New colorObj(0, 255, 0, 0) .opacity = 50 'set the opacity on the style .updateFromString("STYLE OPACITY 50 END") .color = New colorObj(0, 255, 0, 0) .symbol = 0 .width = 1 .outlinecolor = New colorObj(0, 0, 0, 0)

End With

(see attached Stepping.png image for the below) After the first .color = line, the alpha for color is set to 255. After the .opacity = line, the alpha for color is still 255. After the .updateFromString line, the alpha for color is 127 or approximately 50%. After the second .color = line, the alpha for color is back at 255. The .outlinecolor.alpha is always 255 and doesn't seem to affect the eventual appearance of the map, rather the outline is opaque if color.alpha = 255 but semi-transparent if color.alpha is less than 255.

So, if I had to guess as to what's going on under the covers I'd guess that style.alpha is being completely ignored and color.alpha is dictating the transparency of both the fill and the outline.

Testing using MS4W version 3.0.3 which I believe would be MapServer 6.0.1. 32-bit version.

Attachments (2)

Stepping.png (47.0 KB ) - added by woodbri 12 years ago.
Output of stepping through the code.
ms-bug-4153.zip (14.3 KB ) - added by woodbri 12 years ago.
Sample C# code that demonstrates the problem

Download all attachments as: .zip

Change History (3)

by woodbri, 12 years ago

Attachment: Stepping.png added

Output of stepping through the code.

by woodbri, 12 years ago

Attachment: ms-bug-4153.zip added

Sample C# code that demonstrates the problem

comment:1 by woodbri, 12 years ago

Please assign this to Documentation afterwards with appropriate notes on what is the expected behavior. It seems that there are some potential subtle side effects between setting the color, adding a symbol and setting opacity. Setting a color overrides opacity, adding a symbol seems to also modify alpha, and setting opacity only changes the alpha, so any action after setting opacity the implicitly change the alpha destroys the explicitly set opacity.

Note: See TracTickets for help on using tickets.