togpx not defined when trying to convert from geojson

Viewed 87

I'm trying to convert a geojson file to a gpx file in javascript using the togpx method that I found here: https://github.com/tyrasd/togpx

The problem is that when I try to save the file I receive the error Uncaught ReferenceError: togpx is not defined, even if I put the library in my browser page and installed as a command line tool.

This is my code:

document.getElementById('export').onclick = function(e) {
            var gpxFile;
        // Extract GeoJson from drawnItems
        var data = drawnItems.toGeoJSON();

        // Stringify the GeoJson
        var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data));

        gpxFile = togpx(convertedData);  //here I have the error
        var convertedGpx = 'text/xml;charset=utf-8,' + encodeURIComponent(gpxFile);

        // Create export
        document.getElementById('export').setAttribute('href', 'data:' + convertedGpx);
        document.getElementById('export').setAttribute('download', 'route.gpx');
    }

And I added the library using <script src='togpx.js'></script>

Can you help me with that?

0 Answers
Related