News Examples Documentation Download Buy Forum Contact



XML Extensions


Third Party Software
for krpano

NOTE: This page is from an older version, see the latest version here.

krpano Plugin Interface Version 1.20.1

krpano provides a small and simple interface for developing own plugins. A plugin can be either a 'code-only' plugin that extends krpano with additional functionality or controls krpano and / or it can be a 'graphical-plugin' which shows or does something on the screen.

There are two types of plugins: The basic plugin-to-krpano and krpano-to-plugin interfaces are almost the same for HTML5 and Flash plugins, only system and language specific code is different.

The basic structure is that the plugin has these public functions, which will be called from krpano:
  • A registerplugin function - this function will be called from krpano when the plugin will be loaded. The function provides a krpano Interface Object and a krpano Plugin Object.
  • An unloadplugin function - when the plugin will be removed from krpano, then this function will be called. Here all elements and events that the plugin has added should be removed.
  • And optionally an onresize function to allow the plugin reacting on size changes of the plugin element.
The plugin itself can add custom functions or attributes to krpano just by adding / setting them directly to the krpano object or to the plugin object. For custom attributes that can be set from the xml there is additionally the registerattribute function - it allows adding an attribute with a default value while keeping the value from the xml. And the registerattribute function can be used to add setter/getter attributes - this are attributes which will cause automatically calling a get or set function when accessing the variable - this can be used to get notified when an attribute will been changed.

HTML5 Javascript Plugins

The krpano Javascript plugins are just plain Javascript code. Special tools for compiling or building are not necessary, but to reduce the filesize of the final plugin file compressing or minimizing the Javascript code is recommended.
Here an example plugin code with the basic structure for a krpano Javascript plugin:
test view raw download

Compress / Minimize the HTML5 Javascript Plugin Code

This step or part is optionally, but to reduce the filesize of the plugin, compressing or minizing the Javascript file is recommended. Good tools for that are the Google Closure Compiler, the YUI Compressor or other similar tools.

Both of the above tools can be used offline, but there are also online tools available:

Additionally the (minimized) Javascript files can be even more compressed and encrypted and protected by using the krpano Encrypt Tool.

Actionscript3 Flash Plugins

Flash plugins for the krpano Flash viewer can be build either with the free mxmlc compiler from the Flex SDK (recommended) or with Flash Professional CS.
Here an example plugin code with the basic structure for a krpano Flash plugin:
test view raw download

The krpano Plugin Interface

These are the interface functions of the plugin that will be called from krpano. In Flash/Actionscript3 these functions must be public functions of the startup Flash object.
In HTML5/Javascript these functions must be members of a globally defined function object named krpanoplugin. All code need to be within that function, everything outside will get stripped.
krpanoplugin.registerplugin(krpanointerface, pluginpath, pluginobject)
  • The registerplugin() function will be called when the plugin was loaded into krpano and is ready for usage.
  • Here the plugin can add / register attributes, functions, add graphical content to the plugin or to the viewer and do many things more.
  • Parameters that will be passed with the registerplugin() function:
    • krpanointerface
      The krpano Interface Object - this object provides access to interfacing functions and to the whole krpano data structure.
    • pluginpath
      A String with the 'full path' to the plugin object, e.g. "plugin[name]".
    • pluginobject
      The krpano Plugin Object - this object provides direct access to all plugin attributes and functions.

  • The unloadplugin() function will be called from krpano when plugin will be removed.
  • Here the plugin should remove all content that it has added (e.g. graphical objects, event listeners, timers, ...).

krpanoplugin.onresize(width, height) (optionally)
  • The onresize() function will be called when the plugin will be resized.
  • The parameters width and height are the new size in pixels.
  • Here the plugin can adjust or resize own graphical content.
  • The onresize() function can optionally return a Boolean value - when it returns true then krpano will try to scale the plugin automatically, when false will be returned then krpano will not scale the plugin.

krpano Interface Object

The 'krpano' object (the 'krpanointerface' parameter in the registerplugin call) is the direct interface to krpano. It provides direct access to the whole krpano structure and all functions there. All mapped xml nodes, arrays, objects and attributes can be accessed directly with it. Additionally it provides some functions for data access, action-code calling/executing and more:
krpano.set(variable, value)
  • Sets a variable to a given value.
  • When the variable or the path to it, don't exist then the variable and path will be created.
  • Works like the xml set() action.

  • Returns the value of a variable.
  • Returns 'null' when the variable doesn't exist., callerobject*)
  • Call action code to the krpano actions code.
    When the action system is currently not blocked, then the given actions will be directly executed.
  • actionscode = a String with one or more krpano actions.
  • callerobject (optionally) = the object that was calling the actions (e.g. the plugin object itself). This allowes direct access to the object attributes in the actions code, e.g. just set(x,1) instead of set(plugin[name].x,1).

krpano.trace(code, message)
  • Trace out messages to the krpano log.
  • code = numeric code of the message-type:
    • 0 = DEBUG message - will be only shown with enabled debugmode
    • 1 = INFO message
    • 2 = WARNING message
    • 3 = ERROR message - will also open the log automatically.
    • 4 = FATAL ERROR - this message will be shown in the middle of the viewer.

  • Resolves the krpano placeholders in the given path string.
  • Return value: the resolved path string.

krpano.loadFile(file, donecallback, errorcallback*)
  • Request to load a file as String in Javascript or as ByteArray in Flash.
  • donecallback and errorcallback - these functions will be called when the loading was successfully or has failed. The usage of the errorcallback is optionally.
    Both functions will be called with an Object as parameter - and this Object has these attributes:
    • rqurl
      The request url that was used on the loadFile call.
    • url
      The parsed and resolved url of the file.
    • data
      Javascript: The loaded file as String.
      Flash: The loaded file as ByteArray.
    • errmsg
      A boolean flag with the default value 'true' that indicates if krpano should show an automatic loading error message. Only for usage in the errorcallback function! Set it to 'false' to disable the default loading error message.

  • Functions for converting between screen and spherical coordinates.
  • Return value: an Object with x and y properties. The values of these properties can be NaN (Not a Number) when the conversion wasn't possible.

  • Functions for converting between spherical and XYZ 3D space coordinates
  • Return value:
    • spheretospace - an Object with x,y,z properties.
    • spacetosphere - an Object with h,v,depth properties.

krpano.customParsePath = function(url)
  • The customParsePath variable can be set to a custom Javascript function to do a custom filepath url parsing.
  • The function will get a filepath url that krpano will try to load as argument, and need to return the parsed and (optionally modified) filepath url.
  • All files loaded by krpano (except of the individual multiresoluion tiles) will get passed through that function.
  • Example:
    <action type="Javascript" autorun="preinit"><![CDATA[
      krpano.customParsePath = function(url)
        // load 'image2.jpg' instead of 'image1.jpg':
        if(url == "image1.jpg") url = "image2.jpg";
        return url;

krpano.customParseTilePath = function(url,cube,level,h,v,stereo,image)
  • The customParsePath variable can be set to a custom Javascript function to do a custom filepath url parsing for multiresoluion tiles.
  • The function will get a filepath url that krpano will try to load as argument, and need to return the parsed and (optionally modified) filepath url.
  • After that function the default krpano tile-url parsing will be done.
  • Parameters:
    • url - the base tile-url template.
    • cube - the cube side index, range 0-5, an index into the cubelabels values. Non-cubical panos will use the value 1 here.
    • level - the level index, range baseindex to N.
    • h, v - horizontal and vertical tile index, range baseindex to N.
    • stereo - stereo side, 0 or 1, an index into the stereolabels values.
    • image - the related xml <image> element as object.
  • Example: Custom Tile-URLs

krpano Plugin Object

The 'plugin' object (the 'pluginobject' parameter in the registerplugin call) it the internal representation of the xml <plugin> element. All plugin attriutes and actions are directly accessible by it.
Special plugin-related attributes of the 'plugin' object:

  • Flash - The Actionscript 3 Sprite object of the hotspot.
  • HTML5 - The HTML <div> element of the plugin object.
    Note - when using the plugin as hotspot, then the sprite object is only available when rendering the hotspot via CSS3D (see the renderer setting)!
  • The sprite object can be used for adding custom display elements (DisplayList elements in Flash, HTML DOM elements in HTML5) to the plugin itself.

plugin.videoDOM (HTML5 only)
  • A special attribute to allow the plugin providing a HTML5 video object for rendering.
  • The krpano viewer will use that video object for rendering when using the plugin as hotspots or as pano image (via url="plugin:video").
  • Setup: videowidth and videoheight attributes with the size of the video need to be added to plugin object, and once the video is ready for rendering the onvideoreadyCB function of the plugin be called. For all details please see the example source code of the videoplayer plugin.
  • Special usage: with some tricks it's also possible to use a HTML5 canvas object as video source. Use the canvas as videoDOM and add these 'faked' properties to it: readyState=4, videoWidth=canvas.width, currentTime=time or frame number (should change when the content changes).
Special plugin-related functions of the 'plugin' object:

plugin.registercontentsize(width, height)
  • Define the 'default' size of the plugin display content.
  • This is the size that will be used when the user hasn't set width or height.

  • Parse the position related settings and update the internal display object of the plugin.
  • After calling this function the pixelwidth and pixelheight variables will contain the final pixel sizes of the plugin element.

  • Returns the xml embedding path/name - e.g. "plugin[name]" or "hotspot[name]".

plugin._assignEvents(htmlelement, mode) (HTML5 only)
  • Assign the krpano plugin events to the given html element.
  • mode - "add" for adding the events, "remove" for removing.
  • This can be used for special custom added html elements, e.g. svg path elements.

krpano 'Base' Object (the 'base-class' or 'super-class' in programming language)

All krpano mapped-xml-nodes, objects or array-elements and also the krpano Interface Object are derived from a krpano 'Base' object. The 'base' object has some basic functions for adding / registering new attributes and for creating sub array structures.
Functions of 'Base' objects:

object.registerattribute(attributename, default, setter*, getter*)
  • Adds a new attribute to the object and sets it to the given default value. When the object already has that attribute (e.g. from the xml) then the current value will be kept but the type of the attribute will be converted to the type of the given default value. That automatic type conversion will work for 'Number' and 'Boolean' datatypes.
    For example: When the attribute was set in the xml file to "123" then the type of the attribute is a 'String', but when registering that attribute with a 'Number' default value, then the attribute will be also converted to 'Number' with the Value 123.
  • Setter / Getter (optionally)
    Optionally it's possible to use setter and getter functions instead of a normal attribute. In this case when the attribute will be set from xml or via the set interface then the setter function with the new value will be called, and when the value of the attribute will be read then the getter function will be called to return the value (Note - the setter/getter functions will need to store the value anywhere in this case).

    Accessing the setter/getters from Actionscript or from Javascript:
    • In Actionscript the setter/getter are special objects. Accessing them direct like normal variables/attributes is not possible because the Actionscript language doesn't have/support dynamic setter/getters. For accessing the value these objects have a set(value) function for setting the new value and a get() function for getting the value.
    • In Javascript the setter/getter behave as normal attributes. They can be used directly like normal variables/attributes.

    Notes about setter / getters:
    • Setter and getters are a very powerful instrument for building data structures.
    • They can be used to get informed anytime when the value of an attribute will be changed / updated.
    • With them it possible to check and if necessary correct the value on setting.
    • And/or to set flags and call other functions when the value will be changed.

  • Removes an attribute from the current object.

  • Get all current attributes of the object.
  • Returns a Flash/Javascript 'Array' with the names of all attributes.

  • Create a new krpano Base Object inside / under the current object.
  • Returns the new created krpano Base Object.
  • If the object already exists then the exiting object will be kept and returned.

  • Removes an object from the current object.

  • Create a new krpano Array inside the current object.
  • Returns the new created krpano Array Object.
  • If the array exists already then the current Array will be kept and the exiting Array will be returned.

  • Removes and destroys a krpano Array object.

krpano 'Array' and 'Array-Item' Objects

Arrays in krpano are internally special objects, not native Javascript or Actionscript Arrays. An array will be automatically created when a node in the xml has a 'name' attribute or when a variable with a 'array path' like 'arrayname[itenname].variable' will be set.
The items of the arrays are derived from krpano 'Base' objects and have additional attributes for name and index. Beside of that, these objects can store any kind of attributes or functions, also additional krpano arrays.
Attributes of the krpano 'Array' objects:

  • The number of elements in the array.
  • Can be changed dynamically, but only decreasing makes sense, e.g. set it to 0 to remove all items.
Functions of the krpano 'Array' objects:

array.createItem(name or index) or
array.createarrayitem(name or index) (callable from xml)
  • Create a new item inside the array.
  • When using 'auto' as name, an automatic unique name will be generated.
  • When using a name and not an index, the new item will be added at the end of the array.
  • Returns the new created array item object.
  • When there exists already an item with that name or index, then no new item will be created, instead the existing item will be returned.

array.insertItem(name, index) or
array.insertarrayitem(name, index) (callable from xml)
  • Create a new item and insert it at the given index.
  • When using 'auto' as name, an automatic unique name will be generated.
  • Returns the new created array item object.
  • When there exists already an item with that name, then no new item will be created, instead the existing item will be moved to the given index.

array.getItem(name or index)
  • Get an existing array item.
  • Returns the array item object or null when the items doesn't exist.

array.renameItem(oldname, newname)
  • Changes the name of an existing item.

array.removeItem(name or index) or
array.removearrayitem(name or index) (callable from xml)
  • Removes an item from the array.
  • The removeItem() function returns the removed item object.
  • The removearrayitem() function is the same like the removeItem() function but without return value and also callable from XML / krpano Actions.

  • Returns a native Actionscript/Javascript 'Array' of all array items.
  • Can be used for direct fast access.
  • The array item attributes can be changed, but the array itself (length, item order, ...) not!

Default Attributes of the krpano 'Array-Item' Objects:
  • The name of the current array item (read-only).
  • This name can be used for direct access to the array item.

  • The 0-based index of the current array item (read-only).

krpano WebGL API

The krpano HTML5 viewer exposes a WebGL API for getting access to the internal WebGL canvas and context and for managing custom post-processing shaders.
  • The krpano WebGL API object.
  • When the object is null, then there is no WebGL support.

  • The internal krpano WebGL <canvas> element.


krpano.webGL.createPostProcessingShader(source, uniforms, name)
  • Create a krpano post-processing shader (a WebGL GLSL fragment shader).
  • Parameters:
    • source
      • A GLSL fragment shader source code as string.
      • The shaders code needs to have:
        • A sm named sampler2D - this will be the current screen as input texture.
        • A tx named vec2 varying - this will be the current texture coordinate.
        • Optionally a sz vec2 uniform - this will contain the screen size.
    • uniforms
      • A comma separated list of the uniform names used in the shader.
      • The 'uniform location' will be automatically stored at the returned shader object with the same name.
    • name (optionally)
      • A name for the shader.
  • Return:

  • An array of post-processing shaders.
  • Here custom shaders can be added, inserted or removed.
  • The shaders will be processed by the order in that array.
  • These shaders will be executed after the COMPLETE rendering of a frame. That means it will affect everything that was drawn before by WebGL - the pano and also the hotspots.

  • An array of post-processing shaders.
  • Here custom shaders can be added, inserted or removed.
  • The shaders will be processed by the order in that array.
  • These shaders will be executed AFTER the pano rendering, but BEFORE the hotspots-rendering. That means it will affect only the pano, but not the hotspots, they will be drawn on top of the processed image.

  • Select/activate the shader for interfacing, e.g. for setting uniform values.

  • Delete the shader (free-up the WebGL resources).

  • Notify krpano that it need to restore the krpano WebGL program on the next usage.
  • This need to be called when an external WebGL code had changed the current WebGL program.

krpano.webGL.makeScreenshot(width, height, hotspots, type, jpegquality, crop, sizeinfo, cache)
  • Make a screenshot in the given size and given type.
  • Parameters:
    • width, height - The size in pixels. When set to 0 the current size will be used.
      When the size will be larger than possible by the browser, then the size will be automatically proportionally downscaled.
    • hotspots - Render also the (webgl) hotspots: true or false (false by default).
    • type - This setting defines what will be returned by the function:
      • "jpeg" - A JPEG image as data-url / base64 encoded string. (default)
      • "png" - A PNG image as data-url / base64 encoded string.
      • "raw" - The direct pixels as Uint8Array with RGBA bytes per pixel.
      • "canvas" - A 2D Canvas Object with the screenshot image.
    • jpegquality - The JPEG image / compression quality, from 0.0 (worst) to 1.0 (best) and 0.85 by default. Only used for type="jpeg" and ignored for all other types.
    • crop - An optional Object with {x,y,w,h} properties to define an optional cropping of the screenshot image.
    • sizeinfo - An optional Object with {w,h} properties to pass to get information about the pixel size of the resulting image (useful for raw and image types).
    • cache - An optional empty Object where krpano can store internal buffers. When doing several screenshots with the same size, this can makeScreenshot calls faster. That object should be stored somewhere on application side and passed to all makeScreenshot calls.
  • When there will be an error, null will be returned.
  • Usage notes: Even when called 'screenshot', technically this functions renders a whole new frame directly in the given size/resolution (no interpolation).
    This also allows changing all kind of settings (e.g. a different viewing direction) before doing the 'screenshot' (and then restoring them after it) to render something different to that what's currently shown on the screen.
    There is only one limitation here - only the currently loaded pano tiles/image are used. That means when trying to render a whole different view (e.g. other direction or other zoom) on a multires pano, there might be only the preview image there to render.