Sie sind nicht angemeldet.

1

Donnerstag, 16. Februar 2023, 09:57

Javascript - how to add Listener for krpano variable changed ?

Hi all,

I want to ask if it is possible to create a listener in javascript that would catch every change of a variable from the patch.

I inlude krpano via javascript. and I need to get the information in javascript (outside the krpano XML file) that the krpano variable has changed. How to achieve this please?

I am solving the problem of having a lot of functions in javascript to lighten the krpano. but I need them to communicate with each other. if a variable in patch changes, something must happen in javascript.

thanks in advance for any advice
*smile*

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

2

Donnerstag, 16. Februar 2023, 10:02

What is the variable(s) you want to track?

krpano already offers some events that you can use to trigger javascript. Take a look at https://krpano.com/docu/xml/#events

3

Donnerstag, 16. Februar 2023, 10:14

embedpano({

Hi,

i declare in initvars some variable:

example :

embedpano({
...

initvars : {
test_variable : 1

}

})
in hotspot in XML i have declared : <hotspot name="test" ... url="../img_%$test_variable%.png" />

what i need to achieve is :

if the value of the variables changes, let the hotspot image also change.

but this will not happen to me. Therefore, I need to find out the information that the variable has changed and then I can change the url of the hotspot.
If there was a way to change the image after changing the krpano variable, that would be great. but I don't know if it is possible to achieve this if the value of the krpano variable changes outside of XML

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

4

Donnerstag, 16. Februar 2023, 10:29

I think I get what you want to achieve.

Zitat

if the value of the variables changes, let the hotspot image also change.

One last question: where/how is the variable updated?

5

Donnerstag, 16. Februar 2023, 10:37

Via XML -> hotspot on click action.

but i think i can/want update this variable too in ma Javascript code.

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

6

Donnerstag, 16. Februar 2023, 11:42

I put together a quick example, maybe it can help you?

Basically:

- define imagenbr in initvars
- add a hotspot with the imagenbr from the initvars as the image url
- add an action to the hotspot to update imagenbr and call a javascript outside of krpano
- in the javascript, get krpano object, get the imagenbr and update the hotspot url

This is not using events, but maybe it will work for your use case too?

Code/xml at: https://krpano.kri-soft.be/examples/hots…image/tour.html

7

Donnerstag, 16. Februar 2023, 12:28

Thank you @kme, your answer helped me a lot. well thank you :)