37 lines
820 B
Dart
37 lines
820 B
Dart
import 'package:latlong2/latlong.dart';
|
|
|
|
class GpxTrack {
|
|
final String name;
|
|
final Set<List<LatLng>> tracks;
|
|
|
|
const GpxTrack({
|
|
required this.name,
|
|
required this.tracks,
|
|
});
|
|
|
|
bool get isEmpty => tracks.every((segment) => segment.isEmpty);
|
|
|
|
int get pointCount => tracks.fold<int>(
|
|
0,
|
|
(sum, segment) => sum + segment.length,
|
|
);
|
|
|
|
LatLng? get center {
|
|
final points = tracks.expand((segment) => segment).toList();
|
|
if (points.isEmpty) return null;
|
|
|
|
final latitude = points.fold<double>(
|
|
0,
|
|
(sum, point) => sum + point.latitude,
|
|
) /
|
|
points.length;
|
|
|
|
final longitude = points.fold<double>(
|
|
0,
|
|
(sum, point) => sum + point.longitude,
|
|
) /
|
|
points.length;
|
|
|
|
return LatLng(latitude, longitude);
|
|
}
|
|
}
|