| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import 'package:common_pub/logger.dart';
- import 'package:common_pub/service/controller.dart';
- import 'package:common_pub/ui/map_view/map_view.dart';
- import 'package:common_pub/ui/map_view/view_map_trace.dart';
- import 'package:track_common/model.dart';
- class Flag {
- Flag(this.value);
- int value;
- Color get color => Color(value);
- @override
- bool operator ==(Object other) {
- if (other is Flag) {
- return value == other.value;
- }
- return false;
- }
- @override
- int get hashCode => value.hashCode;
- static final red = Flag(0xffff0000);
- static final yellow = Flag(0xffffcb00);
- static final blue = Flag(0xff00a0ff);
- static List<Flag> get values => [red, yellow, blue];
- }
- class UserOnMap {
- var info = UserInfo();
- int get id => info.id;
- String get name => info.name;
- var startAt = DateTime.now();
- var cpList = <ControlPoint>[];
- final isHide = false.obs;
- var trace = <TracePoint>[].obs;
- var flag = Flag.red.obs;
- String routeName = '';
- int heartRatePercent = 0;
- Pace pace = Pace.perKm(99.hours);
- var distance = 0.km;
- List<HeartRate> hrInfo = [];
- List<Position> positionList = [];
- Duration get duration => DateTime.now().difference(startAt);
- ControlPoint? nextWant;
- Distance get nextDistance {
- final one = nextWant;
- if (one != null) {
- final p1 = one.position;
- final p22 = positionList.lastOrNull;
- if (p22 != null) {
- return p1.distance(p22);
- }
- }
- return const Distance(m: 1000);
- }
- String get nextCPSN {
- return nextWant?.snString ?? '';
- }
- }
- class EventOnMap {
- var info = EventInfo();
- var userList = <UserOnMap>[];
- int get id => info.id;
- String get name => info.name;
- int get cpAllCount => info.cpAllCount;
- final isHide = false.obs;
- }
- abstract class MapWatchService extends GetxService {
- final Rx<MapWatch?> _instance = Rx(null);
- MapWatch? get instance => _instance.value;
- @protected
- Future<MapWatch> newInstanceByMap(MapInfo info);
- Future<void> setMap(MapInfo mapInfo) async {
- final thisInstance = await newInstanceByMap(mapInfo);
- thisInstance.addPlugs([thisInstance.plugMap]);
- _instance.value = thisInstance;
- thisInstance.init();
- thisInstance.workFlushData();
- }
- }
- abstract class MapWatch extends PlugController {
- Future<void> workFlushData() async {
- while (isActive) {
- try {
- // await flushData();
- } catch (e) {
- error(e);
- }
- await 1.seconds.delay();
- }
- }
- EventOnMap? getEventById(int id) {
- for (final one in eventList) {
- if (one.id == id) {
- return one;
- }
- }
- return null;
- }
- MapWatch({required this.id});
- final int id;
- String name = '';
- final plugMap = PlugMap();
- final eventList = <EventOnMap>[].obs;
- @protected
- Future<List<EventOnMap>> getEventList(int mapId);
- }
|