-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Draw colored rectangle when the tile is not yet loaded #635
Draw colored rectangle when the tile is not yet loaded #635
Conversation
} | ||
|
||
if ( typeof fillStyle === "function" ) { | ||
this.context.fillStyle = fillStyle(this.context); |
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.
What's the purpose of passing the context into the function?
I wonder if there are other things worth passing into the function. For instance, we could pass in the TiledImage (in which case this line would probably happen in tiledimage.js), in case someone used the same function for multiple TiledImages but still wanted to differentiate between them.
What do you think? Anything else?
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.
I passed the context into the function to be able to draw a gradient or a image like this:
placeholderFillStyle: function(context) {
var gradient = context.createLinearGradient(0, 0, context.canvas.width, 0);
gradient.addColorStop(0,"black");
gradient.addColorStop(1,"red");
return gradient;
}
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.
Gotcha; I didn't realize the context was necessary for that. Good to have then.
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.
I still think it would be useful to pass the TiledImage into the callback. What do you think?
This is a great start! |
Thanks a lot, i will try to do the changes as soon as possible. Do you have a suggestion of the method name that returns the rect? It should go into the tiledImage or, and not into the drawer? (you said drawer in the issue) |
I'm thinking it would be Drawer.viewportToDrawerRectangle(). We'd probably also want a viewportToDrawerPoint(). The Drawer has a reference to the Viewport, so it should have everything it needs. |
Could you look over the documentation? I know its very bad, but im not good at writing docs :( |
@@ -1217,6 +1218,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, | |||
|
|||
this._hideMessage(); | |||
|
|||
$.extend ( true, options, { |
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.
Doing this means the overall setting would override the setting passed directly into the function. It should be the other way around. You could swap options
and the object literal and assign the result back to options, or go with something like:
if (options.placeholderFillStyle === undefined) {
options.placeholderFillStyle = _this.placeholderFillStyle;
}
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.
Oh damn... Thanks a lot, i had not tried this functionality yet... I was very confused when passing the options 😆
All the docs look good :) |
I hope I have understood correctly the proposals. The drawer is now saving and restoring the context in the |
What could i do with the information of the tiledImage? Would you pass only the tiledImage instread of the context, or both? To style every tiledImage different you can pass the function directly in |
What if I wanted to have a blue gradient for one of my tiledImages and a green gradient for another one? One solution would be to pass a different function for each when you first created them, but if you were relying on the single placeholderFillStyle that's attached to the viewer, you would need a way to distinguish between the different tiledImages. One way would be to pass the tiledImage into the fillStyle function. This serves a different purpose than the context, so you would pass them both. Or we could say if you want different gradients for different tiledImages, you always need to pass different functions. At any rate, I figure we should consider that scenario so we know what the proper way to handle it is. |
Ok i understand what you mean, you want me to change it to |
How about |
Hi, its done! I moved the fillStyle to the tiledImage, seemed cleaner to me. |
Looks beautiful! Thank you. I see on your checklist you still have some testing to do? |
Oh forgot to check it, i already tested it in my project, but i havent deployed it yet, just offline. I will upgrade it tomorrow. Offline it worked great :) |
One last thought... What you think about renaming |
Yes, Drawer.drawRectangle sounds good. |
Great, its done :) |
Lovely. Are we ready to merge it or do you have more testing to do? |
No i think its ready :) Im currently at home and I have the viewer in the office. Tomorrow i will upgrade OpenSeadragon ;) |
Cool. I'm glad to have this feature in; thanks for tackling it. :-) |
Draw colored rectangle when the tile is not yet loaded
I suspect that the opacity is varying. Line 261 in 0d05614
Could you try restoring it once the tile is drawn? |
Yes this line seems to cause the issue. When commenting |
Indeed...as each new tile comes in we fade it over top of the older tiles. However we only draw the placeholder color if no tile exists. We should continue to draw that color until the low res tile has completely faded in. Another solution would be to always draw the placeholder underneath everything, but that would negatively affect performance. So...the trick is to detect when we have our first tile but it hasn't fully faded in. One strategy would be to assume that if we have even one fully opaque tile that's enough, since we load the low res tiles first. If so, you could add a new flag, say openseadragon/src/tiledimage.js Line 583 in 0d05614
...and set it to true when you find an opaque tile, here: openseadragon/src/tiledimage.js Line 1027 in 0d05614
...and then test it instead of lastDrawn.length here: openseadragon/src/tiledimage.js Line 1173 in 0d05614
|
@philipgiuliani Have you had a chance to work on the flickering issue yet? |
Here my first try to draw a colored placeholder rectangle when the tile is not yet loaded. This is currently not building because I re-defined the box, topLeft and size var. But its buildable as minbuild. I used the included collections demo to test it. Will test it soon in my other project.
There is a lot of duplication with the setClip method.
Tasks:
placeholderFillStyle
to draw a gradient or image instead of a single colorCloses #623