Small and fast GPX to GeoJSON converter library for JavaScript
Here you can directly convert a GPX file to GeoJSON using the GPX2GeoJSON library.
Note: The file never leaves your PC and is directly converted inside your browser.
text
to pretty printed JSON in variable jsonstr
using the GPX2GeoJSON library:
const json = GPX2GeoJSON.fromText(text, {
"addAltitude": ADDALT.checked
});
const jsonstr = JSON.stringify(json, null, " ");
This was actually the main goal for the GPX2GeoJSON project. Leaflet only directly supports GeoJSON to create feature layers. GPX2GeoJSON allows you to use GPX files just as easy as GeoJSON files. This allows to mix GeoJSON and GPX on one map while always having the exact same interface for all layers.
GPX2GeoJSON.fromURL("fells_loop.gpx").then((geojson) => {
L.geoJSON(geojson).addTo(map);
});