-
-
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
Mutable symbolizer properties for styles #2678
Conversation
a3831f8
to
e8ad0a9
Compare
This change adds setters for symbolizer properties. In addition, it introduces a mutable flag on all styles. By default, this is set to true. ol.style.createStyleFunction sets it to false for all static styles. The new setters assert that the mutable flag is true, so whenever an application tries to set a symbolizer property on a style that was assigned to a vector layer or feature overlay, the assertion will fail.
e8ad0a9
to
a50f6d7
Compare
Curious to hear about the use case. If the is to be used in a style editing application, could regular old objects (like those passes to the symbolized constructors) be used instead? I fear that people will see the setter methods and assume that is the way to modify existing styles - only to be frustrated when nothing happens (no asserts in compiled code). |
Good point @tschaub. Yes, the use case is interactive style editing. My first solution would also have been plain object literals, but then I saw that |
It may be obvious but I'm failing to understand the purpose of the And what if you do layer.setStyle(styles);
layer.setStyle(function(feature, resolution) {
return styles;
}); You will have your own style function but with immutable styles. Not sure that's expected. |
And in the case where you have your own style function the layer will not be redrawn if you change a style outside the style function. You have to call So, if we want mutable styles, I'd just make it clear (in the docs) that the user needs to call |
|
Removed the |
5323bed
to
ec159fc
Compare
Instead, educate users to call setStyle.
ec159fc
to
0c36d76
Compare
Code looks good to me. But I think the docs need clarifications. I can try to add a commit to your branch tomorrow if you agree. |
Sure @elemoine, thanks. |
For the record I know you don't like the idea of calling The following would look ridiculous to me: style.getFill().setColor(color);
layer.setStyle(layer.getStyle()); Hard to understand for someone reading that code I think. This makes more sense to me: style.getFill().setColor(color);
// notify the layer that we've changed styles (by
// dispatching a change event to it)
layer.dispatchChangeEvent(); We may be able to find better ways in the future. But calling |
I agree with @elemoine that the second way makes more sense As an aside, I don't really like the name dispatchChangeEvent, something like update would make more sense to me. |
Both works, and @elemoine's code does not have to look that ugly: style.getFill().setColor(color);
layer.setStyle(style); If the docs are changed from "Use |
Agreed |
@ahocevar your code won't work if what you passed to the layer initially was a style function. Calling
Too bad (and worrying) that you're taking it that way. |
Whatever. Docs updated. |
At the risk of being "academic" I don't like "update". Update what? This sounds too abstract to me. But I'll think more about it... |
/** | ||
* Set the color. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer | ||
* or feature overlay for changes to take effect. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling setStyle or dispatchChangeEvent on what object? What if the style you're modifying is set on a feature? This is what I mean by saying "needs clarification".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ol.Feature
, ol.layer.Vector
and ol.FeatureOverlay
all have setStyle()
and dispatchChangeEvent()
. Suggestions for further clarification welcome.
And @elemoine, don't worry. You know I am a friend of pragmatic, so excuse me that I find this discussion academic.
c9685af
to
88c3079
Compare
Actually I was wrong. |
5d868cc
to
0e14639
Compare
I think we should update this patch to replace I'm not a big fan of repeating the docs for each style property as done in this patch. But I'll create a new PR if I have ideas on improving this. |
Please consider #2684. The DispatchChangeEvent method really should be renamed because it does more than just dispatch a change event. |
@elemoine I moved the documentation about re-rendering to the ol.style.Style classdesc, so you can change it easily to your liking. Merging now. |
Mutable symbolizer properties for styles
Thanks. It makes to get this change in and exercise it a bit. Looking forward to knowing if that makes less the styling framework less "awkward" for people. |
This change adds setters for symbolizer properties. In addition, it introduces a mutable flag on all styles. By default, this is set to
true
.ol.style.createStyleFunction()
sets it tofalse
for all static styles.The new setters assert that the mutable flag is
true
, so whenever an application tries to set a symbolizer property on a style that was assigned to a vector layer or feature overlay, the assertion will fail.