Call the normal krpano actions in javascript krpano actions

  • Hello everyone, maybe someone knows how to call the normal krpano actions in javascript krpano actions.
    Here are the normal krpano actions:

    Code
    <action name="calculatedistance" scope="local" args="x1, y1, x2, y2"> pow(a, calc(x2-x1), 2); pow(b, calc(y2-y1), 2); set(global.distance, calc(sqrt(a+b))); </action>
    <action name="gotoclosesthotspot" scope="local"> getclosesthotspot(); calc(closesths, hotspot[get(global.closesthsname)]); tween(view.tx, get(closesths.tx)); tween(view.tz, get(closesths.tz));  </action>
    <action name="getclosesthotspot" scope="local"> set(lowestdistance, 100000); set(global.closesthsname, ""); for(set(i,0), i LE hotspot.count, inc(i), calc(hs, hotspot[get(i)]); if (hs.clickablehotspot == true, set (x1, get(hs.tx)); set (y1, get(hs.tz)); set (x2, get(caller.tx)); set (y2, get(caller.tz)); calculatedistance(get(x1), get(y1), get(x2), get(y2)); if(global.distance LT lowestdistance, set(lowestdistance, get(global.distance)); set(global.closesthsname, get(hs.name)); ); ); ); </action>
    <action name="mouse_3d_click" scope="local">
        getclosesthotspot(); 
        calc(closesths, hotspot[get(global.closesthsname)]);
        tour_loadscene(get(closesths.linkedscene), null, MERGE|KEEPVIEW|KEEPMOVING, BLEND(1));
    </action>

    I want to call action "mouse_3d_click" in the function ondoubleclick() of javascript krpano actions. Here is the action itself:

  • Inside javascript, get the krpano object:

    krpano = document.getElementById("krpanoSWFObject");
    krpano = krpano.get("global")

    Note: this is probably not needed inside an <action> as the krpano object will already be defined by krpano.

    Then you can use krpano.call(), in your case

    krpano.call("mouse_3d_click")

    More info:

    krpano.com - Documentation - Javascript Interface

    krpano.com - Documentation - Plugin Interface

  • Thank you very much for your help, but now another problem has come out. I used to have a regular floorspot on the floor:

    And this floorspot correctly performed the floorspot_click() function (the nearest hotspot to the click location is calculated, and a move occurs to it) :

    Code
    <action name="calculatedistance" scope="local" args="x1, y1, x2, y2"> pow(a, calc(x2-x1), 2); pow(b, calc(y2-y1), 2); set(global.distance, calc(sqrt(a+b))); </action>
    <action name="getclosesthotspot" scope="local"> set(lowestdistance, 100000); set(global.closesthsname, ""); for(set(i,0), i LE hotspot.count, inc(i), calc(hs, hotspot[get(i)]); if (hs.clickablehotspot == true, set (x1, get(hs.tx)); set (y1, get(hs.tz)); set (x2, get(caller.tx)); set (y2, get(caller.tz)); calculatedistance(get(x1), get(y1), get(x2), get(y2)); if(global.distance LT lowestdistance, set(lowestdistance, get(global.distance)); set(global.closesthsname, get(hs.name)); ); ); ); </action>
    <action name="floorspot_click" scope="local">
        getclosesthotspot(); 
        calc(closesths, hotspot[get(global.closesthsname)]);
        tour_loadscene(get(closesths.linkedscene), null, MERGE|KEEPVIEW|KEEPMOVING, BLEND(1));
    </action>

    Here is an example of hotspots:

    Code
    <style name="hotspot" type="text"  width="100" height="100" scale="1"   mipmapping="true" zorder="1" distorted="true" depth="0" depthbuffer="true" torigin="world"  capture="false" handcursor="false"  clickablehotspot="true" keep="true"/>
    
    	<hotspot name="hotspot_001" style="hotspot" tx="-11820.78" ty="10.67" tz="8928.37" linkedscene="scene_M39_WT_001"/>
    	<hotspot name="hotspot_002" style="hotspot" tx="-9649.45" ty="-58.51" tz="8928.37" linkedscene="scene_M39_WT_002"/>
    	<hotspot name="hotspot_003" style="hotspot" tx="-7431.22" ty="-116.29" tz="8928.37" linkedscene="scene_M39_WT_003"/>

    But when I added to the project mouse_3d_cursor.xml (I deleted the old floorspot) and prescribed the same floorspot_click action for it, as you suggested above :

    Code
    function ondoubleclick()
    	{
    		krpano.call("floorspot_click");
    				
    	}

    With a double click, the logic of moving to the nearest hotspot from the click point disappeared somewhere, became incorrect. For example, it doesn't matter where you clicked, the movement always happens in one hotspot.
    This is how it looks completely mouse_3d_cursor.xml:

    I can't figure out what the problem is.

  • The reason is that in the original example, the "onclick" is linked to the hotspot. Later, in the routines to calculate where to go to, there is an object used "caller".

    set (x2, get(caller.tx));

    More info on caller:

    krpano.com - Documentation - XML Reference

    The doubleclick is not bound to an object/hotspot, but is a global event, which does not hold the "caller" object and hence, the routine does not have enough information to calculate the positions and thus caller.tx will always return 0 or NaN.

Jetzt mitmachen!

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