Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi-tracks gpx #134

Closed
wants to merge 1 commit into from
Closed

multi-tracks gpx #134

wants to merge 1 commit into from

Conversation

jeromectm
Copy link

As suggested by #123, added a "trackNumber" option to return a single track, when the gpx file contains multiple ones. The name, desc etc are then returned from this track. Also added get_number_of_tracks() to count the tracks.

I am not a javascript expert, maybe there is a better way to go; but I used this like this:

var colors = ['#0000FF', '#FF00FF', '#25DB00', '#FF0000', '#00C0FF', '#FF7F00', '#A46129'];
new L.GPX(groupGpxURL, {async: true, marker_options: opts}).on('loaded', function(e) {
	var gpx = e.target;
	for (trackIdx=0; trackIdx<gpx.get_number_of_tracks(); trackIdx++) {
		var polyline_options = {
			color: colors[trackIdx % colors.length],
			opacity: 0.5,
			weight: 7,
			lineCap: 'round'
		};
		new L.GPX(groupGpxURL, {async: true, marker_options: opts, trackNumber: trackIdx, polyline_options: polyline_options}).on('loaded', function(e) {
			var gpxTrack = e.target;
			gpxTrack.addTo(map);
			layerControl.addOverlay(gpxTrack, gpxTrack.get_name());
		});
	}
});

As suggested by mpetazzoni#123, added a "trackNumber" option to return a single track, when the gpx file contains multiple ones. The name, desc etc are then returned from this track. Also added get_number_of_tracks() to count the tracks.
@jeromectm jeromectm changed the title Update gpx.js multi-tracks gpx Apr 21, 2022
@jeromectm
Copy link
Author

Hello, any chance you merge this change? Thanks!

@mpetazzoni
Copy link
Owner

If the point is to be able to style each track separately, and the source GPX file can't be modified to use the GPX Style extension data as shown in https://github.com/mpetazzoni/leaflet-gpx#line-styling, I think the best option is to modify how polyline_options work to take an array of objects, applied to each track. This feels cleaner than what you're doing here, which will have you re-parse the same GPX many times just to skip over N-1 tracks each time. I'll see if I can prepare a diff for that.

@jeromectm
Copy link
Author

One point is to style each track separately, but more importantly, as explained in #123, is to let user toggle which track to display or not.
Thanks!

@mpetazzoni
Copy link
Owner

Thanks, I'll make sure to add support for that too.

@mpetazzoni mpetazzoni closed this Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants