krpano Javascript接口Version 1.22
程序入口点 – 获取krpano接口对象
获取krpano接口对象的最佳推荐方法是使用 embedpano() 函数的 onready 回调:
1 2 3 4 |
embedpano({..., onready:function(krpano) { console.log( krpano.version ); }); |
另一种方法是使用 document.getElementById(id)和在 embedpano() 调用中设置的 id:
1 2 3 4 |
embedpano({..., id:"mypano"}); ... var krpano = document.getElementById("mypano"); console.log( krpano.version ); |
不过,不建议使用这种方法–根据代码/应用程序结构的不同,当第一次使用 getElementById() 时,可能还没有调用 embedpano()。
此外,krpano 接口对象还可以在以下文件中使用:
- krpano Javascript 插件
- Javascript <action> 元素
- 在 js(), jscall() 或 jsget() 动作中,
- js:开头的动作代码
- 通过loadjs()动作加载的JavaScript文件内
krpano接口对象
krpano 接口对象是 krpano 的直接接口。它可以直接访问整个 krpano 结构以及其中的所有变量/设置和函数。所有 xml 节点和属性也可映射到这里。
基础/核心接口函数:传统接口
- krpano.set(variable, value)
- krpano.get(variable)
- krpano.call(actioncode, caller*)
高级函数:
- krpano.trace(code, message)
- krpano.resolveExpression(expression, caller*)
- krpano.toBoolean(var)或者 krpano.BOOLEAN(var)
- krpano.roundNumber(var, dp=0)
- krpano.clampNumber(value, min, max)
- krpano.unload()
扩展函数:
- krpano.registerType(type, callback)
实用函数:
- krpano.utils.wildcmp(template, text)
- krpano.utils.spliturl(url)
- krpano.utils.buildurl(urlinfo, urlmods)
事件函数:
- krpano.events.addListener(eventname, callback, once*)
- krpano.events.removeListener(eventname, callback)
- krpano.events.dispatch(eventname, instantly*)
直接使用 Javascript API 进行操作的krpano动作:
- krpano.tween(object, object, …)
- krpano.stoptween(object, …)
- id = krpano.delayedcall(time, callback)
- krpano.stopdelayedcall(id)
- krpano.asyncloop(callback)
- krpano.copyattributes(object, object)
- krpano.callwith(object, actioncode)
加载:
- krpano.parsePath(url)
- krpano.loadFile(url, donecallback, errorcallback*)
- krpano.sendRequest(request, callback)
- krpano.mergeCallbacks(tasks, done)
特殊路径解析/加载拦截:
- krpano.customParsePath
- krpano.customParseTilePath
坐标转换函数:
- krpano.screentosphere(x,y)
- krpano.spheretoscreen(h,v)
- krpano.spheretospace(h,v,depth)
- krpano.spacetosphere(x,y,z)
- krpano.actions.screentolayer(layer,x,y)
- krpano.actions.layertoscreen(layer,x,y)
- krpano.view.syncto(otherview)
- krpano.view.unproject(x,y,d,rotated)
- krpano.view.remapfovtype(fov,srcfovtype,destfovtype,w,h)
- krpano.view.fovtoscale(fov,fovtype,w,h)
- krpano.view.resetlimits()
交互式编程:
- krpano.addChangeListener(object, key, callback)
- krpano.removeChangeListener(object, key, callback)
- krpano.actions.link(object, varname, …)
- krpano.actions.unlink(object, varname)
- krpano.actions.linkstyle(object, styles)
- krpano.actions.onchange(object, var, callback)
- krpano.actions.removeonchange(object, var)
表达式函数:
- krpano.functions.*
直接访问数据结构:
- krpano.*– all static and dynamic global variables.
- krpano.actions.*– all krpano Actions as Functions.
- krpano.actions.actioncaller– the caller of the current action.
- krpano.mouse.*– mouse/touch information
- krpano.gesture.*– multi-touch gestures
- krpano.device.*– device/system information
- krpano.browser.*– browser information
- krpano.xml.*– information about the current xml file
- krpano.image.* – the current pano image
- krpano.image.reset()– reset the viewing-range limits
- krpano.view.*– the current view settings
- krpano.view.resetlimits()– multi-touch gestures
- krpano.view.update()– instantly update the viewing-range limits
- krpano.area.*– the screen area/window for the pano-view
- krpano.display.*– display / rendering settings
- krpano.display.requestresize() – request a resize event
- krpano.display.layout.update()– – instantly update all layers and hotspots
- krpano.control.*– mouse/touch and keyboard control settings
- krpano.cursors.*– – customize the mouse cursor.
- krpano.autorotate.*– automatic rotation / moving / zooming
- krpano.contextmenu.* – – the contextmenu settings
- krpano.contextmenu.items– Array of the contextmenu items
- krpano.network.* – network settings and paths
- krpano.memory.* – – the contextmenu settings
- krpano.contextmenu.* – – the contextmenu settingsk
– memory usage settings
krpano.security.* – security settings
Predefined krpano Arrays:
krpano.layer.* – all <layer> elements
krpano.hotspot.* – all <hotspot> elements
krpano.scene.* – all <scene> elements
krpano.action.* – all <action> elements
krpano.events.* – all <events> elements
krpano.data.* – all <data> elements
krpano.style.* – all <style> elements
krpano.cssstyles.* – all <cssstyles> elements
Base Object API:
object.registerattribute(attributename, default, setter, getter)
object.registerattribute(attributename, default, setter)
object.registerattribute(attributename, default)
object.removeattribute(attributename)
object.getattributes()
object.setattributes(object,object2*,object3*,…)
object.setvars(object,object2*,object3*,…)
object.createobject(objectname)
object.removeobject(objectname)
object.createarray(arrayname)
object.removearray(arrayname)
Array Object API:
array.createItem(name or index)
array.createarrayitem(name or index)
array.insertItem(name, index)
array.createarrayitem(name, index)
array.getItem(name or index)
array.renameItem(oldname, newname)
array.renamearrayitem(oldname, newname)
array.removeItem(name or index)
array.removearrayitem(name or index)
array.addChangeListener(callback)
array.removeChangeListener(callback)
array.getArray()
array.forEach(callback)
WebGL API:
krpano.webGL.canvas
krpano.webGL.context
krpano.webGL.projectionMatrix
krpano.webGL.depthbufferbits
krpano.webGL.addListener(eventname, callback)
krpano.webGL.removeListener(eventname, callback)
krpano.webGL.createPostProcessingShader(source, uniforms, name, callback
krpano.webGL.ppShaderArray
krpano.webGL.ppShaderArray2
krpano.webGL.useShader(shader)
krpano.webGL.deleteShader(shader)
krpano.webGL.restoreProgram()
krpano.webGL.resetState()
krpano.webGL.redirectBackbuffer(…)
krpano.webGL.makeScreenshot(…)
krpano.spheretospace()
- krpano.spacetosphere()
Javascript Polyfills
注意 – 当下面的函数在浏览器中不可用时,krpano viewer会自动为这些 Javascript 函数安装 Polyfills:
- Object.prototype.__defineGetter__()
- Object.prototype.__defineSetter__()
- Object.assign()
- String.prototype.trim()
- Array.prototype.forEach()
krpano插件接口
…
var krpano = document.getElementById(“mypano”);
console.log( krpano.version );
However, this way would not be recommended – depending on your code/application structure, the embedpano() may not have been called yet when getElementById() is used for the first time.
Additionally the krpano Interface Object is also available in:
krpano Javascript Plugins,
Javascript <action> Elements,
in the js(), jscall() or jsget() actions,
in Actioncode that starts with js:
and inside Javascript files loaded with the loadjs() action.
:
- 使用 embedding script 的 onready 回调函数(推荐方法)。
- 或通过Javascript 调用: document.getElementById(id)
id参数是viewer的唯一性id(默认为”krpanoSWFObject“)可在embedding script中进行设置。