-
-
Notifications
You must be signed in to change notification settings - Fork 593
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
Add TiledImage.fitInBounds method. #888
Conversation
Looks lovely! I'm down with updating OverlayPlacement as you suggest. I suppose the only risk is if people have serialized the values (or plan to in the future, since the new values don't lend themselves to that)... not sure if that's a likely scenario. As for adding it to addTiledImage, I suppose we can have new image spec properties: |
Good point. I found that post http://stijndewitt.com/2014/01/26/enums-in-javascript/ to have the best of both worlds. And it will be 100% compatible with the current implementation.
I am willing to add it. Right now, I am adding the images at an approximate location before fixing it in the |
That sounds like a great plan for the enums! ... and sure, let's add the new properties to addTiledImage. |
Serializing overlay placement is something that I am planning on doing and seems like it would be a common requirement. I don’t know about current uses. Couldn’t you just assign the indicated values to the placement objects, as in: 18, 36, 24, 12, 10, 9, 11, 21, 22 for CENTER through LEFT and then add functions to the placement object, as in isLeft(placement), isHorizontallyCentered(placement), isRight(... These functions could use a simple bitwise and to return the desired binary result. That way you can easily serialze the overlay placement value and also get your binary values. You could also put a quick check for the old values before the “bitwise and” so that those functions could also handle the old values 0-9. |
Sorry: “old values 0-9.” s/b “old values 0-8.” David W. Rogers From: Rogers, David W Ø I suppose the only risk is if people have serialized the values (or plan to in the future, since the new values don't lend themselves to that)... not sure if that's a likely scenario. Serializing overlay placement is something that I am planning on doing and seems like it would be a common requirement. I don’t know about current uses. Couldn’t you just assign the indicated values to the placement objects, as in: 18, 36, 24, 12, 10, 9, 11, 21, 22 for CENTER through LEFT and then add functions to the placement object, as in isLeft(placement), isHorizontallyCentered(placement), isRight(... These functions could use a simple bitwise and to return the desired binary result. That way you can easily serialze the overlay placement value and also get your binary values. You could also put a quick check for the old values before the “bitwise and” so that those functions could also handle the old values 0-9. DavidDavid W. Rogers From: Ian Gilman [mailto:notifications@github.com] Looks lovely! I'm down with updating OverlayPlacement as you suggest. I suppose the only risk is if people have serialized the values (or plan to in the future, since the new values don't lend themselves to that)... not sure if that's a likely scenario. As for adding it to addTiledImage, I suppose we can have new image spec properties: fitBounds and fitBoundsPlacement and pass those through (making sure along the way that people don't pass both x and fitBounds, for instance). Of course the image spec options are already plentiful, so I'm hesitant to add more. On the other hand, it does seem like a common scenario. — |
That is an option as well. However, I am pretty bad with bitwise operations. How do you go about choosing the values and the operators? Note that it will break again any serialization people currently may have been doing but I am planning on doing so anyway because OverlayPlacement.CENTER is currently 0. This is dangerous because in the following example, if placement is set to CENTER, it will be overwritten by TOP_LEFT. function myFunc(placement) {
placement = placement || OverlayPlacement.TOP_LEFT;
} |
My bitwise operators are good - my javascript is newbie... :-) The bitwise operations would be done against a "private" set of constants:
|
The constants would be more like they are now - just with different values:
|
I added the clipping handling. It should be ready to merge. |
@avandecreme Awesome, looks great! |
I added a new "enum"
Placement
which is very similar to OverlayPlacement but with the added functionality to have handy boolean values.I am thinking of replacing https://github.com/openseadragon/openseadragon/blob/master/src/overlay.js#L54-L64 by
$.OverlayPlacement = $.Placement
. It should be backward compatible provided people did not use the previously assigned numbers.It would be nice to be able to set the bounds directly from the constructor (and consequently from
viewer.addTiledImage
) but it doesn't look easily doable. Suggestions welcome :)