You are not logged in.

Tourvista

Intermediate

  • "Tourvista" started this thread

Posts: 260

Location: Leicester UK

  • Send private message

1

Friday, November 20th 2015, 2:14pm

Send an event from krpano

Hello everyone,

Thank you very much in advance for helping.

One if my clients have asked if it would be possible to send an event from krpano so they can listen to it and this way know when a new scene has been loaded. This event also should send the scene name or any kind of information to identify this new scene.

So I've spent a good hour on this but I'm definitely stuck.
The virtual tour uses the latest Beta version krpano 1.19-pr3 (build 2015-08-04)
So I thought It would be good use javascript directly like this:

Source code

1
2
    <action name="new_event" type="Javascript" devices="html5"><![CDATA[
    ]]></action>



My client said that if I can create an event like using:

Source code

1
var event = new Event("zoneChanged");event.zone = 2;document.dispatchEvent(event);



Then they can listen to it:

Source code

1
2
3
document.addEventListener("zoneChanged", function (event) {
   console.log(event.zone);
});



I have no experience with Krpano and the JS interface. I know that the information about the scene can be supplied by using

Source code

1
get(xml.scene)


But I haven't managed to get the right commands/syntax to export an event.

Thanks

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

2

Saturday, November 21st 2015, 4:02pm

Source code

1
2
3
4
5
6
7
8
9
10
11
<action name="add_listener">
jscall('document.addEventListener("zoneChanged", function (event) {
   console.log(event.zone);
});');
</action>
<action name="scenechange">
jscall('var event = new Event("zoneChanged");event.zone = '+xml.scene+';');
</action>

<krpano onstart="add_listener()"..
<scene onstart="scenechange();"....



This is probably pretty close.
Remove the listener if it's already in javascript outside krpano of course and correct for any typos..
the documentation for jscall should be enough to figure that out.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

Tourvista

Intermediate

  • "Tourvista" started this thread

Posts: 260

Location: Leicester UK

  • Send private message

3

Monday, November 23rd 2015, 8:10am

Hello Sacha,

Thank you very much for taking your time helping me.

I added your code to my virtual tour and uploaded HERE
It gives me an error. Please click on any hotspot and then press letter 'o' to open the console.
I included in screenshot below:




Here is the relevant part of the code (sorry for the weird format. I never get it right when I post it in the forum):

Source code

1
2
  <action name="activatepano">  loadscene(%1,null,MERGE,BLEND(1));  txtadd(new_scene_setup,'start_' , get(xml.scene));  new_scene_setup();  layer[ga].trackpageview(get(layer[panolist].pano[get(xml.scene)].title));  send_event();  </action>
    <action name="send_event">  jscall('var event = new Event("zoneChanged");event.zone = '+xml.scene+';');  </action>


I didn't add the add_listener because my client is going to do that in their application.

Many thanks,

Rafael

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

4

Wednesday, November 25th 2015, 3:54am

http://krpano.com/docu/actions/#jscall

Yup, get the quotes and apostrophes correct to fix the syntax.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

Tourvista

Intermediate

  • "Tourvista" started this thread

Posts: 260

Location: Leicester UK

  • Send private message

5

Wednesday, November 25th 2015, 12:09pm

Awesome!

I looked up in the JS documentation but I didn't spot that I had to use double quotes instead of single quotes.
Now it works perfectly.

Thank you so much Sacha!