How to get value from a js function

1.3k views Asked by At

I'm using the KRPano plugin for street viewer. I've a <hotspot> that needs to show a tooltip with a value when I click on it. That value I need to take it from a JS function. So I added a <style> to my hotspot:

<style name="styletooltips"
    onclick="exhibit(); set(layer[text].html, get(js(getText()))); "           
/>

My js function:

function getText()
{
    return "Hello World!";
}

I tried it that way but I keep getting null. If I take out the getbefore the js it shows literally js(getText()).

P.D: the exhibit() is KRPano action that shows the layer with the tooltip.

1

There are 1 answers

3
Dylan Corriveau On BEST ANSWER

I haven't used KRPano very much, nor do I have an enviroment to test atm, but I do believe the get isn't necessary. I believe you would just need to do:

<style name="styletooltips"
    onclick="exhibit(); set(layer[text].html, js(getText())); "           
/>

If you look in the KRPano documentation, it says the get will try to:

Resolve the 'variable' to its value.

In this case, there isn't a variable in use, just a method. You should be safe to just call js and use the return (since it is a string literal).

Edit: I just noticed the parameters list for get, and it makes complete sense for your instance.

variable (Any Variable):
When the variable doesn't exists, then get() will return null.

Edit 2: Another option would be to try setting a variable with the value, then passing that. Example:

<style name="styletooltips"
    onclick="exhibit(); var item = js(getText()); set(layer[text].html, item)); "           
/>