Members
(constant) auth :google.auth.GoogleAuth
The Google Auth object for authentication with Google Drive.
Type:
- google.auth.GoogleAuth
(constant) categories :Array.<string>
The list of categories for the GPX traces.
Type:
- Array.<string>
(constant) drive :google.drive
The Google Drive object for interacting with the Google Drive API.
Type:
- google.drive
(constant) gpxFilesDir :string
The path to the output dir where the processed gpx files were saved.
Type:
- string
Methods
addCurrentPositionToMap(position)
Adds the current GPS position to the map.
Parameters:
Name | Type | Description |
---|---|---|
position |
Object | The position object containing latitude and longitude. |
cleanGpxFilesDirectory(gpxFilesDir)
Cleans the GPX files directory by deleting all files in it.
Parameters:
Name | Type | Description |
---|---|---|
gpxFilesDir |
string | The directory to clean. |
(async) downloadGpxFile(fileId, fileName, gpxFilesDir) → {Promise.<string>}
Downloads a GPX file from Google Drive and saves it to the specified directory.
Parameters:
Name | Type | Description |
---|---|---|
fileId |
string | The ID of the file to download. |
fileName |
string | The name of the file to download. |
gpxFilesDir |
string | The directory to save the downloaded file. |
Returns:
A promise that resolves to the path of the downloaded file.
- Type
- Promise.<string>
ensureDataDirectoryExists(tracesFilePath)
Ensures that the data directory exists, creating it if necessary.
Parameters:
Name | Type | Description |
---|---|---|
tracesFilePath |
string | The path to the output file where the processed traces will be saved. |
ensureGpxFilesDirectoryExists(gpxFilesDir)
Ensures that the GPX files directory exists, creating it if necessary.
Parameters:
Name | Type | Description |
---|---|---|
gpxFilesDir |
string | The directory to check and create if necessary. |
getCategory(sanitizedName) → {string}
Determines the category of a trace based on its sanitized name.
Parameters:
Name | Type | Description |
---|---|---|
sanitizedName |
string | The sanitized name of the trace. |
Returns:
The category of the trace.
- Type
- string
getColor(category) → {string}
Returns the color associated with a given category.
Parameters:
Name | Type | Description |
---|---|---|
category |
string | The category of the trace. |
Returns:
The color associated with the category.
- Type
- string
getCoordinates(trkpts) → {Array.<Object>}
Extracts the coordinates from the track points in a GPX file.
Parameters:
Name | Type | Description |
---|---|---|
trkpts |
Array.<Object> | The array of track point objects. |
Returns:
The array of coordinate objects.
- Type
- Array.<Object>
getWeight(category) → {number}
Returns the weight associated with a given category.
Parameters:
Name | Type | Description |
---|---|---|
category |
string | The category of the trace. |
Returns:
The weight associated with the category.
- Type
- number
handleError(error)
Handles errors when getting the current position.
Parameters:
Name | Type | Description |
---|---|---|
error |
Object | The error object. |
initializeMap(gpxFilesDir, tracesFilePath) → {L.Map}
Initializes the map and loads GPX traces from a given directory and file path.
Parameters:
Name | Type | Description |
---|---|---|
gpxFilesDir |
string | The directory where GPX files are stored. |
tracesFilePath |
string | The path to the JSON file containing trace data. |
Returns:
The initialized Leaflet map instance.
- Type
- L.Map
Example
initializeMap('/path/to/gpx/files', '/path/to/traces.json');
The JSON file should have the following structure:
{
"traces": [
{
"name": "Trace Name",
"sanitizedName": "trace-name",
"category": "category-name",
"coordinates": [
{ "lat": 47.325, "lon": -1.736 },
...
]
},
...
]
}
(async) listGpxFiles() → {Promise.<Array.<Object>>}
Lists the GPX files in the specified Google Drive folder.
Returns:
A promise that resolves to an array of file objects.
- Type
- Promise.<Array.<Object>>
(async) processGpxFiles(gpxFilesDir, tracesFilePath) → {Promise.<void>}
Processes the GPX files in the specified directory and generates a JSON file with the trace data.
Parameters:
Name | Type | Description |
---|---|---|
gpxFilesDir |
string | The directory containing the GPX files to process. |
tracesFilePath |
string | The path to the output file where the processed traces will be saved. |
Returns:
A promise that resolves when the processing is complete.
- Type
- Promise.<void>
removeCurrentPositionFromMap()
Removes the current GPS position marker from the map.
simplifyCoordinates(coordinates) → {Array.<Object>}
Simplifies the coordinates by keeping one point every 10 meters using Turf.js.
Parameters:
Name | Type | Description |
---|---|---|
coordinates |
Array.<Object> | The array of coordinate objects. |
Returns:
The simplified array of coordinate objects.
- Type
- Array.<Object>
(async) writeTracesJson(traces, tracesFilePath) → {Promise.<void>}
Writes the processed trace data to a JSON file.
Parameters:
Name | Type | Description |
---|---|---|
traces |
Array.<Object> | The array of trace objects to write. |
tracesFilePath |
string | The path to the output file where the processed traces will be saved. |
Returns:
A promise that resolves when the writing is complete.
- Type
- Promise.<void>