PageSourceSearch

https://lamitja.cat/app-circuits/js/gpx-parser.js

js lamitja.cat collected 2026-10-02 07:29:44 UTC 642 bytes, 15 lines download raw bytes

1// Minimal GPX parser — extracts track points as [lat, lng] array.
2window.parseGPX = async function parseGPX(url) {
3  const res = await fetch(url);
4  if (!res.ok) throw new Error(`No s'ha pogut carregar ${url}`);
5  const text = await res.text();
6  const xml = new DOMParser().parseFromString(text, "application/xml");
7  const pts = xml.getElementsByTagName("trkpt");
8  const coords = [];
9  for (let i = 0; i < pts.length; i++) {
10    const lat = parseFloat(pts[i].getAttribute("lat"));
11    const lon = parseFloat(pts[i].getAttribute("lon"));
12    if (!Number.isNaN(lat) && !Number.isNaN(lon)) coords.push([lat, lon]);
13  }
14  return coords;
15};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.