Adding properties/nodes/elements to krpano through javascript

  • I was wondering if it was possible to create actions on the fly through javascript or other properties for that matter like view, display, textstyle etc. I know you can add hotspots and plugins (krpano.call('addplugin(test)"); but was curious about those options.

    If that isnt possible, I was wondering if loading an external xml would do the trick. For instance I host a plugin.xml somewhere, then in javascript I get either the content of the xml through ajax and send it like krpano.call("loadxml(" + xmlcontents + ")"); or just send the url directly to krpano and merge with the current xml.

  • Hi,

    I was wondering if it was possible to create actions on the fly through javascript or other properties for that matter like view, display, textstyle etc. I know you can add hotspots and plugins (krpano.call('addplugin(test)"); but was curious about those options.

    almost everything (expect the <image>) can be set/create dynamically just by setting it,
    e.g. to create an action do:

    Code
    set(action[actionname].content, trace(hello from the dynamically created action); );


    see also:
    https://krpano.com/docu/xml/#action.content

    If that isnt possible, I was wondering if loading an external xml would do the trick. For instance I host a plugin.xml somewhere, then in javascript I get either the content of the xml through ajax and send it like krpano.call("loadxml(" + xmlcontents + ")");

    that would work too, but a loadxml call will also remove the current <image> and load the new one from the xml,

    best regards,
    Klaus

  • how would this work with for instance view? How to create that dynamicly? Or does it always exist in krpano and I only have to alter the defaults?
    set('view.fov', 90);

    If I for instance would not use a xml file at all. Give krpano a blanco xml file:

    Code
    <krpano>
      <preview type="grid(CUBE,16,16,512,0xCCCCCC,0xFFFFFF,0x999999);" />
    </krpano>

    and then control the rest with just javascript. Would I able to recreate a complete tour just using calls/gets/sets?

    all the hotspots/plugins/attributes I could either parse a json from a server, translate to a addhotspot, addplugin, set(property, value); or parse the data as xml and send in directly to xml (not sure what would be faster yet).
    The image would be possible by forcing a loadxml with the image tag in it (created from server). Im just theorycrafting here, what is your opinion, is it possible? Would it be fast enough?

    I see some benefits with this method:
    - always live data from a database. 10 people at the same time adding hotspots/plugins, adjusting views etc.
    - more secure. Viewing xml, is not as simple as view source
    - granually build up your pano, build priorities (show all hotspots before loading plugins).
    - precalulation done in javascript (a thumbnails posistion in a gallery, can be calculated more easily)
    - integrations with other apis (generate hotspots based on facebookfriends, get the latest retail information so you can set a hotspot with the label " sold" on a specific house")

    First I did this with just hotspots and plugins. And altering some basic properties like the fov through javascript. But as more I develop javascript, the lesser xml I write. Im wondering where the line is....Should I be concerned of writing to less xml. I havent noticed any major delays yet ( I put 20 hotspots with a blink of an eye, each with all the properties + custom properties).

  • Hi,

    how would this work with for instance view? How to create that dynamicly? Or does it always exist in krpano and I only have to alter the defaults?
    set('view.fov', 90);

    the <view> node is always there, just set its attributes to the values you want,


    and then control the rest with just javascript. Would I able to recreate a complete tour just using calls/gets/sets?

    with expectation of the pano images, everything can be added just by setting it,
    the plugins and hotspots needs the calling of addplugin/addhotspot to become visible, but the attributes can be set normally,


    Would it be fast enough?

    it would be a bit slower of course, because each call is a small overhead, but I can't say how much,

    best regards,
    Klaus

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!