Hello, I need some guidance in krpano JS.
I have an action and a style that defines the behaviour of double clicking hotspots. When I load my hotspots from server and inject them in XML it works as expected. But when I try to add hotspots dynamically via Javascript I can't get it to work.
This is the Style tag for the doubleclick event
Code
<style name="doubleclick" downx="0" downy="0" clicks="0" onsingleclick="" ondoubleclick="" onclick="doubleclick_style_onclick();" />
This is the action
Code
<action name="doubleclick_style_onclick"> inc(clicks); if(clicks == 2, set(clicks,0); stopdelayedcall(doubleclickdetector); if((((mouse.x-downx)^2 + (mouse.y-downy)^2)^0.5) LT (device.touch ? 10 : 2), ondoubleclick(); , onsingleclick(); onsingleclick(); ); , copy(downx, mouse.x); copy(downy, mouse.y); delayedcall(doubleclickdetector, 0.3, set(clicks,0); onsingleclick(); ); ); </action>
And this is how I am trying to set the events in JS
Code
krpano.call('addhotspot('+$('#named').val()+')');
krpano.call('hotspot['+$('#named').val()+'].loadstyle("doubleclick");');
krpano.call('set(hotspot['+$('#named').val()+'].url, "/img/tools/hotspotNav.png");');
krpano.call('set(hotspot['+$('#named').val()+'].ondoubleclick,js(functions.gotToScene('+$('#named').val()+')));');
krpano.call('set(hotspot['+$('#named').val()+'].onsingleclick,js(functions.editHotspotNav('+$('#named').val()+')));');
What happens in this code is: only single click works.
When double clicked, nothing happens...
But if I comment the single click line, then double click function is called
--- EDIT
Managed to work...
Instead of calling the onsingleclick and ondoubleclick attributes in set function of krpano.call, I did this:
Code
for(var i = 0; i < hotspotArr.length; i++){
if(hotspotArr[i].name.toLowerCase() == $('#named').val().toLowerCase()) {
$(hotspotArr[i]).attr('ondoubleclick', 'js(functions.gotToScene('+$('#named').val()+'));');
$(hotspotArr[i]).attr('onsingleclick', 'js(functions.editHotspotNav('+$('#named').val()+'));');
}
}
Now it works as expected