Global State for a Very Large HTML5 Project

  • I am in the process of evaluating KRPano to create an HTML5 version of a very large project (hundreds of nodes, viewable at gcpano.org) that already has a Flash version (based at its core on PanoSalado) that I intend to continue to use. I intend to make an HTML5 version, based on KRPano, available only when Flash is not available, primarily for iOS. Thus all my testing thus far has been in the HTML5 viewer.

    I need to figure out the best way to maintain global state within KRPano. The application, for example, lets the user control whether all hotspots are displayed or not, and this setting is maintained as the user moves from node to node. I first tried simply declaring variables within a root XML file, but it seems that the variables are always lost whenever a new panorama is loaded (regardless of KEEP settings). The solution I then came up with, and am currently using, was to create a very simple non-graphical plugin where I simply register a set of attributes to maintain the required global state, and then get and set theses attributes from and to the plugin from within KRPano scripts located in .xml files for particular nodes.

    Now that also has problems. In my testing so far, I must use the KEEPPLUGINS flag whenever loading new scenes and panoramas in order to keep my little plugin alive and its state maintained, but a side effect of the KEEPPLUGINS flag is that layers tied to the textfield plugin stick around as well, even if keep="false" is specified on the layer. I've found an ugly workaround to that as well, but I'm not happy with it.

    So my core question is - how to best maintain global state? Is there something better than the non-graphical plugin solution I have come up with? Also am I missing something on the use of the KEEP flags and attributes for plugins?

  • Do you change scenes by calling loadxml, loadscene or by changing the page?
    If you are using loadxml, loadscene.. meaning that krpano is still active.. the variables will not change.
    If you change to a new krpano with a new xml on a different scene.. use javascript to keep track or javascript and cookies, and then embed the variable and value when embedding krpano on startup.

    You don't declare your variable in an xml structure, put it in an action or onstart="set(hotspots_on,false);"
    not
    <layer hotspots_on="false" />

  • Well I was sure I was setting my variables in my root xml within an <action> block, but apparently I wasn't *cry* . Tried it again and the startup variables are indeed being preserved, so that is the solution, since all nodes are being loaded via loadpano or loadscene.

    Thanks

  • Hi,

    I first tried simply declaring variables within a root XML file, but it seems that the variables are always lost whenever a new panorama is loaded (regardless of KEEP settings).

    krpano will not touch (change, remove, ...) any global/unknown data structures when loading new panos!
    That means such settings will be always kept, regardless which loadpano flags were used.

    I must use the KEEPPLUGINS flag whenever loading new scenes and panoramas in order to keep my little plugin alive and its state maintained

    Try using the MERGE flag and keep=true for your plugin.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!