pixelx, pixelwidth, etc. always returning "0"

  • Hello everyone.
    I now I must be missing something really obvious here, my coding skills are very limited, so I apologize in advance...
    I'm trying to recover the pixel width of "Layer A" (which has been created using relative parameters), and then use that value for the x position of "Layer B".

    This is my simple test code:


    Layer B's x value should be equal to Layer A's width in pixels, but it's "0". And the traced value is also "0" in every "pixel" dimension.
    If I change set(layer[layer_B].x, get(layer[layer_A].pixelwidth)); to set(layer[layer_B].x, get(layer[layer_A].width)); it moves to where I want it, because it takes de relative value (40%). But I really need to work with pixel values.
    Any help would be much appreciated.

  • OK, so a weird update after additional testing...
    It works properly if viewed in an incognito window on Chrome, returning the right pixel values and positioning the Layer B right after Layer A. It also works on MS Explorer 11 and Edge straight away, and on an Android phone using Chrome. But it doesn't work using a normal tab of Chrome, or Firefox.
    Does this make any sense? *blink*

  • I've tried that, but still no luck.
    I figured the problem must be related to the processing speed and number of threads. Layer B starts to get created before Layer A has been completed. So I also tried using nexttick in the initial action, trying to first create Layer A, and then Layer B, but I can't figure it out.
    I've come up with a somewhat clumpsy solution: I delay the creation of Layer B for a small amount, giving it time to complete the previous layer. It works, but it seems to me there must be a more elegant way to work around this, since I'm afraid it'll become a mess when dealing with many layers that depend on previous ones for their sizing...
    This is my temporary solution:

  • Hi,

    it might be possible that there is no size available for the krpano viewer window itself yet.

    Try checking the stagewidth / stageheight variables - they might be 0.

    If that's the case, you could try adding a:

    Code
    callwhen(stageheight GT 0, ... );

    around your code,

    but as your code mixes relative % sizes with calculated pixelwidth sizes, it would be better to put pixelwidth/pixelheight depended code in an onresize event. Then these sizes also would get updated when changing the window size.

    Or rethink the layout/code - e.g. by creating layer_B as child of layer_A it would move automatically with it. Or when width is always set to 40%, then x also could be simply set to 40%.

    Best regards,
    Klaus

Jetzt mitmachen!

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