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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...