194 lines
6.3 KiB
Dart
194 lines
6.3 KiB
Dart
import 'dart:ui';
|
|
import "dart:ffi" as ffi;
|
|
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();
|
|
ScenceMapController mapcontroller = Get.put(ScenceMapController());
|
|
|
|
class PassTrackController extends GetxController {
|
|
var tileCount = 0.obs;
|
|
var tileFirst = 0.obs;
|
|
var tileLast = 0.obs;
|
|
final mapController = Get.put(ScenceMapController());
|
|
|
|
String projCode;
|
|
String projType;
|
|
var speed = 1.obs;
|
|
late final GetServices service;
|
|
|
|
PassTrackController(this.projCode, this.projType);
|
|
Map<String, int> deviceMap = {};
|
|
Map<String, int> coorTransMap = {};
|
|
// final PassTrack _passTrackPlugin;
|
|
final PassTrack _passTrackPlugin = PassTrack();
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
service = GetServices(projCode: projCode, projType: projType);
|
|
loadProject();
|
|
// loadSideLine();
|
|
loadBindDevice();
|
|
// getHisFileList();
|
|
var future = getHisFileList(_passTrackPlugin);
|
|
|
|
// var maxLen =
|
|
// controller.allLen > 0 ? controller.allLen : 1.0; // 确保 maxLen 大于 0
|
|
// _rangevalues = SfRangeValues(0.0, maxLen);
|
|
// SchedulerBinding.instance.addPostFrameCallback((_) async {
|
|
// sWidth = sqrt(screen.width * screen.width + screen.height * screen.height)
|
|
// .ceil();
|
|
|
|
// // scenceMapController.scale = passTrackPlugin.passTrack_getScale() * 1.0;
|
|
// fileHandle.date = widget.date;
|
|
// await fileHandle.init();
|
|
// //在帧绘制完成后执行数据渲染
|
|
// // await initPlatformState();
|
|
// if (fileHandle.pointData.isNotEmpty) {
|
|
// DecodeDataObj obj = fileHandle.pointData[0].obj!;
|
|
// scenceMapController.centerXY = Offset(obj.y / 20, obj.x / 20);
|
|
// }
|
|
|
|
// for (var item in fileHandle.deviceList) {
|
|
// if (item["point"] != null) {
|
|
// bits = item["bits"];
|
|
// break;
|
|
// }
|
|
// }
|
|
// // passTrackPlugin.map_setCenterDevice(bits);
|
|
// setState(() {
|
|
// if (fileHandle.pointData.isNotEmpty) {
|
|
// maxLength = fileHandle.pointData.length;
|
|
// // _value = maxLength;
|
|
// _rangevalues = SfRangeValues(0.0, maxLength.toDouble());
|
|
// }
|
|
// });
|
|
// });
|
|
|
|
var f = initPlatformState();
|
|
|
|
f.then((void _) {
|
|
_passTrackPlugin.setGridColor(const Color.fromARGB(255, 0, 0, 0).value);
|
|
_passTrackPlugin.drawGrid();
|
|
|
|
future.then((value) {
|
|
_passTrackPlugin.setScale(1);
|
|
for (var TID in deviceMap.keys) {
|
|
_passTrackPlugin.addDevice(int.parse(TID), 0);
|
|
}
|
|
for (var item in coorTransMap.entries) {
|
|
print("tid:${item.key} value:${item.value}");
|
|
}
|
|
// 统计用时 获取当前时间
|
|
var start = DateTime.now().millisecondsSinceEpoch;
|
|
// _passTrackPlugin.generateTile(0, value);
|
|
_passTrackPlugin.waitForTile(() {
|
|
var start = DateTime.now().millisecondsSinceEpoch;
|
|
print("len: ${_passTrackPlugin.allTileCnt()}");
|
|
tileCount.value = _passTrackPlugin.allTileCnt();
|
|
// _rangevalues = SfRangeValues(0, _passTrackPlugin.allTileCnt());
|
|
_passTrackPlugin.playTrack(
|
|
0, _passTrackPlugin.allTileCnt(), true, 0, ffi.nullptr);
|
|
var end = DateTime.now().millisecondsSinceEpoch;
|
|
print("play: ${end - start}");
|
|
});
|
|
// _passTrackPlugin.drawGrid();
|
|
// 获取当前时间
|
|
});
|
|
});
|
|
}
|
|
|
|
loadBindDevice() async {
|
|
var binddevices = await service.getDeviceBind();
|
|
for (var device in binddevices) {
|
|
var dev = DeviceItem.fromJson(device);
|
|
deviceMap[dev.TID.toString()] = 0;
|
|
// deviceMap[dev.TID as String] = dev[int.parse(dev["width"])];
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
Future<int> 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().getHisFil1(file);
|
|
print("have message");
|
|
int len = fileHandle.resolveJson(jsData, passTrackPlugin);
|
|
tileCount.value += len;
|
|
if (tileCount.value >= 20000) {
|
|
break;
|
|
}
|
|
}
|
|
coorTransMap = fileHandle.pointsMap;
|
|
return tileCount.value;
|
|
}
|
|
|
|
Future<void> initPlatformState() async {
|
|
String platformVersion;
|
|
try {
|
|
platformVersion = await _passTrackPlugin.getPlatformVersion() ??
|
|
'Unknown platform version';
|
|
} on Exception {
|
|
platformVersion = 'Failed to get platform version.';
|
|
}
|
|
await _passTrackPlugin.create(
|
|
mapcontroller.height.toInt(), mapcontroller.width.toInt());
|
|
fileHandle.textureId = await _passTrackPlugin.getTextureId() ?? -1;
|
|
print("textureId: ${fileHandle.textureId}");
|
|
print("${mapcontroller.height.toInt()}");
|
|
|
|
// if (!mounted) Exception('Failed to get textureId.');
|
|
|
|
// setState(() {
|
|
// platformVersion = platformVersion;
|
|
// });
|
|
return;
|
|
}
|
|
}
|