e.createTooltipFunc is not a function
Hello,
My API returns data escaped in double quotes. As a result, the createTooltipFunc/clickHandlerFunc is returned as a string which then fails to be called as a function.
What should I do?
"hotSpots": [
{
"type": "info",
"pitch": "6.1",
"yaw": "-7.6",
"createTooltipArgs": "Living",
"clickHandlerArgs": "/living",
"createTooltipFunc": "customLink",
"clickHandlerFunc": "customLinkClick"
}
]
You're passing a string not a function. Assuming customLink and customLinkClick are your function names, drop the quotation marks around the names to specify the functions themselves instead of strings that contain the function name.
Agree with @mpetroff but when you use a json file e.g. https://cdn.pannellum.org/2.5/pannellum.htm#config=https://pannellum.org/configs/tour.json then it is not possible to specify the function by name as the parser recognize it's a string. Any solution for that? Thanks
@SharmPRO A JSON file can't contain a JavaScript function reference, so, no, it's not possible to use custom click handlers there (and the standalone viewer wouldn't have your functions in it anyway).
Hi, @mpetroff what do you think to solve that problem like this: replace if(a.createTooltipFunc)a.createTooltipFunc(f,a.createTooltipArgs); with if(a.createTooltipFunc){if(typeof a.createTooltipFunc == 'string')window[a.createTooltipFunc](f,a.createTooltipArgs)}else{a.createTooltipFunc(f,a.createTooltipArgs)};
Same concept for a.clickHandlerFunc ...
I hacked the scripts (pannellum.js and pannellum.htm) and it works.
The only constrain of this solution is to have the function specified in 'createTooltipFunc' should be defined 'globally'
Trying to implement an editor to produce tours with scene navigation, custom hotspot markers, custom info tooltip and graph flow, preview to produce a full featured json configuration file to feed your script.
Thank for your time

The solution is to provide a function reference, not a function name. How you perform such a replacement prior to passing the configuration object to Pannellum is up to you.
Hi, as you said the function reference is not an option when .json config is used in standalone version. In the same pannellum.htm I included the definition of such function in a pannellum-custom.js file and a pannellum-custom.css to decorate the output.
The standalone version isn't designed for such integrations. You're of course more than welcome to use it as a starting example for your own use of the API, as you seem to have done, but don't expect such functionality to be included by default.