import 'dart:ui'; import 'package:get/get.dart'; import 'package:cpnav/service/base.dart'; import 'package:scence_map/controllers/controller.dart'; import 'package:scence_map/record_entity.dart'; class PassTrackController extends GetxController { final mapController = Get.put(ScenceMapController()); String projCode; String projType; late final GetServices service; RecordEntity? selectedPilePoint; PassTrackController(this.projCode, this.projType); @override void onInit() { super.onInit(); service = GetServices(projCode: projCode, projType: projType); loadProject(); loadSideLine(); // loadBindDevice(); loadRcordList(); } loadBindDevice() async { var binddevices = await service.getDeviceBind(); for (var device in binddevices) { var dev = DeviceItem.fromJson(device); mapController.deviceList[dev.TID] = dev; } } loadCoorTrans() async {} loadProject() async {} loadSideLine() async { var data = await service.getSideLine(); double maxX = -double.infinity; double maxY = -double.infinity; double minX = double.infinity; double minY = double.infinity; var sideLineData = data as Map; // var sideLineData = data; sideLineData.forEach((group, items) { for (var item in items) { SideLineItem sideLineItem = SideLineItem.fromJson(item); var sideLineList = mapController.sideLinListeMap[group]; if (sideLineList == null) { sideLineList = []; mapController.sideLinListeMap[group] = sideLineList; } sideLineList.add(sideLineItem); if (sideLineItem.x > maxX) { maxX = sideLineItem.x; } if (sideLineItem.y > maxY) { maxY = sideLineItem.y; } if (sideLineItem.x < minX) { minX = sideLineItem.x; } if (sideLineItem.y < minY) { minY = sideLineItem.y; } } }); if (maxX != -double.infinity && maxY != -double.infinity && minX != double.infinity && minY != double.infinity) { mapController.centerXY = Offset((maxX + minX) / 2, (maxY + minY) / 2); } } loadRcordList() async { List record = await service.getRcordList("2024-08-7"); if (record.isNotEmpty) { for (var i = 0; i < record.length; i++) { RecordEntity item = RecordEntity.fromJson(record[i]); mapController.recordList.add(item); } mapController.centerXY = Offset( mapController.recordList[mapController.recordList.length - 1].x, mapController.recordList[mapController.recordList.length - 1].y); //将地图或画布的中心定位到最新记录的位置上 } } }