Skip to content

Add color option to ol.style.Icon #4457

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

Merged
merged 3 commits into from
Jan 10, 2016
Merged

Conversation

alexbrault
Copy link
Contributor

This PR adds a color option to tint an ol.style.Icon.

See https://groups.google.com/forum/#!topic/ol3-dev/vPK4ygQHaqo

@alexbrault
Copy link
Contributor Author

@ahocevar, I ended up multiplying pixel values instead of replacing white with the colour because the latter left undesired artifacts in the majority of cases (e.g. anything with antialiasing)

@ahocevar
Copy link
Member

Thanks for this pull request @alexbrault. Great enhancement! I'll review it within the next few days.

@@ -492,6 +516,7 @@ ol.style.IconImage_.prototype.handleImageLoad_ = function() {
this.imageState_ = ol.style.ImageState.LOADED;
this.size_ = [this.image_.width, this.image_.height];
this.unlistenImage_();
this.replaceColor_();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying the color will only work if the image is not tainted.
It should be moved after determineTainting().

@alexbrault alexbrault force-pushed the colour-icon branch 4 times, most recently from 06a5230 to 28633e4 Compare November 25, 2015 02:02
@@ -6004,6 +6004,7 @@ olx.style.FillOptions.prototype.color;
* anchorOrigin: (ol.style.IconOrigin|undefined),
* anchorXUnits: (ol.style.IconAnchorUnits|undefined),
* anchorYUnits: (ol.style.IconAnchorUnits|undefined),
* color: (ol.Color|undefined),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to also accept a string here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget what my reasoning for omitting this was, but yes, it should

@fredj fredj added this to the v3.13.0 milestone Jan 7, 2016
@ahocevar
Copy link
Member

ahocevar commented Jan 8, 2016

This looks great @alexbrault. It looks like we do not have a CLA on file from you yet. Can you please submit one so we can merge this?

ahocevar added a commit to openlayers/cla that referenced this pull request Jan 10, 2016
Thanks @alexbrault for openlayers/openlayers#4457 and any future contributions you can make.
ahocevar added a commit that referenced this pull request Jan 10, 2016
Add color option to ol.style.Icon
@ahocevar ahocevar merged commit d05b519 into openlayers:master Jan 10, 2016
@@ -23,6 +23,7 @@ var iconStyle = new ol.style.Style({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
color: '#8959A8',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nicer to have a dedicated example that shows what this option should be used for. We have a bad tendency to continue modifying examples that started out simple until they become overly complex (or just ugly). And I think this particular example looked nicer before the color option was added (same goes for opacity).

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll submit a PR to fork the example

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.

5 participants