Start a new topic
Solved

How do you pass dynamic parameter to AR World view?

How do you pass dynamic parameter to AR World view?

Hey!

I'm wondering how you can pass parameters to the AR World view.  I'm needing to dynamically show POIs based off of a category.  So, a user selects an item in a list, which is associated to a category, and that click event launches the AR World, and I'd like that category to be passed into the view.

I've tried sticking query string params onto the worldPath that I send to loadARchitectWorld(), and that didn't work.  I've tried setting properties on the window object inside the worldLaunched() event handler, like this, thinking that this event handler would be called inside the execution of the AR World view, but it seems like its not:

var category = 'some category';
WikitudePlugin.worldLaunched = (function (c) {
   return function() {
       window.category = c;
   }
})(category);

So, any help would greatly be appreciated, thanks!

Cheers,
Todd
Hi Todd,

Please have a look at the sample-projects on Github to get familiar with the phoneGap - Wikitude interaction possibilities.
There are at least two solutions for your request

Load different architect worlds, pass aruments and parse them inside the AR-html.

Load same AR-html for all categories, but then trigger loading of category content using WikitudePlugin.callJavascript. (e.g. define mehtod "loadCategory(id)" in your AR-html and use WikitudePlugin.callJavascript('loadCategory(1)') to bypass the information

Hope that helps.

Kind regards,
Andreas
Andreas,

Thanks for the reply, but I'm still confused.

1) So, I've tried parsing params in my AR html, but I may be not passing them correctly. Here's how I'm doing it, let me know if its not correct and how to do so correctly:
WikitudePlugin.loadARchitectWorld("/some/path/to/AR/world.html?foo=bar")
So I launch the AR World with a path to my AR html and I put query string params on there, but when I do this, the AR world wont load my AR, and I can't seem to get an error to show up anywhere.  Thoughts?

2) So the whole callJavaScript() function is very confusing.  If I'm in my AR html and can define a loadCategory function, why do I need to call WikitudePlugin.callJavascript('loadCategory(1)')? 
Also, where would that '1' come from?  I would think it has to be 'passed' into the AR html, but thats my whole thing, I don't know how to do that.

Cheers,
Todd
Hi Todd,

To be more precise, you have two options:

Load AR-html file from local assets folder (also works when loading file from web, recommended approach)
e.g.
WikitudePlugin.loadARchitectWorld("myassetfile.html);
Arguments are not working in this approach, they'd be interpreted as part of a filename, which is not what we want.
You can therefore only inject e.g. category information by adding a type field to your e.g. "newData()"-function and use something like WikitudePlugin.callJavascript('newData(1)') to tell your AR-html that you're currently dealing with category "1" (feel free to adjust naming and nuber of args, this is just a sample)

Load AR-html file from web
e.g. WikitudePlugin.loadARchitectWorld("https://dl.dropbox.com/u/1588973/temp/phonegap/HelloWorld.html?foo=bar");
You can use the common way to parse arguments in JS, as described in stackoverflow.
Simply declare a function in body's onLoad-function.

var prmstr = window.location.search.substr(1);
var prmarr = prmstr.split ("&");
var params = {};
for ( var i = 0; i < prmarr.length; i++) {
var tmparr = prmarr.split("=");
params = tmparr;
}
alert(params.foo); /* will show you "bar" in this sample */

Hope that helps.

Kind regards,
Andreas
Hi,

I've added to your WikitudeTitaniumSample project:

in the ARchitectWindow.js I have:
this.arview.callJavaScript('passData(1)');

In the imagerecognition.jsl (inside 1_ImageRecognition_1_ImageOnTarget) I have
var aa;
function passData(id) {   
            aa = id;
        }
alert(aa);
var World = {
    loaded: false,
...
alert(aa);
        /* Create overlay for page one */
..
World.init();

However, the first alert works fine displaying the correct value (1) for the aa variable, but the second one (located where I actually need to reach the variable) fails, showing "undefined".
How can I reach the aa variable inside the AR world?

Thanks so much in advance
Ric
Hi Riccardo,

Hard to tell based on your snippet. Since you get the passed data already in JavaScript, you need to store it in a place where you can access it later. This is more of a general JavaScript question than a Wikitude SDK question. It depends on your data structures and your application flow.

Is the second alert in the var World = {...} block? If yes, you need to be careful not to override the aa variable anywhere. Other than that, you really need to debug where you can still access the variable, and where you loose it. Again, this is pure javascript code and functionality and nothing special is added by Wikitude here.

Best,
Martin

Hmm, I tried all ways, but FAILED. Seem, wikitude don't support pass data to AR View.

Hi Huy,


If you call the method callJavascript then you can communicate between Javascript and the loaded ARchitect World context. We also provide an example here https://www.wikitude.com/external/doc/documentation/latest/ios/pluginsapi.html#plugin-base-class.


Thanks

Eva

Hi Eva,

Thanks for your reply. It is working now. :)

Login or Signup to post a comment