pannellum icon indicating copy to clipboard operation
pannellum copied to clipboard

e.createTooltipFunc is not a function

Open joshuakoh1 opened this issue 4 years ago • 7 comments

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"
                }
            ]

joshuakoh1 avatar May 30 '21 10:05 joshuakoh1

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.

mpetroff avatar Jun 09 '21 15:06 mpetroff

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 avatar Feb 23 '23 18:02 SharmPRO

@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).

mpetroff avatar Feb 24 '23 23:02 mpetroff

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 Screen Shot 2023-02-25 at 02 17 53 Screen Shot 2023-02-25 at 02 22 37

SharmPRO avatar Feb 25 '23 00:02 SharmPRO

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.

mpetroff avatar Mar 07 '23 17:03 mpetroff

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.

SharmPRO avatar Mar 07 '23 18:03 SharmPRO

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.

mpetroff avatar Mar 15 '23 01:03 mpetroff