-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from BohdanOne/25-home-page-do-not-load-gpx-data
fix: prevent premature data fetching
- Loading branch information
Showing
2 changed files
with
20 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DOMParser } from 'xmldom'; | ||
// @ts-expect-error - no types | ||
import togeojson from '@mapbox/togeojson'; | ||
|
||
import type { GeoJson } from '$lib/types'; | ||
|
||
/** | ||
* Parses a GPX string and converts it to GeoJSON format. | ||
* @param gpx - The GPX string to parse. | ||
* @returns A promise that resolves to a GeoJSON object. | ||
*/ | ||
export default async function getGeoJson(gpx: string): Promise<GeoJson> { | ||
const parser = new DOMParser(); | ||
|
||
const parsedGPX = parser.parseFromString(gpx, 'application/gpx+xml'); | ||
|
||
return togeojson.gpx(parsedGPX); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters