map_watch.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:common_pub/logger.dart';
  2. import 'package:common_pub/service/controller.dart';
  3. import 'package:common_pub/ui/map_view/map_view.dart';
  4. import 'package:common_pub/ui/map_view/view_map_trace.dart';
  5. import 'package:track_common/model.dart';
  6. class Flag {
  7. Flag(this.value);
  8. int value;
  9. Color get color => Color(value);
  10. @override
  11. bool operator ==(Object other) {
  12. if (other is Flag) {
  13. return value == other.value;
  14. }
  15. return false;
  16. }
  17. @override
  18. int get hashCode => value.hashCode;
  19. static final red = Flag(0xffff0000);
  20. static final yellow = Flag(0xffffcb00);
  21. static final blue = Flag(0xff00a0ff);
  22. static List<Flag> get values => [red, yellow, blue];
  23. }
  24. class UserOnMap {
  25. var info = UserInfo();
  26. int get id => info.id;
  27. String get name => info.name;
  28. var startAt = DateTime.now();
  29. var cpList = <ControlPoint>[];
  30. final isHide = false.obs;
  31. var trace = <TracePoint>[].obs;
  32. var flag = Flag.red.obs;
  33. String routeName = '';
  34. int heartRatePercent = 0;
  35. Pace pace = Pace.perKm(99.hours);
  36. var distance = 0.km;
  37. List<HeartRate> hrInfo = [];
  38. List<Position> positionList = [];
  39. Duration get duration => DateTime.now().difference(startAt);
  40. ControlPoint? nextWant;
  41. Distance get nextDistance {
  42. final one = nextWant;
  43. if (one != null) {
  44. final p1 = one.position;
  45. final p22 = positionList.lastOrNull;
  46. if (p22 != null) {
  47. return p1.distance(p22);
  48. }
  49. }
  50. return const Distance(m: 1000);
  51. }
  52. String get nextCPSN {
  53. return nextWant?.snString ?? '';
  54. }
  55. }
  56. class EventOnMap {
  57. var info = EventInfo();
  58. var userList = <UserOnMap>[];
  59. int get id => info.id;
  60. String get name => info.name;
  61. int get cpAllCount => info.cpAllCount;
  62. final isHide = false.obs;
  63. }
  64. abstract class MapWatchService extends GetxService {
  65. final Rx<MapWatch?> _instance = Rx(null);
  66. MapWatch? get instance => _instance.value;
  67. @protected
  68. Future<MapWatch> newInstanceByMap(MapInfo info);
  69. Future<void> setMap(MapInfo mapInfo) async {
  70. final thisInstance = await newInstanceByMap(mapInfo);
  71. thisInstance.addPlugs([thisInstance.plugMap]);
  72. _instance.value = thisInstance;
  73. thisInstance.init();
  74. thisInstance.workFlushData();
  75. }
  76. }
  77. abstract class MapWatch extends PlugController {
  78. Future<void> workFlushData() async {
  79. while (isActive) {
  80. try {
  81. // await flushData();
  82. } catch (e) {
  83. error(e);
  84. }
  85. await 1.seconds.delay();
  86. }
  87. }
  88. EventOnMap? getEventById(int id) {
  89. for (final one in eventList) {
  90. if (one.id == id) {
  91. return one;
  92. }
  93. }
  94. return null;
  95. }
  96. MapWatch({required this.id});
  97. final int id;
  98. String name = '';
  99. final plugMap = PlugMap();
  100. final eventList = <EventOnMap>[].obs;
  101. @protected
  102. Future<List<EventOnMap>> getEventList(int mapId);
  103. }