Ticket #3441 (closed bug: fixed)

Opened 22 months ago

Last modified 22 months ago

Default opacity of layer

Reported by: mosesonline Owned by: euzuro
Priority: minor Milestone: 2.12 Release
Component: Layer Version: SVN
Keywords: layer Cc:
State: Review

Description

Currently the opacity of a layer is null by default but it is visible. If there is a control or an element which wants to control the opacity of layers it has to deal with this strange "number" null like :
if (layer.opacity == null) layer.opacity = 1;
It think it would be clearer if the opacity would be 1 form start.

Attachments

opacity_default.patch Download (0.7 KB) - added by mosesonline 22 months ago.
opacity-not-null.patch Download (2.2 KB) - added by ahocevar 22 months ago.
with fixed OWS and WMC formats
openlayers-3441.patch Download (1.0 KB) - added by ahocevar 22 months ago.

Change History

Changed 22 months ago by mosesonline

  Changed 22 months ago by ahocevar

  • state changed from Review to Needs More Work

Several tests fail with this patch applied.

follow-up: ↓ 3   Changed 22 months ago by mosesonline

All the layer tests are running well. Maybe the creators of the failing classes/tests could help to solve why the classes/tests fail with visible layers? WMC, Format/OWSContext/v0_3_1.html and Marker/Box tests fail, did I missed some?
The first fails because the sanitize-method in the test changes the version from 1.1.1 to 1.10000.1 and other floating point numbers or text which looks like floating point to an unexpected format.
But these tests only fail when the tests are running with all tests as batch when running only one test as a single test.

in reply to: ↑ 2   Changed 22 months ago by mosesonline

Cancel the last sentence. I had the configuration without the patch, sorry.

  Changed 22 months ago by ahocevar

The WMC and OWSContext tests failing is a concern. It should be possible to configure layers without the opacity set. This is why I think that a default of null makes sense, meaning "we don't bother". It isn't that hard to deal with this on the application level. See e.g.  http://trac.geoext.org/browser/core/trunk/geoext/lib/GeoExt/widgets/LayerOpacitySlider.js?rev=2605#L213 for how this is done in GeoExt - it goes along with checking if we have a layer and doesn't hurt at all.

  Changed 22 months ago by mosesonline

But it seems that the formats do bother about the opacity, they work with opacity null but not with 1. In a case where 1 is a documented value for the property and null the undocumented default value. My app handles the null value, because it has to, but why the format don't handle legal values for this option? I would change it if I could, but I'm not so into these classes. Maybe someone who wrote the classes could give a hint to fix it. I would try to fix the errors in the classes or should the null value stay?
Why I think it should be fixed:
The null value is sometimes "we don't bother", sometimes "oh, I forgot to set", sometimes "Make it visible" and sometimes "Don't show it", it is ambiguous. Ambiguous values lead to confusion and this leads to exceptions or errors.
A layer is a visual component so it is always visible or not, and if it's visible it has an opacity(that's why the Layer-class has this attribute and not a subclass), if a client (class) doesn't bother it should not use this value.
I cannot imagine a use case where the opacity of a layer must not be set, at least to a default value 1. I can imagine several cases where it is not used, but than I don't use it.
The last thing is that it leads to more code, where the user has to deal an ambiguous value every time he wants to compute something with the opacity.

  Changed 22 months ago by ahocevar

@mosesonline: your explanation makes good sense. I will create a new patch with the required modifications to the format classes.

Changed 22 months ago by ahocevar

with fixed OWS and WMC formats

  Changed 22 months ago by ahocevar

  • state changed from Needs More Work to Commit

  Changed 22 months ago by ahocevar

  • status changed from new to closed
  • resolution set to fixed

(In [12227]) making 1 the default for layer opacity. p=mosesonline,me r=me (closes #3441)

  Changed 22 months ago by ahocevar

  • status changed from closed to reopened
  • state changed from Commit to Review
  • resolution fixed deleted

This needs a few more changes after reverting r12185. Please review openlayers-3441.patch Download.

Changed 22 months ago by ahocevar

  Changed 22 months ago by mosesonline

The changes in this patch are coherent, correct and an enhancement/bugfix (before tiles are modified also with opacity 1) for me. It also to works right for WMS layers but we have no marker layers so I cannot check this. Thx, for patching the formats and this.

  Changed 22 months ago by ahocevar

  • status changed from reopened to closed
  • resolution set to fixed

(In [12240]) opacity fixes required after reverting r12185. r=mosesonline (closes #3441)

Note: See TracTickets for help on using tickets.