-
Notifications
You must be signed in to change notification settings - Fork 116
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
Fix: Load annotator with the correct initial scale #256
Changes from 2 commits
7f661ea
7230510
a4541f8
f6933d4
4428f4b
b4ed7d8
e4a9f63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ class Annotator extends EventEmitter { | |
this.isMobile = data.isMobile; | ||
this.previewUI = data.previewUI; | ||
this.annotationModeHandlers = []; | ||
this.annotatedElement = this.getAnnotatedEl(this.container); | ||
} | ||
|
||
/** | ||
|
@@ -89,7 +90,6 @@ class Annotator extends EventEmitter { | |
* @return {void} | ||
*/ | ||
init() { | ||
this.annotatedElement = this.getAnnotatedEl(this.container); | ||
this.notification = new Notification(this.annotatedElement); | ||
|
||
const { apiHost, fileId, token } = this.options; | ||
|
@@ -106,7 +106,8 @@ class Annotator extends EventEmitter { | |
this.setupMobileDialog(); | ||
} | ||
|
||
this.setScale(1); | ||
const scale = annotatorUtil.getScale(this.annotatedElement); | ||
this.setScale(scale); | ||
this.setupAnnotations(); | ||
this.showAnnotations(); | ||
} | ||
|
@@ -236,10 +237,11 @@ class Annotator extends EventEmitter { | |
* Sets the zoom scale. | ||
* | ||
* @param {number} scale - current zoom scale | ||
* @return {void} | ||
* @return {Annotator} Annotator instance returned for chaining | ||
*/ | ||
setScale(scale) { | ||
this.annotatedElement.setAttribute('data-scale', scale); | ||
return this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the benefits of chaining, but since we already have access to the annotator instance, what is the benefit here over just calling My thought process is that it goes against any coding paradigms we currently follow, in Preview There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anytime you can chain you will have access to the instance. Its just for readability so you can chain calls in a clear readable fashion.
As opposed to
Very minute semantic idea, although I understand it is probably not a good idea to throw it into the mix now. Essentially your functions will build properties of your instance and a few getter methods will actually display the transformed properties. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When in Rome :) Good discussion around patterns here but since we don't utilize that sort of chaining in Preview, please add it in a feature change. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,7 +344,10 @@ class BaseViewer extends EventEmitter { | |
// Add a resize handler for the window | ||
document.defaultView.addEventListener('resize', this.debouncedResizeHandler); | ||
|
||
this.addListener('load', () => { | ||
this.addListener('load', (event) => { | ||
// this.scale set to 1 if event.scale does not exist | ||
({ scale: this.scale = 1 } = event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that's not how it works now, but wouldn't it make more sense if set scale set If so, then move to
and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally misread what you meant. Problem here is that setScale is in Annotator and the eventListener is in BaseViewer. Annotator does not have a Annotator.scale value. It gets its scale from data-scale. In addition, BaseViewer.initAnnotations() both sets up the scale listener and the annotator. At this point the Annotator needs to know the scale value which cannot be known through any method other than the 'load' event. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make this more clear by doing
since this.scale is set to 1 by the property default. |
||
|
||
if (this.annotationsPromise) { | ||
this.annotationsPromise.then(this.loadAnnotator); | ||
} | ||
|
@@ -653,6 +656,8 @@ class BaseViewer extends EventEmitter { | |
locale: location.locale, | ||
previewUI: this.previewUI | ||
}); | ||
|
||
this.annotator.setScale(this.scale); | ||
this.annotator.init(); | ||
|
||
// Disables controls during point annotation mode | ||
|
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.
Maybe throw an error here if a developer forgets to override getAnnotatotedEl() in their viewer specific annotator