leaflet-gpx icon indicating copy to clipboard operation
leaflet-gpx copied to clipboard

multi-tracks gpx

Open jeromectm opened this issue 2 years ago • 0 comments

As suggested by https://github.com/mpetazzoni/leaflet-gpx/issues/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());
		});
	}
});

jeromectm avatar Apr 21 '22 15:04 jeromectm