-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't attempt to constrain values in setters #798
Conversation
Sounds sane to me. Thanks. |
How will this work if we allow something like +/- buttons to modify opacity? If I get to opacity 1 and click + ten times, do I have to click - 11 times just to reduce the opacity? |
increaseOpacityButton.addEventListener('click', function (e) {
layer.setOpacity(Math.min(1, layer.getOpacity() + 0.1));
}); |
I don't think this is going in the right direction to have every control know about the constraint (all in the name of binding to another property without a constraint). I'd like to have more discussion about this before you merge. |
I don't mind holding off merging, but:
|
Examples of controls needing to know about the valid values: https://github.com/openlayers/ol3/blob/master/examples/bind-input.html#L54-63 |
As discussed on the call, at some point it could be nice to configure an For now, we agree that its ok to have controls etc. needing to know about these constraints (without asking the object for them). So merging is ok by me. |
Don't attempt to constrain values in setters
P.S. I agree that constraints on |
Fix click on PanZoomBar when page is scrolled (fix openlayers#798).
A number of setters in
ol.layer.Layer
attempted to constrain the values that could be set which breaks property binding. This PR fixes that by deferring the application of the constraints until the creation of the layer state.Here are two examples of how the old code could break. Consider brightness (which eventually needs to be in the range -1..1) and opacity (range 0..1).
Case one:
Case two:
In general, due to binding, it is not possible to apply constraints in setters. Consider the case where two properties with incompatible constraints are bound to each other (e.g. constraint in the first object is
x > 0
and constraint in the second object isx < 0
; what values canx
take?).The PR fixes these problems by removing the constraints from the properties, and instead sanitising the values when they are used.