getting current nodeID through JS - please help

Q&A about the latest versions
Post Reply
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

I have been trying for a while now to get the current nodeID using JS, but I just seem unable to use this API. Here is what I did:

I created a test tour with just two nodes.
I have linked the panos and added a skin.
In the HTML normal template I checked off "direct node access".
In the normal html template, at the very bottom, i.e. just before </body>, I added the following code:

var blabla;
blabla = pano.getCurrentNode();
console.log(blabla);

I thought I had a variable name conflict, as initially I used "var currentNode" which I discovered is used internally by pano2VR, so I changed it "var blabla".
The console seems to indicate that the function is being executed, but the result is an empty string.
I also tested another API, pano.getPan(); in this case I do get a result, i.e. "0". So I guess I am using the API correctly.
I also tried using Chrome instead of Safari, no difference.
I disabled possible sources of conflict, such as Adblocker and Ghostery - no difference.
I am using a MacBook Pro late 2016 running Sierra 10.12.3.

At this point I am out of ideas. Your help would be much appreciated.

Best regards,
Franco
christoph
Gnome
Posts: 108
Joined: Mon Aug 20, 2012 3:01 pm

Hi Franco!
You are using the right function, but at the time you are calling it, the Pano2VR player hasn't read the xml file yet, and therefore returns an empty string.
At any later point in time, pano.getCurrentNode() will give you the correct node Id.
Just try typing 'pano.getCurrentNode()' into the console of your browsers developer tools...

Regards,
Christoph
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

Thanks!

Yes, that did indeed work.
However, to make it work programmatically, I had to switch loading the xml file from asynchronously to synchronously.

One more issue: one function call that just won't work is pano.getNodeUserdata("nodeId")
I did enter some information in the User Data form, but the function call simply generate an empty object.

-Franco
christoph
Gnome
Posts: 108
Joined: Mon Aug 20, 2012 3:01 pm

Are you using an actual nodeId from your tour, like 'node1', in your function call?

like: pano.getNodeUserdata('node1')

Because this should work (and it does, when you try entering it in the browser console)....
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

this is what I am using:

pano.getNodeUserdata("node1")

But it doesn't work, either in the template or the Console.
christoph
Gnome
Posts: 108
Joined: Mon Aug 20, 2012 3:01 pm

Are you trying this with a tour output (multiple nodes)?
Because in a single node project, the one node does not have an id, and calling 'pano.getNodeUserdata("node1")' returns an empty structure.

In case of a single node output, you could get the userdata by calling 'pano.getNodeUserdata("")'.
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

No, just 2 nodes with each one hotspot.
christoph
Gnome
Posts: 108
Joined: Mon Aug 20, 2012 3:01 pm

'pano.getNodeIds()' gives you an array of all nodeIds in your tour.
This would look similar to this:
["node1", "node2", "node3", "node4"]
Then you can call pano.getNodeUserdata with one of those Ids to retrieve the user data for each node.

What do you get when you call 'pano.getNodeIds()' in your output?
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

pano.getNodeIds() works fine, I get ["node1", "node2"] as expected.

-Franco
ffurger
Posts: 105
Joined: Mon Mar 24, 2014 11:45 am

Update:

I did some additional testing of various JS APIs. Most of them work, but there is a second one
that either I don't understand how to use or is somehow not working quite right.

Here is the relevant code section in the template. It's the only part of the normal template that I have modified:

Code: Select all

	window.addEventListener("load", function() {

              // Changed readConfigUrl from async to sync to make the test work:
			pano.readConfigUrl("pano.xml");

              // Testing some APIs: all work correctly
		        console.log("basepath", pano.getBasePath() );
			console.log("NodeIds", pano.getNodeIds() );
			console.log("Node title", pano.getNodeTitle("node2") );
			console.log("Current node", pano.getCurrentNode() );
			console.log("Next node", pano.getNextNode() );
			console.log("Prev node", pano.getPrevNode() );
			pano.setFov(90);
			pano.setPan(90)
			pano.setTilt(-45);
			pano.setRoll(15);
			pano.startAutorotate(1, 3, 45)

                 // The following two APIs  don't work:

		        console.log("user data",  pano.getNodeUserdata("node1") );
                      // Console shows an empty object,
                     // but XML file contains the correct information.

  		       console.log("pano complete", pano.isComplete() );
                      // Error message from the Console: 
                     //     "TypeError: pano.isComplete is not a function. 
                     //     (In 'pano.isComplete()', 'pano.isComplete' is undefined)"
                     //     but the pano is completely loaded. 
	}); // END window.addEventListener
Not quite sure what to make of these results. Anyone has any thoughts?

-Franco
Post Reply