bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

Possible GPX file issue with geojson #146

Closed sigg3 closed 2 years ago

sigg3 commented 2 years ago

Getting an error message when trying to use leaflet-gpx (see below).

$ cat leaflet_test-togeojson.log 
togeojson.js?ver=3.0.2:15 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)
get @ togeojson.js?ver=3.0.2:15
gpx @ togeojson.js?ver=3.0.2:302
request.t.onreadystatechange @ leaflet-ajax-geojson.min.js?ver=3.0.2:1
XMLHttpRequest.send (async)
onAdd @ leaflet-ajax-geojson.min.js?ver=3.0.2:1
_layerAdd @ Layer.js:114
whenReady @ Map.js:1465
addLayer @ Layer.js:176
addLayer @ LayerGroup.js:47
addLayer @ FeatureGroup.js:35
addTo @ Layer.js:52
WPLeafletgpxShortcode @ (index):363
t @ construct-leaflet-map.min.js?ver=3.0.2:1
init @ construct-leaflet-map.min.js?ver=3.0.2:1
load (async)
(anonymous) @ construct-leaflet-map.min.js?ver=3.0.2:1
(anonymous) @ construct-leaflet-map.min.js?ver=3.0.2:1

Could be because the file is huge (even pruned it has some 400 points). What do you think?

sigg3 commented 2 years ago

Reading the togeojson FAQ it seems like some GPX and KML features are unsupported:

KML is a very complex format with many features. Some of these features, like NetworkLinks, folders, and GroundOverlays, don't have a GeoJSON equivalent. In these cases, toGeoJSON doesn't convert the features. It also doesn't crash on these constructs: toGeoJSON should be able to run on all valid KML and GPX files without crashing: but for some files it may have no output.

This might be what I'm seeing, according to this issue @ mapbox/togeojson.

I'll try to remove some layers before pushing it to leaflet.

sigg3 commented 2 years ago

Turns out the file was not the issue.

Removing zoom="15" and instead using fitbounds solved the issue for me (DOH).

Anyway, before I got there, I did convert my files to GeoJSON using these instructions. I believe on-the-fly conversion from gpx or kml to geojson (leaflet native format) is brittle.