cpnav/lib/pages/pass_track/controller.dart
2024-09-06 09:52:06 +08:00

97 lines
2.7 KiB
Dart

import 'dart:ui';
import 'package:get/get.dart';
import 'package:scence_map/controller.dart';
import 'package:cpnav/service/base.dart';
import 'package:pass_track/pass_track.dart';
import 'sevice/file_handle.dart';
FileHandle fileHandle = FileHandle();
class PassTrackController extends GetxController {
int allLen = 0;
final mapController = Get.put(ScenceMapController());
String projCode;
String projType;
late final GetServices service;
// final PassTrack _passTrackPlugin;
PassTrackController(this.projCode, this.projType);
@override
void onInit() {
super.onInit();
service = GetServices(projCode: projCode, projType: projType);
loadProject();
loadSideLine();
loadBindDevice();
// getHisFileList();
}
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<String, dynamic>;
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);
}
}
getHisFileList(PassTrack passTrackPlugin) async {
Map textlist = await GetServices().getHisFileList();
List fileList = textlist['list'];
for (var i = 0; i < fileList.length; i++) {
var file = fileList[i];
var jsData = await GetServices().getHisFile(file);
int len = fileHandle.resolveJson(jsData, passTrackPlugin);
allLen += len;
// print("$pointList");
// var totalList =fileHandle.allPointData;
}
print("allLen: $allLen");
}
}