All Apps and Add-ons

Call external function from JavaScript file - XML dashboard

SP987541
Explorer

Hello,
I'm trying to use an external javasript library (https://github.com/manuelbieh/Geolib) within the javascript that is called from the XML Dashboard.
code of javascript included directly in XML dashboard:
var polygon2 = [
{"latitude": 51.513357512, "longitude": 7.45574331, "elevation":523.92},
{"latitude": 51.515400598, "longitude": 7.45518541, "elevation":524.54},
];
require(['Geolib-master/src/geolib'], function($){
box = geolib.getCenterOfBounds(polygon2);
alert ("center Lat: " + box.latitude + "Lon: "+box.longitude );
});

I get the error: ReferenceError: Can't find variable: geolib
the geolib.js file is stored in the path Splunk/share/splunk/search_mrsparkle/exposed/js/Geolib-master/src
Thank you in advance for your help!

0 Karma
1 Solution

SP987541
Explorer

I tried different things, and this finally worked out for me:
1. copied the geolib.js file to Splunk/share/splunk/search_mrsparkle/exposed/js
2. changed the code from: require(['Geolib-master/src/geolib'], function($){
to: require(['geolib'], function(geolib){

I don't fully understand, but it is working 🙂

View solution in original post

0 Karma

SP987541
Explorer

I tried different things, and this finally worked out for me:
1. copied the geolib.js file to Splunk/share/splunk/search_mrsparkle/exposed/js
2. changed the code from: require(['Geolib-master/src/geolib'], function($){
to: require(['geolib'], function(geolib){

I don't fully understand, but it is working 🙂

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...