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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...