Callbacks
You can define callback functions to react on events fired by assigning methods to the FSI Viewer instance.
Refer to the appropriate chapter to learn how to implement callbacks.
The following callback methods exist:
on3DWorldChanged
on3DWorldChanged(data)
Called each time the 3D world parameters like rotation or dimension change. `data.projection` provides access to the three.js objects (camera, scene, renderer and objects). `data.scenes` contains information about the FSI Viewer scenes and scene sets.
instance.addListener('on3DWorldChanged', (data) => {
// 3D World changes
myFunc(data)
})
Example
onAfterReady
onAfterReady()
Calls an action after the instance is ready.
instance.addListener('onAfterReady', () => {
// after instance is ready
doReallyGoodThings()
})
Example
onAfterRegisterExternalButton
onAfterRegisterExternalButton(button, buttonID, buttonPresent)
Removes inactive buttons from the menu bar if you are using a custom skin.
instance.addListener('onAfterRegisterExternalButton', (button, buttonID, buttonPresent) => {
// external button registered
myFunc(button, buttonID, buttonPresent)
})
Example
onAnimationComplete
onAnimationComplete()
Called when a spin and/or zoom animation finishes.
instance.addListener('onAnimationComplete', () => {
// animation complete
doReallyGoodThings()
})
Example
onAnimationStart
onAnimationStart()
Called when a spin and/or zoom animation starts.
instance.addListener('onAnimationStart', () => {
// animation starts
doReallyGoodThings()
})
Example
onChangeConfig
onChangeConfig(cfgFile, parameters)
Called as soon as the config is changed.
instance.addListener('onChangeConfig', (cfgFile, parameters) => {
// config changed
myFunc(cfgFile, parameters)
})
Example
onChangeImage
onChangeImage(parameters, view)
Calls an action as soon as the viewed image changes.
instance.addListener('onChangeImage', (parameters, view) => {
// image changed
myFunc(parameters, view)
})
Example
onClickDemoMode
onClickDemoMode(url, targetFrame)
This optional callback function can be used to call an action as soon as the demo mode instance is clicked on. (You need to return `false` in order to prevent default action!)
instance.addListener('onClickDemoMode', (url, targetFrame) => {
// click on demo mode instance
myFunc(url, targetFrame)
})
Example
onConfigsReady
onConfigsReady(config)
Called as soon as the configuration is loaded.
instance.addListener('onConfigReady', (config) => {
// config loaded
myFunc(config)
})
Example
onDataComplete
onDataComplete()
Calls an action while the configuration data loading is completed. Images/videos are not loaded yet at this point.
instance.addListener('onDataComplete', () => {
// data complete
doReallyGoodThings()
})
Example
onDestroy
onDestroy()
Called as soon as the viewer is destroyed.
instance.addListener('onDestroy', () => {
// instance is destroyed
doReallyGoodThings()
})
Example
onEnterDemoMode
onEnterDemoMode()
Call an action as soon as the demo mode is entered.
instance.addListener('onEnterDemoMode', () => {
// demo mode is entered
doReallyGoodThings()
})
Example
onExitDemoMode
onExitDemoMode()
Call an action as soon as the demo mode is left.
instance.addListener('onExitDemoMode', () => {
// leave demo mode
doReallyGoodThings()
})
Example
onFullScreen
onFullScreen(set)
This optional callback function can be used to call an action when `FullScreen` mode is enabled or disabled.
instance.addListener('onFullScreen', (set) => {
// FullScreen enabled/disabled
myFunc(set)
})
Example
onHotspotEvent
onHotspotEvent(action, hotspotID, hotspotAttribute, content, event)
Calls an action as soon as a certain Hotspot event occurs.
instance.addListener('onHotspotEvent', (action, hotspotID, hotspotAttribute, content, event) => {
// HotSpot event triggered
myFunc(action, hotspotID, hotspotAttribute, content, event)
})
Example
onInit
onInit(parameters)
Called as soon as the viewer is initialized.
instance.addListener('onInit', (parameters) => {
// config loaded
myFunc(parameters)
})
Example
onInit3D
onInit3D(projection)
Called as soon as the viewer is initialized.
instance.addListener('onInit3D', (projection) => {
// 3D world loaded
myFunc(projection)
})
Example
onInitFailed
onInitFailed(reason)
Called when the initialization is failed. This could happen if e.g. an image cannot be loaded or the dimensions of an image cannot be requested. The listener returns a string with the reason why the initialization failed.
instance.addListener('onInitFailed', (reason) => {
// init fails
myFunc(reason)
})
Example
onInitMenu
onInitMenu()
Calls an action when the menu is built (after all buttons are added).
instance.addListener('onInitMenu', () => {
// menu is ready
doReallyGoodThings()
})
Example
onLanguageData
onLanguageData(items)
Calls an action when the language data is loaded.
instance.addListener('onLanguageData', (items) => {
// language data loaded
myFunc(items)
})
Example
onMeasureChange
onMeasureChange(length, rotation, label)
Calls an action as soon the measurement is changed.
instance.addListener('onMeasureChange', (length, rotation, label) => {
// measure changes
myFunc(length, rotation, label)
})
Example
onMeasureEnd
onMeasureEnd(length, rotation, label, coords)
Calls an action as soon as the measurement ends.
instance.addListener('onMeasureEnd', (length, rotation, label, coords) => {
// measure ends
myFunc(length, rotation, label, coords)
})
Example
onMeasureShow
onMeasureShow(show)
Calls an action as soon as the measurement is displayed.
instance.addListener('onMeasureShow', (show) => {
// Measure is visible
myFunc(show)
})
Example
onMeasureStart
onMeasureStart(length, rotation, label)
Calls an action as soon the measurement is started.
instance.addListener('onMeasureStart', (length, rotation, label) => {
// measure starts
myFunc(length, rotation, label)
})
Example
onMeasureUpdateRatio
onMeasureUpdateRatio(lengthFactor, imageRealWidth, imageWidth)
Calls an action as soon as the measurement reference is updated due to a change of the original image ratio.
instance.addListener('onMeasureUpdateRatio', (lengthFactor, imageRealWidth, imageWidth) => {
// measure ratio updated
myFunc(lengthFactor, imageRealWidth, imageWidth)
})
Example
onMenuButtonEnabled
onMenuButtonEnabled(buttonID, null, enable)
Calls an action when a button is enabled or disabled.
instance.addListener('onMenuButtonEnabled', (buttonID, null, enable) => {
// button enabled/ disabled
myFunc(buttonID, null, enable)
})
Example
onMenuButtonMouseDown
onMenuButtonMouseDown(buttonID, evt)
Calls an action when the mouse pointer is over the element and the mouse button is pressed.
instance.addListener('onMenuButtonMouseDown', (buttonID, evt) => {
// button mouse down
myFunc(buttonID, evt)
})
Example
onMenuButtonPressed
onMenuButtonPressed(buttonID, evt)
Sets an action that starts when a button is pressed.
instance.addListener('onMenuButtonPressed', (buttonID, evt) => {
// button pressed
myFunc(buttonID, evt)
})
Example
onMenuButtonReleased
onMenuButtonReleased(buttonID, evt)
Sets an action that starts when a button is released.
instance.addListener('onMenuButtonReleased', (buttonID, evt) => {
// button released
myFunc(buttonID, evt)
})
Example
onMenuButtonClicked
onMenuButtonClicked(buttonID, evt)
Sets an action that starts when a button is clicked.
instance.addListener('onMenuButtonClicked', (buttonID, evt) => {
// button clicked
myFunc(buttonID, evt)
})
Example
onMenuButtonSetPressed
onMenuButtonSetPressed(pressed)
Called as soon as the button is set to `pressed`.
instance.addListener('onMenuButtonSetPressed', (pressed) => {
// button set to pressed
myFunc(pressed)
})
Example
onMenuDestroy
onMenuDestroy()
Called if the menu is destroyed.
instance.addListener('onMenuDestroy', () => {
// menu is destroyed
doReallyGoodThings()
})
Example
onMenuEnabled
onMenuEnabled(enabled)
Called if the menu is enabled/disabled.
instance.addListener('onMenuEnabled', (enabled) => {
// menu enabled
myFunc(enabled)
})
Example
onMenuReady
onMenuReady()
Sets an action when the menu is ready (after all buttons are added).
instance.addListener('onMenuReady', () => {
// menu is ready
doReallyGoodThings()
})
Example
onMouseModeChanged
onMouseModeChanged(mouseMode)
Calls an action when the mouse mode is changed.
instance.addListener('onMouseModeChanged', (mouseMode) => {
// mouse mode changes
myFunc(mouseMode)
})
Example
onProgress
onProgress(percent)
Can be called while the loading progresses.
instance.addListener('onProgress', (percent) => {
// progress
myFunc(percent)
})
Example
onReady
onReady()
Called as soon as the instance is ready.
instance.addListener('onReady', () => {
// instance is ready
doReallyGoodThings()
})
Example
onRegisterExternalMenuButtons
onRegisterExternalMenuButtons()
Calls an action as soon as external menu buttons are registered.
instance.addListener('onRegisterExternalMenuButtons', () => {
// menu button registered
doReallyGoodThings()
})
Example
onReset
onReset()
Calls an action when the configuration is changed.
instance.addListener('onReset', () => {
// config is reset
doReallyGoodThings()
})
Example
onResize
onResize(width, height, done, fullScreen)
Called as soon as the instance is resized.
instance.addListener('onResize', (width, height, done, fullScreen) => {
// resize
myFunc(width, height, done, fullScreen)
})
Example
onSkinChanged
onSkinChanged(currentSkin, beforeSkin)
Called when the skin class is changed.
instance.addListener('onSkinChanged', (currentSkin, beforeSkin) => {
// skin class is changed
myFunc(currentSkin, beforeSkin)
})
Example
onStartDragging
onStartDragging(inNavWindow)
Calls an action when the user starts dragging the image.
instance.addListener('onStartDragging', (inNavWindow) => {
// dragging starts
myFunc(inNavWindow)
})
Example
onStopDragging
onStopDragging(inNavWindow)
Calls an action when the user stops dragging the image.
instance.addListener('onStopDragging', (inNavWindow) => {
// dragging stops
myFunc(inNavWindow)
})
Example
onViewChanged
onViewChanged(view)
Calls an action as soon as the viewed image section changes.
instance.addListener('onViewChanged', (view) => {
// viewed image section changes
myFunc(view)
})
Example
onZoomChanged
onZoomChanged(scale, scaleMax, percent)
Called each time the magnification level change is finished.
instance.addListener('onZoomChanged', (scale, scaleMax, percent) => {
// zoom changed
myFunc(scale, scaleMax, percent)
})
Example
onZoomChanging
onZoomChanging(scale, scaleMax, percent, preliminary)
Called each time while magnification level changes.
instance.addListener('onZoomChanging', (scale, scaleMax, percent, preliminary) => {
// zoom currently changes
myFunc(scale, scaleMax, percent, preliminary)
})
Example