Methods
Initialization Example:
// create the Layers node and set parameters
const instance = $FSI.createNode("fsi-layers", {
id: "myLayers",
width: '600px',
height: '400px',
skin: 'white',
debug: true
})
document.body.appendChild(instance);
// create the layers root
const layersRoot = $FSI.createNode("fsi-layers-root", {});
instance.appendChild(layersRoot);
// add a layers group
const layersContainer = $FSI.createNode("fsi-layer-group", {
name: "container",
width: '100%',
height: '100%'
});
layersRoot.appendChild(layersContainer);
addGroup
addGroup(parentGroupName, [parameters], [index])
Adds a new group.
instance.addGroup("someExistingGroup", {"name": "my new Group"});
Example
addLayer
addLayer(parentGroupName, [parameters], [index], content)
Adds a new layer.
instance.addLayer("_root", {"name": "myLayer", "src": "images/foo.tif", "left": "30%"});
// or
instance.addLayer("targetGroup", {name: "new layer"}, "some existing layer or group");
Example
addListener
const success = addListener(listenerName, fn, iScope)
Calls a specific listener. Listeners which are added via addListener(), remain valid when changeConfig() is called.
const success = instance.addListener('onRenderLayer',
(layer) => {
// code
})
Example
Consult Callbacks for an overview of all available listeners.
debugError
debugError()
Returns the corresponding viewer error messages in the console.
instance.debugError()
Example
debugLog
debugLog()
Returns the corresponding viewer debug log messages in the console.
instance.debugLog()
Example
debugWarn
debugWarn()
Returns the corresponding viewer debug warn messages in the console.
instance.debugWarn()
Example
deselect
deselect(layerName, layerName, ...)
Deselects selected layers.
instance.deselect('yourLayer')
Example
destroy
destroy()
Destroys the FSI Layers instance leaving the empty container div only.
instance.destroy()
Example
dumpLayers
dumpLayers()
Shows all layers in the browser console
instance.dumpLayers()
// return example
/*
FSI Layers [myFSILayers]> Current Layers:
0: [Group] container
{name: 'container', right: 'centered', bottom: 'centered', width: '100%', height: '100%'}
children of 'container':
0: [Layer] 'background'
{name: 'background', src: 'images/samples/layers/background.png', width: '100%', height: '100%', left: '0'}
1: [Group] foreground
{name: 'foreground', width: '400rpx', height: '400rpx', refwidth: '400', refheight: '400'}
children of 'foreground':
0: [Layer] 'tree'
{name: 'flower', width: '60%', height: '60%', opacity: '0.5', hidden: '0'}
1: [Layer] 'house'
{name: 'vase', width: '10%', height: '10%', top: '10%', left: '10%'}
*/
Example
dumpListeners
dumpListeners()
Lists all listeners in the console and how often they were called.
instance.dumpListeners()
Example
duplicate
const success = duplicate(layerName, newLayerName, withChildren)
Duplicates a certain layer or layer group.
const success = instance.duplicate('background','new background', true)
Example
getBuild
const version = getBuild()
Returns a string containing the FSI Layers software build number.
const version = instance.getBuild()
Example
getChildNameAt
const name = getChildNameAt(groupName, index)
Returns name of a child layer.
const success = instance.getChildNameAt('foreground', 1)
Example
getConfigValue
const value = getConfigValue(name)
Returns the value of any configuration parameter addressed with `name`.
const value = instance.getConfigValue('useDevicePixelRatio')
Example
getHTML
const code = getHTML()
Returns the HTML code of all current groups and layers.
const code = instance.getHTML()
Example
getInitDone
const success = getInitDone()
Returns if the initialization process is done.
const success = instance.getInitDone()
Example
getInstanceID
const getID = getInstanceID()
Returns the number of the viewer object.
const getID = instance.getInstanceID()
Example
getInstanceName
const name = getInstanceName()
Returns the type of the viewer (e.g. FSI Layers) and the id attribute of the viewer object.
const name = instance.getInstanceName()
Example
getSelectedLayerNames
const name = getSelectedLayerNames()
Returns the names of the currently selected layers.
const name = instance.getSelectedLayerNames()
Example
getLayerNames
const name = getLayerNames()
Returns an information object for each layer and group.
const name = instance.getLayerNames()
Example
getProperties
const prop = getProperties(layerName)
Returns the properties of a specific layer.
const prop = instance.getProperties('vase')
Example
getParameters
const param = getParameters()
Returns an object containing all parameters set via javascript or custom tag attributes.
const param = instance.getParameters()
// return example:
/*
{
debug: "1"
id: "myFSILayers"
onready: "ready"
usedevicepixelratio: "true"
}
*/
Example
getTypeOf
const type = getTypeOf(layerName)
Returns the type of a layer.
const prop = instance.getTypeOf('background')
Example
getVersion
const version = getVersion()
Returns a string containing the FSI Layers software version number.
const version = instance.getVersion()
Example
hide
hide(layerName, layerName, ...)
Hides specified layers.
instance.hide('yourLayer')
instance.render()
Example
hideSelected
hideSelected()
Hides all currently selected layers.
instance.hideSelected()
instance.render()
Example
init
const success = init(id, options, debug)
Initialises the chosen viewer element.
This method is only needed if a FSI Layers has not been started automatically (default).
const success = instance.init('fsi-123', {
usedevicepixelratio: true,
debug: true
}, true)
Example
move
const success = move(layerName,targetGroup,targetIndex)
Moves the specified layer to the specified target group.
const success = instance.move('vase','background', 2)
Example
printAPI
printAPI()
Shows all API methods, listeners and button IDs in the console in alphabetical order.
instance.printAPI()
Example
remove
const success = remove(layerName, layerName, ...)
Removes specific layers.
const success = instance.remove('vase','flower')
instance.render()
Example
removeListener
const success = removeListener(listenerName, fn)
Removes a specific listener.
const success = instance.removeListener('onRenderLayerDone', yourFunction)
Example
removeSelected
const success = removeSelected()
Removes all currently selected layers.
const success = instance.removeSelected()
instance.render()
Example
render
render()
Render the current state of FSI Layers. Must be called after changing properties or adding/removing layers.
instance.render()
Example
select
select(layerName, layerName, ...)
Selects specified layers.
instance.select('yourLayer')
Example
setContent
const success = setContent(layerName, content)
Sets the content in background.
const success = instance.setContent('yourLayer', 'Your content goes here')
Example
setHTML
setHTML(HTMLCode)
Resets FSI layers and renders the fsi-layers and fsi-layer-group tags as given in the HTMLCode argument.
instance.setContent('<fsi-layers useDevicePixelRatio="true" debug="1"><fsi-layer-group></fsi-layer-group>...</fsi-layers>')
Example
setProperties
const success = setProperties(layerNames, properties)
Sets the properties of the specified layers.
const success = instance.setProperties(["layer1", "layer2"], {"left":"20%", "hidden":false})
Example
setPropertiesOfSelected
const success = setPropertiesOfSelected(properties)
Sets the properties of all selected layers.
const success = instance.setPropertiesOfSelected({"left":"20%", "hidden":false});
Example
show
show(layerName, layerName, ...)
Shows specified layers if hidden before.
instance.show('yourLayer')
instance.render()
Example
showSelected
showSelected()
Shows selected layers if hidden before.
instance.showSelected()
instance.render()
Example
testAPIListenersStart
testAPIListenersStart()
Starts the API test and shows all called listeners and the parameters which they return.
instance.testAPIListenersStart()
Example
testAPIListenersStop
testAPIListenersStop()
Stops the API test.
instance.testAPIListenersStop()
Example
toggleInfo
toggleInfo()
Toggles the info (name, dimensions, clipping state) and direction arrows of all layers and groups.
instance.toggleInfo()
Example
traceConfigValue
const show = traceConfigValue(strName)
Traces a config value and enables you to see where (by parameter/attribute, in config files, the _default.xml, etc) a specific value is set.
const show = instance.traceConfigValue('useDevicePixelRatio')
// return example:
// Tracing parameter "useDevicePixelRatio"
// By Parameter/Attribute:
// true
// RESULT:
// useDevicePixelRatio = "true"
Example