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

Move gradient and pattern fills with the view #5950

Merged
merged 1 commit into from
Oct 13, 2016

Conversation

ahocevar
Copy link
Member

Opened for discussion.

Currently, when using a gradient or pattern to fill polygons, gradient and pattern won't change their position when panning/rotating the map. See https://openlayers.org/en/master/examples/canvas-gradient-pattern.html.

To change this, I have added a moveWithView option to ol.style.Fill. When set to true, fills will move and rotate with the view. This is especially useful for pattern fills, as can be seen here:

moveWithView: false:
oct-11-2016 18-09-52

moveWithView: true:
oct-11-2016 18-12-29

Any opinions on whether this is the way to go, or if we should solve this in a different way?

@marcjansen
Copy link
Member

I love the effect! And the name makes sense as does the place where you suggest to set it. I like it!

@marcjansen
Copy link
Member

And can we somehow get the same with the gradient or am I missing sth.?

@ahocevar
Copy link
Member Author

And can we somehow get the same with the gradient or am I missing sth.?

That would require more changes to the example (different start and end coordinates for the gradient), but should also work with the new option. I did not apply it to the gradient because I don't see much use in filling polygons with a gradient.

@bartvde
Copy link
Member

bartvde commented Oct 11, 2016

I wonder if the current behaviour is needed at all, or if we should just make this the default?

@marcjansen
Copy link
Member

Generally I agree, Bart. Why not add the option and default it to true? That would be a behavioural change but easily revertable by our users. Though I doubt many actually use this feature.

@tschaub
Copy link
Member

tschaub commented Oct 11, 2016

I'd be tempted to call it a bug fix (instead of exposing an option).

@ahocevar ahocevar force-pushed the fill-movewithview branch 2 times, most recently from 1492eec to c29dee5 Compare October 12, 2016 16:21
@ahocevar
Copy link
Member Author

I updated the pull request according to the suggestions and made the new behavior the default, without a new option to change to the previous behavior. I also changed the example to use a per-feature gradient instead of a global one, which probably makes more sense:

oct-12-2016 18-16-38

@marcjansen
Copy link
Member

Very nice, especially the pixelRatio usage in the example. The explanation there could probably have one sentence about that, but I'll leave it up to you.

@ahocevar ahocevar changed the title Add option to move fills with the view Move gradient and pattern fills with the view Oct 12, 2016
Copy link
Member

@bartvde bartvde left a comment

Choose a reason for hiding this comment

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

Minor review comments, looks good otherwise. Thanks, this is an exciting change.

canvas.height = 11 * pixelRatio;
// white background
context.fillStyle = 'white';
context.fillRect(0, 0, 11 * pixelRatio, 11 * pixelRatio);
Copy link
Member

Choose a reason for hiding this comment

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

minor but could use canvas.width and canvas.height here

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

* panning or rotating. Default is `false`.
* @type {boolean}
*/
olx.style.FillOptions.prototype.moveWithView;
Copy link
Member

Choose a reason for hiding this comment

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

not needed anymore right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

@@ -208,15 +208,18 @@ ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel = function(
};


ol.renderer.canvas.TileLayer.prototype.renderTileImage = function(replayContext, frameState, tile, tileGrid, tilePixelRatio, skippedFeatureUids) {

};
Copy link
Member

Choose a reason for hiding this comment

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

why is this empty function needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Accidently committed, part of my next pull request 😄 - removed.

@ahocevar ahocevar force-pushed the fill-movewithview branch 2 times, most recently from dcfdf41 to 31532ba Compare October 13, 2016 07:27
@ahocevar
Copy link
Member Author

Thanks for the comments and reviews!

@ahocevar ahocevar merged commit 74450f4 into openlayers:master Oct 13, 2016
@ahocevar ahocevar deleted the fill-movewithview branch October 13, 2016 07:41
ahocevar added a commit to ahocevar/openlayers that referenced this pull request Oct 14, 2016
@ahocevar ahocevar mentioned this pull request Oct 14, 2016
tchandelle pushed a commit to tchandelle/openlayers that referenced this pull request Oct 17, 2016
This pull request was closed.
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.

4 participants