-
Notifications
You must be signed in to change notification settings - Fork 30
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
Mirroring support #439
Merged
Merged
Mirroring support #439
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d3342c
Add mirroring control
barrettMCW 5680fcc
Merge branch 'master' of https://github.com/barrettMCW/omero-iviewer
barrettMCW d7d6ba5
remove debug stuff
barrettMCW 668955f
fix python error
barrettMCW b517024
string not bool
barrettMCW d8ca54b
add mirror to globals
barrettMCW 4d7c531
don't reset mirror initparam
barrettMCW 0b9279d
Merge pull request #1 from ome/master
barrettMCW df603ac
fix mirror configname
barrettMCW b90c7c3
mirror saved viewport
barrettMCW 788a6eb
Merge branch 'master' of https://github.com/barrettMCW/omero-iviewer
barrettMCW 19211b6
fixed birdseye
barrettMCW 8908754
account for rotation
barrettMCW 3414bb0
cached mirroring
barrettMCW 278dd54
add mirror initparams
barrettMCW 222c510
convert string
barrettMCW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import {listen} from 'ol/events'; | ||
import EventType from 'ol/events/EventType'; | ||
import Control from 'ol/control/Control'; | ||
import {CLASS_UNSELECTABLE, CLASS_CONTROL } from 'ol/css'; | ||
|
||
export class Mirror extends Control { | ||
/** | ||
* @constructor | ||
* @param {ol.Map=} map openlayers map. | ||
* @param {ol.control.FlipOptions=} opt_options options. (className, target) | ||
*/ | ||
constructor(opt_options) { | ||
var options = opt_options ? opt_options : {}; | ||
|
||
var element = document.createElement('div'); | ||
super({ | ||
element: element, | ||
target: options.target | ||
}); | ||
|
||
/** | ||
* @type {string} | ||
* @private | ||
*/ | ||
this.class_name_ = | ||
options.className === 'string' ? options.className : 'ol-flip'; | ||
|
||
/** | ||
* @type {MapBrowserPointerEvent} | ||
* @private | ||
*/ | ||
this.ref_ = null | ||
|
||
/** | ||
* @type {View} | ||
*/ | ||
this.view = null | ||
|
||
var cssClasses = | ||
this.class_name_ + ' ' + CLASS_UNSELECTABLE + ' ' + | ||
CLASS_CONTROL; | ||
|
||
element.className = cssClasses; | ||
var buttonGroup = document.createElement('div'); | ||
buttonGroup.className = "btn-group btn-group-sm ol-flip-buttons"; | ||
buttonGroup.appendChild(this.addFlipButton(false)); | ||
buttonGroup.appendChild(this.addFlipButton(true)); | ||
element.appendChild(buttonGroup); | ||
} | ||
|
||
/** | ||
* Adds both, flip vertical and horizontal buttons | ||
* @param {boolean} flip_vertical the vertical flip button is added if true, otherwise horizontal | ||
* @private | ||
*/ | ||
addFlipButton(flip_vertical) { | ||
if (typeof flip_vertical !== 'boolean') flip_vertical = false; | ||
|
||
var title = 'Flip ' + (flip_vertical ? 'vertical' : 'horizontal'); | ||
var element = document.createElement('button'); | ||
element.className = | ||
this.class_name_ + (flip_vertical ? '-vertical glyphicon-resize-vertical' : '-horizontal glyphicon-resize-horizontal') + | ||
" btn btn-default glyphicon ol-flip-button"; | ||
element.setAttribute('type', 'button'); | ||
element.title = title; | ||
|
||
listen(element, EventType.CLICK, this.handleClick_, this); | ||
|
||
return element; | ||
} | ||
|
||
init(){ | ||
this.view = this.getMap().getView() | ||
|
||
this.view.flipX = false | ||
this.view.flipY = false | ||
|
||
this.view.constrainCenter_ = this.view.constrainCenter | ||
this.view.constrainCenter = (center) => { | ||
let curCenter = this.view.getCenter() | ||
if (this.view.flipX) { | ||
center[0] = curCenter[0]-(center[0]-curCenter[0]) | ||
} | ||
if (this.view.flipY) center[1] = curCenter[1]-(center[1]-curCenter[1]) | ||
return this.view.constrainCenter_(center) | ||
} | ||
|
||
// override getEventPixel to account for mirroring | ||
this.map_.getEventPixel = function (evt) { | ||
const viewportPosition = this.viewport_.getBoundingClientRect(); | ||
const eventPosition = | ||
//FIXME Are we really calling this with a TouchEvent anywhere? | ||
'changedTouches' in evt | ||
? /** @type {TouchEvent} */ (evt).changedTouches[0] | ||
: /** @type {MouseEvent} */ (evt); | ||
|
||
let x=eventPosition.clientX - viewportPosition.left | ||
let y=eventPosition.clientY - viewportPosition.top | ||
|
||
if (this.getView().flipX) x=viewportPosition.width-x | ||
if (this.getView().flipY) y=viewportPosition.height-y | ||
|
||
return [x,y] | ||
} | ||
} | ||
|
||
handleClick_(event) { | ||
if(this.view == null) this.init() | ||
// 0 axis if vertical ( flip y over x axis ) | ||
// 1 axis if hortizontal ( flip x over y axis ) | ||
event.preventDefault(); | ||
var viewport = this.getMap().getViewport().children[0] // (mirror just tiles) | ||
var axis = event.target.className.indexOf("ol-flip-vertical") !== -1 ? 0 : 1; | ||
|
||
// set desired transform and record in view | ||
let transform; | ||
if (axis == 0) { | ||
transform="scaleY(-1)" | ||
this.view.flipY=!(this.view.flipY) | ||
|
||
} else { | ||
transform="scaleX(-1)" | ||
this.view.flipX=!(this.view.flipX) | ||
} | ||
|
||
// if it is already mirrored remove mirror, otherwise add mirror | ||
viewport.style.transform = viewport.style.transform.includes(transform) ? | ||
viewport.style.transform.replace(transform, "") : | ||
viewport.style.transform + transform | ||
return true | ||
} | ||
|
||
} | ||
export default Mirror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You have a double underscore in
enable__mirror
which I think is why my config didn't work before.