资讯专栏INFORMATION COLUMN

krpano各种Objects

n7then / 3450人阅读

摘要:在定义时的方法中的第三个参数,实际上是文件中元素的内部呈现。但是除了元素的各种属性意外,还有几个特殊的属性和方法在定义时,其中一个接口中的第一个参数,是内部访问的直接媒介接口对象。数组中的元素也是继承与,并且额外提供了和属性。

krpano中有好多object,krpano Plugin Interface, krpano Plugin Object, krpano Base Object, krpano Interface Object, krpano Javascript Interface... 真心觉得官方文档的组织形式太晦涩了,所以这里整理下

krpano Plugin Interface

定义krpano plugin的时候需要遵循的接口。
http://krpano.com/docu/plugininterface

定义krpano插件的时候,基本上就是定义一个叫krpanoplugin的function,这个function会在krpano加载插件的时候调用到。

krpanoplugin的方法里,有几个特殊的地方:

this指向当前的plugin对象

需要按照krpano Plugin Interface,在this下定义并实现几个方法。registerplugin, unloadplugin必选;onresize可选

registerplugin当krpano要去加载该插件的时候被调用,调用时会传三个参数:依次是krpano Interface Object, plugin path, krpano Plugin Object

例如:

/*
    krpano HTML5 Javascript Plugin Example
*/

function krpanoplugin () {
    var local = this;   // save the "this" pointer from the current plugin object
    var krpano = null;  // the krpano and plugin interface objects
    var plugin = null;

    var xml_value = 100.0;   // the value for a custom xml attribute

    // registerplugin - startup point for the plugin (required)
    // - krpanointerface = krpano interface object
    // - pluginpath = the fully qualified plugin name (e.g. "plugin[name]")
    // - pluginobject = the xml plugin object itself
    local.registerplugin = function (krpanointerface, pluginpath, pluginobject) {
        // get the krpano interface and the plugin object
        krpano = krpanointerface;
        plugin = pluginobject;

        // first - say hello
        krpano.trace(1, "hello from plugin[" + plugin.name + "]");

        // add plugin attributes
        plugin.registerattribute("mode", "normal");
        plugin.registerattribute("value", xml_value, value_setter, value_getter);

        // add plugin action (the attribute needs to be lowercase!)
        plugin.dosomething = action_dosomething;

        // optionally - add some graphical content:

        // register the size of the content
        plugin.registercontentsize(200,200);

        // use 100% width/height for automatic scaling with the plugin size
        var text = document.createElement("div");
        text.style.cssText = "width:100%;height:100%;"+
            "display:flex;color:white;background:rgba(10,50,100,0.5);"+
            "align-items:center;justify-content:center;text-align:center;";
        text.innerHTML = "HTML5
TEST PLUGIN
click me"; // the plugin "sprite" variable is the internal html element of the plugin plugin.sprite.appendChild(text); } // unloadplugin - exit point for the plugin (optionally) // - will be called from krpano when the plugin will be removed // - everything that was added by the plugin should be removed here local.unloadplugin = function() { plugin = null; krpano = null; } // onresize (optionally) // - width,height = the new size for the plugin // - when not defined then only the krpano plugin html element will be sized local.onresize = function(width,height) { // not used in this example // the plugin content will resize automatically because // of the width=100%, height=100% CSS style return false; } function value_setter(newvalue) { if (newvalue != xml_value) { krpano.trace(1, ""value" will be changed from " + xml_value + " to " + newvalue); xml_value = newvalue; } } function value_getter () { return xml_value; } function action_dosomething () { // trace the given action arguments krpano.trace(1, "dosomething() was called with " + arguments.length + " arguments:"); for (var i=0; i < arguments.length; i++) krpano.trace(1, "arguments[" + i + "]=" + arguments[i]); // trace some infos krpano.trace(1, "mode=" + plugin.mode); krpano.trace(1, "lookat=" + krpano.view.hlookat + " / " + krpano.view.vlookat); // call krpano actions plugin.accuracy = 1; // disable grid fitting for smoother size changes krpano.call("tween(width|height, 500|100)", plugin); krpano.call("lookto(0,0,150); wait(1.0); lookto(90,0,90);"); krpano.call("tween(width|height, 200|200)", plugin); } }
krpano Plugin Object

在定义krpano plugin时,其中一个接口registerplugin中的第三个参数,指代plugin对象本身。
http://krpano.com/docu/plugininterface/#plugininterface

在plugin定义时的registerplugin方法中的第三个参数krpano plugin object,实际上是xml文件中元素的内部呈现。但是除了元素的各种属性意外,plugin object还有几个特殊的属性和方法:

sprite

HTML5 - The HTML

element of the plugin object.

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

videoDOM

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).

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 the width or height.

updatepos()

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.

getfullpath()

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

_assignEvents(htmlelement, mode)

krpano Interface Object

在定义krpano plugin时,其中一个接口registerplugin中的第一个参数,是内部访问krpano的直接媒介(接口对象)。
http://krpano.com/docu/plugininterface/#krpanointerface

这个接口对象提供了访问整个krpano的所有结构和方法,之外还额外提供了一些方法来做数据访问,action调用等。

这些额外的方法有:

1. set(variable, value)
2. get(variable)
3. call(actioncode, callerobject*)
4. trace(code, message)
5. parsepath(path)
6. loadFile(file, donecallback, errorcallback*)
7. loadImage(fiel, donecallback, errorcallback*)
8. screentosphere(x, y)
9. spheretoscreen(v, h)
krpano Base Object

http://krpano.com/docu/plugininterface/#baseobject

所有的xml中定义的元素、对象和数组对象,包括krpano Interface Object都是继承与krpano Base Object。(上面说过krpano Plugin Interface就是xml中的元素,所以它也继承了base)

Base提供了一些基础的添加/注册属性或者创建子数组结构的方法:

1. registerattribute(attributename, defaultvalue, setter*, getter*)
2. removeattribute(attributename)
3. getattributes()
4. createobject(objectname)
5. removeobject(objectname)
6. createarray(arrayname)
7. removearray(arrayname)
krpano Array and Array-Item Objects

http://krpano.com/docu/plugininterface/#array

krpano中的数组对象,不同于javascript中的数组。当在xml中一个元素定义了name属性,那么其实就创建了一个krpano数组;或者是当给一个变量设置了array-path,即"arrayname[itemname].variable"时,也创建了krpano数组。

数组中的元素也是继承与krpano Base Object,并且额外提供了nameindex属性。这些数组元素可以用来保存任何属性,方法或者是另外一个krpano数组。

例如:

var kr = document.getElementById("krSWFObject");
var hotspots = kr.get("hotspot");           // hotspots就是krpano array
var aHotspot = hotspot["spot1"];            // aHotspot就是krpano array item

krpano Array Object提供的属性和方法:

1. count
2. createItem(name or index)
3. getItem(name or index)
4. renameItem(oldname:String, newname:String)
5. removeItem(name or index) / removearrayitem(name or index)
6. getArray()

krpano Array-item Object提供的属性:

1. name
2. count 
krpano Javascript Interface / krpano Javascript-Interface Object

http://krpano.com/docu/js/#top

在krpano外部同步javascript操作krpano的接口,实现这个接口的对象就是krpano Javascript-Interface Object

这个对象提供的接口有:

1. set(variable, value)
2. get(variable)
3. call(action)
4. spheretoscreen(h, v)
5. screentosphere(x, y)

ygjack: 可以看到这个接口是krpano Interface Object提供接口的子集

获得krpano Javascript-Interface Object:

var kr = document.getElementById("krpanoSWFObject"); // "krpanoSWFObject"是默认id

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/87808.html

相关文章

  • 使用 krpano 实现全景视频

    摘要:下载,我使用的版本是最新的解压下载文件,就是官方提供全景视频,将整个目录放入服务中,直接访问就可以预览了。 使用 krpano 制作全景视频 krpano的强大我就不多说了,了解过的人应该都知道,现在市场上只要应用全景的几乎都是使用的krp来实现,krp官方提供了插件,全景视频使用的是 videoplayer 插件,使用全景摄像机录制视频,在将他们播放到网页上,可以操作鼠标改变视角,也...

    陆斌 评论0 收藏0
  • ThinkPHP3.2+Krpano实现全景图

    摘要:为了实现全立体的全景图效果,我们采用了软件将普通鱼眼图片渲染为全景图说明代码有过调整,并不能保证运行,主要说明实现思路。显示全景图要将图片显示出来,我们必须按照规则生成必须的配置文件。我们将根据上传图片是生成的唯一码作为依据生成全景图。 为了实现全立体的3D全景图效果,我们采用了Krpano软件将普通鱼眼图片渲染为720°全景图 说明:代码有过调整,并不能保证运行,主要说明实现思路。首...

    My_Oh_My 评论0 收藏0
  • 10-django——RESTful API 之序列化

    摘要:之序列化前后端分离就是前台的开发和后台的开发分离,这个技术方案的实现需要借助,简单来说就是开发人员提供编程的接口被其他人调用,调用之后会返回数据供其使用安装什么是序列化把模型对象转换为格式然后响应出去,便于客户端进行数据解析创建序列化类在应 Django RESTful API之序列化 前后端分离:就是前台的开发和后台的开发分离,这个技术方案的实现需要借助API,简单来说就是开发人员提...

    Bowman_han 评论0 收藏0
  • 2-django——模型

    概述:Django对各种数据库都提供了很好的支持,Django为这些数据库提供了统一的调用接口API,程序员可以根据自己的业务需求选择不同的数据库 ORM简介 概述:对象-关系-映射 作用: 根据类生成表结构;将对象、列表的操作转换成对应的SQL语句;将SQL语句查询到的结果转换为对象或者列表 优点:极大的减轻开发人员的工作量,不需要面对因数据库的变更而导致代码无效在修改代码 图解: showIm...

    idisfkj 评论0 收藏0
  • ES6引入的数据结构 - ES6 - ECMAScript特性 - Javascript核心

    摘要:引入的数据结构新加入的数据类型有这些数据结构的支持并不广泛,在写这篇文章的时候。是或其他可枚举的对象,其每个元素是的元数组。开头的和不对持有引用,不影响。因此,他们没有办法对自身的进行直接的枚举。目前新版的和支持。 原文:http://pij.robinqu.me/JavaScript_Core/ECMAScript/es6/es6_data_types.html 源代...

    fobnn 评论0 收藏0

发表评论

0条评论

n7then

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<