Hi,
I have a custom map plugin and I would like to access/call a js function, actually a function from Leaflet.js library, in the plugin. I would like to call this function from the xml file, i.e. from a krpano action called by an event, "onstart" a new scene.
Can anyone tell me how to do that?
There are several ways - e.g. expose your Javascript function as function on the plugin object:
|
Source code
|
1
2
3
4
|
plugin.my_function = function()
{
...
}
|
When that plugins is included in krpano e.g. this way:
|
Source code
|
1
|
<plugin name="my_plugin" url="my_plugin.js" ... preload="true" />
|
(preload=true to have it loaded before the newscene event)
Then you can call it from xml this way:
|
Source code
|
1
2
3
|
<events name="my_events" keep="true"
onnewscene="plugin[my_plugin].my_function();"/
/>
|
(Important: use an 'own' named <events> element to avoid conflicts with other code when using the global ones)
Or if you want, you can create that event also directly in your plugin:
|
Source code
|
1
2
3
4
5
6
7
|
krpano.set("events[my_events].keep", true);
krpano.set("events[my_events].onnewscene", my_onnewscene_function);
...
function my_onnewscene_function()
{
...
}
|
For more information please see the documentation about the plugin API:
https://krpano.com/docu/plugininterface/#top
and have also a look into the plugin examples sources provided here:
https://krpano.com/docu/plugininterface/#examples
Best regards,
Klaus