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!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...