Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const DEFAULT_OPTIONS = {
}
};

// Color mapping for different activity types
const ACTIVITY_COLORS = {
'walking': '#ffc0cb',
'hiking': '#ffc0cb',
'running': '#ff0000',
'cycling': '#00ff00',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more note actually -- could you keep the original colors here?

Copy link
Contributor Author

@pthon pthon Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For walking and hiking I changed to the original colors.
I still kept cycling now being green instead of cyan, as I added swimming as blue think the old cyan is very close to the default one and 3 blueish colors are hard to distinguish.

I'm still open to changing it to original behavior if this is important to you, though 😉 .

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, no strong preference from me here. Feels like this should be customizable at some point anyway (not for this PR though)

'swimming': '#0000ff',
};


export default class GpxMap {
constructor(options) {
Expand Down Expand Up @@ -233,12 +242,23 @@ export default class GpxMap {
let lineOptions = Object.assign({}, this.options.lineOptions);

if (lineOptions.detectColors) {
// set line option color depending on activity type:
if (track.activityType) {
const color = ACTIVITY_COLORS[track.activityType.toLowerCase()];
if (color) {
lineOptions.color = color;
}
}

// Legacy support for file-ending colors:
if (/-(Hike|Walk)\.gpx/.test(track.filename)) {
lineOptions.color = '#ffc0cb';
lineOptions.color = ACTIVITY_COLORS["hiking"];
} else if (/-Run\.gpx/.test(track.filename)) {
lineOptions.color = '#ff0000';
lineOptions.color = ACTIVITY_COLORS["running"];
} else if (/-Ride\.gpx/.test(track.filename)) {
lineOptions.color = '#00ffff';
lineOptions.color = ACTIVITY_COLORS["cycling"];
} else if (/-Swim\.gpx/.test(track.filename)) {
lineOptions.color = ACTIVITY_COLORS["swimming"];
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function extractGPXTracks(gpx) {

for (const trk of tracks) {
const name = getTextContent(trk, 'name') || 'untitled';
const activityType = getTextContent(trk, 'type') || null;
let timestamp;

for (const trkseg of queryElements(trk, 'trkseg')) {
Expand All @@ -68,7 +69,7 @@ function extractGPXTracks(gpx) {
}

if (points.length > 0) {
parsedTracks.push({ timestamp, points, name });
parsedTracks.push({ timestamp, points, name, activityType });
}
}
}
Expand Down Expand Up @@ -112,6 +113,7 @@ function extractTCXTracks(tcx, name) {
}

const parsedTracks = [];
const activityType = activities[0].getAttribute('Sport') || null;

for (const activity of activities) {
const laps = queryElements(activity, 'Lap');
Expand Down Expand Up @@ -153,7 +155,7 @@ function extractTCXTracks(tcx, name) {
}

if (points.length > 0) {
parsedTracks.push({ timestamp, points, name });
parsedTracks.push({ timestamp, points, name, activityType });
}
}
}
Expand All @@ -170,6 +172,7 @@ function extractFITTracks(fit, name) {

let timestamp;
const points = [];
const activityType = fit.sport ? fit.sport.sport.toLowerCase() : null;
for (const record of fit.records) {
if (record.position_lat && record.position_long) {
points.push({
Expand All @@ -181,7 +184,7 @@ function extractFITTracks(fit, name) {
record.timestamp && (timestamp = record.timestamp);
}

return points.length > 0 ? [{ timestamp, points, name }] : [];
return points.length > 0 ? [{ timestamp, points, name, activityType }] : [];
}

function extractIGCTracks(igc) {
Expand Down