how to set values to sprite object?

  • Hi,

    we have a development in which we add some values (id, class, a custom attribute) to some layer.sprite objects via a javascript action. It worked OK using krpano v. 1.20

    Now, when upgrading the krpano version to 1.21, this section of our code fails. We have read in the docs that in this version the layer.sprite object is read-only. Is there any other way to attach values to the underlying dom object? Or getting the dom object associated to the sprite?


    Here, simplified, our code:

    it was working with krpano v. 1.20, and fails with 1.21

    Code
        <action name="setColorProperties" type="Javascript">
            caller.sprite.id = args[1];
            caller.sprite.className = args[2];
            settingColorSprite(caller.sprite, args[3]);
        </action>
  • another point. We have found that when doing caller.sprite, we get a Converting circular structure to JSON error type. In fact, the caller object has a sprite property which has itself as a vaule (kobject), that has as a sprite property with itself as a value and so on. Truly circular

    • Official Post

    Just set/add anything to sprite as you want...

    The 'read only' note in the documentation means you shouldn't change the sprite value itself.

    About the internal kobject linking - that's intentional to allow access from both sides (from krpano to DOM and from DOM to krpano).


    About 'failing code' - do you use your code with hotspots?
    If yes, make sure to use renderer="html" - because WebGL hotspots don't have a HTML object and so also no sprite.
    If no - WHEN do you call your code? It should be always at least after the onloaded event.

    Best regards,
    Klaus

  • Hi, Klaus, thanks for your quick response.

    Our situation is:

    we dynamically create a layer

    we dynamically create a hotspot (with renderer = "html")

    we attach an onloaded event to the layer and to the hotspot

    Even a simple trace() on the onloaded event of the layer is never called. We are sure that the preload of the layer is false.

    The event on the hotspot gets called, but throws an error in the browser console: Converting circular structure to JSON


    Exactly the same code is working on the v. 1.20.11 (if we go back to that version)

  • Hi and again thanks for your advices,

    We discovered that we were setting a parent to that layer. We are parenting it to the image element so this broke this (maybe a element with a parent doesn't trigger the onloaded event or is just that is not possible to parent a layer to the image element)


    With this mystery resolved we found something more related to the tag image behaviour.

    We are using a "custom" attribute on the image tag of the xml, some thing like this:

    Code
    <image customatt='URL.tiles/l%l/%0v/l%l_%0v_%0h.jpg'>
       <sphere url='plugin:video' multires='512,1536x768,3072x1536,6144x3072,12288x6144'>    		   
       </sphere>
    </image>

    Previously we can access this with:

    Code
    get(image.customatt)

    Now we are getting null.

    What is the cause of this and what is the solution to save the data in the xml for later changes at runtime?

    • Official Post

    We discovered that we were setting a parent to that layer. We are parenting it to the image element so this broke this (maybe a element with a parent doesn't trigger the onloaded event or is just that is not possible to parent a layer to the image element)

    *confused*

    Example?

    Now we are getting null.

    Here too - example?

    Maybe your code is somehow out of order and tries to access things when they are not there or not ready yet...

  • Here is the code for the parenting:

    Code
    if(get(image) != null,
        set(layer[get(layerName)].parent, image);
    );


    For the custom attribute (we use customatt on the previous post for be clear but we let the actually name here just in case this is a reserved one) here is how we have it (this code was working on krpano 1.20.11 version):

    Code
    image.reset();
    set(image.sphere.url, get(image.imgalt));
    
    loadpanoimage(KEEPPLUGINS|KEEPVIEW);


    Even when we ask for image.imgalt from the browser console we get null too:

    Code
    krpano.get('image.imgalt');

    But if we ask from the browser console for the xml.content we can check that the image tag have our custom attribute (imgalt):

    Code
    "[...] <image imgalt='URL.tiles/l%l/%0v/l%l_%0v_%0h.jpg'>
       <sphere url='plugin:video' multires='512,1536x768,3072x1536,6144x3072,12288x6144'>    		   
       </sphere>
    </image> [...]"
  • Okey, problem solved.

    We have seen the new "copy" option to the image.reset function and the attribute is now preserved.

    Here is the current code:

    Code
    image.reset("copy");
    set(image.sphere.url, get(image.imgalt));
    loadpanoimage(KEEPPLUGINS|KEEPVIEW);

    Thanks for your replies, hope this can help someone in the future and we hope we don't need to use more this thread, that will be good news.

Participate now!

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