• Resolved akoelsch

    (@akoelsch)


    Hi,
    I tried to load my gpx track, but it doesn’t work. The sample gpx track from the shortcode documentation works though.

    [leaflet-map fitbounds]
    [leaflet-gpx src="wp-content/uploads/2021/09/track.gpx" color=black]

    According to DevTools, the file is retrieved by leaflet-ajax-geojson.min.js?ver=3.0.2 but there’s an uncaught error in the console.

    Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
        at get (togeojson.js?ver=3.0.2:15)
        at Object.gpx (togeojson.js?ver=3.0.2:302)
        at XMLHttpRequest.request.t.onreadystatechange (leaflet-ajax-geojson.min.js?ver=3.0.2:1)

    I’m not sure what is the problem here. The file works perfectly fine in other apps.

Viewing 3 replies - 16 through 18 (of 18 total)
  • Plugin Contributor hupe13

    (@hupe13)

    It’s not a wp.com installation.

    I misinterpreted this, but these calls are now gone.

    Write in your .htaccess file above the WordPress lines:

    RewriteEngine On
    RewriteRule .*\.gpx$ - [L,T=application/gpx+xml]

    P.S. Backup this file and use an editor like Notepad++!

    • This reply was modified 4 years, 9 months ago by hupe13.
    Plugin Author bozdoz

    (@bozdoz)

    I agree with this. It looks to me like it’s reading the xml as text instead of xml.

    See this if statement: https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/scripts/leaflet-ajax-geojson.js#L32-L36

    if (type === 'json') {
      data = JSON.parse(xhr.responseText);
    } else if (['kml', 'gpx'].indexOf(type) !== -1) {
      data = window.toGeoJSON[type](xhr.responseXML);
    }

    It’s reading the type as ‘gpx’, but there is no xhr.responseXML. There is, however, a value for xhr.responseText. So it should just be a matter of fixing the mimetype/content-type, like @hupe13 said.

    Thread Starter akoelsch

    (@akoelsch)

    Cool, this fixed the issue. Thanks! However, I’ll stick with @hupe13’s extension which was already working before.

Viewing 3 replies - 16 through 18 (of 18 total)

The topic ‘Cannot load GPX file’ is closed to new replies.