You are not logged in.

1

Tuesday, February 2nd 2021, 7:52am

Javascript apply a style to a hotspot

Hello,
In a JS script, I want to place hotspots with :

krpano.call("addhotspot(" + hs_name + ")");
krpano.set("hotspot["+hs_name+"].type", 'text');

For style, I tried:
krpano.set("hotspot["+hs_name+"].style", 'mystyle');
or
krpano.call("assignstyle(hotspot["+hs_name+"]", "'mystyle');");

(for info, "mystyle" is defined in an xml).


Can you help me find the right command to use this style?
Thank you very much for your help
Best regards

2

Tuesday, February 2nd 2021, 8:37am

your quotes were off...
krpano.call("assignstyle(hotspot["+hs_name+"],'mystyle');");

3

Tuesday, February 2nd 2021, 9:17am

Hi,

that could be done also this way:

Source code

1
2
3
var hs = krpano.addhotspot();
hs.type = "text";
hs.loadsyle("mystyle");


Best regards,
Klaus

4

Wednesday, February 3rd 2021, 7:19pm

Hello both of you,
Thank you for your 2 very quick proposals.

I also tried with Klaus' proposal, but it didn't work. I must have made another mistake in my javascript.


Indexofrefraction's 1st solution worked very well and I was able to reuse my styles easily and automatically.

Thanks again for your very quick help.
Best regards
Vincent

5

Thursday, February 11th 2021, 9:52am

Hello,

I was super happy with the above solution:
krpano.call("assignstyle(hotspot["+hs_name+"],'mystyle');");


This Javascript function worked great locally (with krpano Testing Server.exe)
After copying my tree structure on my website, online, I get this error :


(newHotspot is my style)

this error occurs each time I have the order krpano.call("assignstyle(hotspot["+hs_name+"],'mystyle');");
and with all styles.


However the FichiersVBs/Def_Styles.xml is well defined in the tour.xml and it is well copied to the right place.

Do you have an idea
Thank you for your help
Best regards
Vincent

6

Thursday, February 11th 2021, 5:39pm

not sure, but maybe try with lowercase name "newhotspot"... krpano names are not case-sensitive
https://krpano.com/docu/xml/#xmlspecial
also webservers can be case-sensitive or not, it's best to not use mixed cases for krpano files or names

7

Friday, February 12th 2021, 7:50am

Thanks
It was a case problem betwenn JavaScript and Krpano
Have a good day