krpano.set(variable, value)
- Sets a variable to a given value.
- If the variable or the path to it doesn't exist, then the variable and path will be created.
- Works like the set() action.
result = krpano.get(variable)
- Returns the value of a variable.
- Returns null if the variable doesn't exist.
krpano.call(actionscode, caller*)
- Call krpano action code.
- When the actions system is currently not blocked (e.g. due xml-loading or xml-parsing),
then the actions will be directly executed.
- But when blocked, the actions will be 'queued' and automatically executed once
the actions system is unblocked again.
- actionscode = a String with one or more krpano actions.
- caller
- The 'caller' of the action code.
- This is an Object that will be used as local variable scope.
- This allows direct access to the attributes of that Object.
krpano.trace(code, message)
- Trace out messages to the krpano log.
- code = numeric code of the message-type:
- 0 = DEBUG message (these will be only shown with enabled debugmode)
- 1 = INFO message
- 2 = WARNING message
- 3 = ERROR message (when showerrors is enabled, the log will also be opened)
- 4 = FATAL ERROR (a noticeable message in the middle of the screen)
result = krpano.resolveExpression(expression, caller*)
- Resolve a krpano expression and return its result.
- caller
- The 'caller' of the expression.
- This is an Object that will be used as local variable scope.
- This allows direct access to the attributes of that Object.
result = krpano.toBoolean(var)
result = krpano.BOOLEAN(var)
- Convert any variable to a Boolean.
- If the variable is null or undefined, false will be returned.
- If the variable is already a Boolean, it will be returned as it is.
- If the variable is a Number, +0, -0 and NaN will return false, all other values return true.
- If the variable is a String, values like "true", "yes" or "on" (lowercase or uppercase, surrounding whitespace are ignored)
will return true, all others will return false.
- If the variable is an Object, true will be returned.
result = krpano.roundNumber(var, decimalplaces=0)
- Round a Number to given decimal places.
- The return value will be a String.
- decimalplaces
- The number of decimal places, 0 by default.
- Negative values work like positive ones, except that trailing zeros are automatically removed (except for a least one zero after the comma dot).
- Examples:
krpano.roundNumber(1.5) ⇒ "2.0"
krpano.roundNumber(1.23, 6) ⇒ "1.230000"
krpano.roundNumber(1.23, -6) ⇒ "1.23"
krpano.roundNumber(1.0, -6) ⇒ "1.0"
result = krpano.clampNumber(value, min, max)
- Clamp/limit a Number to be between the given min and max values.
- min / max
- The lower and upper limit for the result.
- Returns the limited value.
- Examples:
val = krpano.clampNumber(val, 0.0, 1.0);
val = krpano.clampNumber(val, -1.0, +1.0);
val = krpano.clampNumber(val, -90.0, +90.0);
krpano.unload()
krpano.registerType(type, callback)
- Register a custom type for
Layers or
Hotspots.
- This can be used to create custom elements in krpano, e.g. to load custom file types.
For example, this is used in the ThreeJS plugin to support loading 3D-Models
as hotspots.
- If a layer or hotspot has a custom, non-default type setting and
there is a registerType() call with the same type, then the given callback
function will be called when creating or destroying the element.
- callback(object, url, okaycallback)
- object - the layer or hotspot object
- url - on creating the url if set, or the custom type name in angle-brackets if no url is used.
On destroying null will be passed as url to allow a custom unload/destroy handling.
- okaycallback - a callback to be called with true or false to signal if the creating is done and was successful.
This will also trigger the onloaded event.
- Example:
<hotspot name="spot1" type="special" ... >
and
krpano.registerType("special", function(hotspot, url, callback)
{
if (url)
{
// create or load the special hotspot
...
// callback with true to signal that the creating was successful
callback(true);
}
else
{
// destroy or unload the special hotspot
}
});
result = krpano.parsePath(path)
result = krpano.parsepath(path)
- Resolves the krpano placeholders in the given path string.
- Return value: the resolved path string.
krpano.loadFile(rqurl, donecallback, errorcallback*)
- Request to load a text-file as String.
- donecallback and errorcallback - these functions will be called when the loading was successfully or has failed.
The usage of the errorcallback is optionally.
- Both callback 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 - the loaded file content as String.
- errmsg (errorcallback only)
- A boolean flag with the default value true.
- When kept set to true, krpano will show a default loading error message.
- When set to false, no error message will be shown.
krpano.sendRequest(request, callback)
- Send a HTTP server request.
- request need to be an Object with the follow properties:
- type - the request type: GET or POST
- url - the server url.
- data
- The data to send with the request.
- Can be an Object or a String.
- Objects will be automatically converted to a JSON String.
- headers
- Optional headers, can be an Object or a String.
- String-syntax: "key:value, key:'a,b,c', ..."
- cors - when set to true, the CORS credentials will be added.
- user and password - HTTP Basic Authentication.
- The callback function will be called with the given request Object as argument and adds these properties to it:
- ok - true when the request was ok, false when it has failed.
- statuscode - the HTTP status code, e.g. 404 on loading errors.
- statustext - the HTTP status as text description.
- responsetext - the response text.
krpano.mergeCallbacks(tasks, donecallback)
- Merge the callbacks from multiple asynchronous tasks.
- E.g. when multiple files are loaded and/or processed in parallel and
another task should be executed when all previous ones are completed.
- tasks - an Array that contains multiple functions.
- Each function will be called with a callback function as argument.
- This callback function must becalled when the function is completed.
- Optionally, it is possible to pass an argument to this function as return/result value.
- donecallback
- This function will be called when all functions are completed.
- The function gets an Array as argument that contains the all the return/result values from the
called functions (in the same order the functions were defined).
- Example:
krpano.mergeCallbacks(
[ function(callback){
console.log("1 start");
setTimeout(function(){ // randomly delay
console.log("1 done");
callback(1); // here the function is done
}, Math.random()*5000);
},
function(callback){
console.log("2 start");
setTimeout(function(){ /// randomly delay
console.log("2 done");
callback(2); // here the function is done
}, Math.random()*5000);
},
function(callback){
console.log("3 start");
setTimeout(function(){ /// randomly delay
console.log("3 done");
callback(3); // here the function is done
}, Math.random()*5000);
}
],
function(results){
// all functions from above are done
console.log("all done, results:", results); // "[1, 2, 3]"
}
);
krpano.customParsePath = function(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
result = krpano.screentosphere(x,y)
result = krpano.spheretoscreen(h,v)
- 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) if the conversion wasn't possible.
result = krpano.spheretospace(h,v,depth)
result = krpano.spacetosphere(x,y,z)
- 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.utils.wildcmp(template, text)
- A string comparison using * (star) as a wildcard.
- A * matches arbitrary many (including zero) occurrences of any character.
- Returns true or false depending on whether the template and text match.
krpano.utils.spliturl(url)
- Split an URL/filepath string into its components.
- The function will return an Object with the following properties:
- url - the input url
- path - the path (including protocol and folders) but excluding the filename
- filename - the filename, including the file extension
- basename - the filename, without the file extension
- ext - the file extension
- query - the query string
- hash - the hash string
krpano.utils.buildurl(urlinfo, urlmods)
- Rebuild an URL/filepath string using the Object from spliturl().
- Optionally a second Object with alternative values can be provided to modify the URL.
If a particular property is defined in the second Object, the value will be taken from there
rather than from the first Object.
krpano.events.addListener(eventname, callback, once)
krpano.events.removeListener(eventname, callback)
Add or remove Javascript listeners / callback-functions for any krpano
events.
Parameters:
- eventname
- The name of any krpano event, e.g. "onclick" for the onclick event.
- It is possible to assign several events at once to the same callback by separating the names
by | or , characters.
- It is possible to put the once parameter optionally directly into this list instead
of using an additional parameter,
e.g. "onclick,once".
- callback
- The Javascript function to be called on the given event.
- Some events, like mouse or keyboard events, will provide an Event object as parameter.
- Special case: when calling events.removeListener() with the
String * as callback,
then all assigned callbacks will be removed.
- once
- When set to "once", the callback function will be called only once
and then automatically be removed.
krpano.events.dispatch(eventname, instantly*)
Dispatches / calls the given event listeners from all
<events> elements.
Parameters:
- eventname
- The name of the krpano event.
- Can be also any custom name, when event listeners for that name are used.
- instantly
- A Boolean setting (true or false, false by default).
- When set to true, the events will be called and executed instantly,
when not set or set to false, the events will be called after the current actions calls.
2 Parameters - krpano variable path:
krpano.addChangeListener(varpath, callback)
krpano.removeChangeListener(varpath, callback)
3 Parameters - direct Object access:
krpano.addChangeListener(object, key, callback)
krpano.removeChangeListener(object, key, callback)
Make a callback when an Object key/property changes.
- This will convert the given Object property to a setter/getter function and call the callback function on each change/set.
- The key/property can be even already a setter/getter and keeps working.
- When the key/property doesn't exists yet, it will be created with the value undefined.
Parameters:
- varpath
- The name / path of any krpano variable, e.g. "view.hlookat".
- object
- key
- The name of the key/property/variable of the Object.
- callback
- The Javascript function to be called on the given event.
- Some events, like mouse or keyboard events, will provide an Event object as parameter.
Either:
krpano.addChangeListener("view.hlookat", function(){...});
or:
krpano.addChangeListener(krpano.view, "hlookat", function(){...});