Skip to content
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

Allow passing undefined to ol.layer.Vector#setStyle #2638

Merged
merged 2 commits into from Aug 28, 2014
Merged

Allow passing undefined to ol.layer.Vector#setStyle #2638

merged 2 commits into from Aug 28, 2014

Conversation

elemoine
Copy link
Member

This PR changes the ol.layer.Vector#setStyle to make it more consistent with the way the ol.layer.Vector constructor treats the style option.

Currently, if the style option is undefined or null, the ol.layer.Vector constructor uses the default style function as the style. The setStyle fails (js error) if it is passed null or undefined.

This PR makes the constructor and the setStyle behave in a similar way. If the style passed to the function is null then a null style (and an undefined style function) is used. If undefined is passed then the default style function is used.

This allows to easily reset a vector layer to using the default style, without having to export the ol.style.defaultStyleFunction symbol.

Please review.

@probins
Copy link
Contributor

probins commented Aug 27, 2014

I added a link to the constructor option docs so people can easily find out what the default style is. It might be a good idea to add the same text to setStyle docs.

@elemoine
Copy link
Member Author

Yep, thanks, I can add that.

@fredj
Copy link
Member

fredj commented Aug 27, 2014

(setStyle instead of setCenter in the PR description ?)

@elemoine
Copy link
Member Author

(setStyle instead of setCenter in the PR description ?)

Fixed. Thanks.

@tonio
Copy link
Member

tonio commented Aug 27, 2014

Makes sense. Code looks good.

@fredj
Copy link
Member

fredj commented Aug 27, 2014

LGTM

@elemoine
Copy link
Member Author

I've been asked why the default style is not used when null is passed. In other words why are null and undefined treated differently?

That use-case: I want that the styles set in the features be used, and I want that features with no styles be not rendered in the layer. This use-case is covered by doing layer.setStyle(null). This is explained in the setStyle API docs.

@ahocevar
Copy link
Member

I think this makes sense.

elemoine pushed a commit that referenced this pull request Aug 28, 2014
Allow passing undefined to ol.layer.Vector#setStyle
@elemoine elemoine merged commit 99071b2 into openlayers:master Aug 28, 2014
@elemoine elemoine deleted the setstyle branch August 28, 2014 10:12
@elemoine elemoine added this to the v3.0.0 milestone Aug 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants