Új térkép widget, melyet több oldal is használ

This commit is contained in:
2026-05-12 00:14:11 +02:00
parent 7dd642b299
commit f2457817b2
11 changed files with 1718 additions and 434 deletions
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:math' as math;
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:file_picker/file_picker.dart';
@@ -26,6 +26,7 @@ import 'package:terepi_seged/eov/eov.dart';
import 'package:terepi_seged/gnss_sentences/gngga.dart';
import 'package:terepi_seged/gnss_sentences/gngst.dart';
import 'package:terepi_seged/gnss_sentences/gnrmc.dart';
import 'package:terepi_seged/models/measured_point.dart';
import 'package:terepi_seged/models/point_to_measure.dart';
import 'package:terepi_seged/models/point_with_description_model.dart';
import 'package:proj4dart/proj4dart.dart' as proj4;
@@ -33,6 +34,11 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:terepi_seged/pages/map_survey/presentations/views/measured_points_table_dialog.dart';
import 'package:shared_preferences/shared_preferences.dart';
enum MapSurveyMode {
measure, // Bemérés — ahol vagyok, azt rögzítem
stakeout, // Kitűzés — adott ponthoz navigálok, majd rögzítem
}
class MapSurveyController extends GetxController {
// String gpsAddress = "E8:31:CD:14:8B:B2";
// String gpsAddress = "98:CD:AC:62:FF:4E";
@@ -140,6 +146,32 @@ class MapSurveyController extends GetxController {
late Session? session;
late User? user;
final mode = MapSurveyMode.measure.obs;
// ── Közös adatok ──────────────────────────────────────────────
final currentEovY = 0.0.obs;
final currentEovX = 0.0.obs;
final currentEovZ = 0.0.obs;
final accuracy = 0.0.obs;
//final gpsQuality = 0.obs;
// ── Kitűzés adatok — csak stakeout módban aktív ───────────────
final targetEovY = 0.0.obs;
final targetEovX = 0.0.obs;
final targetName = ''.obs;
// Eltérés — valós időben számolódik
double get deltaY => currentEovY.value - targetEovY.value;
double get deltaX => currentEovX.value - targetEovX.value;
double get distanceToTarget => math.sqrt(deltaY * deltaY + deltaX * deltaX);
// Belül a célpont határán vagyunk-e (pl. 0.05 m)
bool get isOnTarget => distanceToTarget < 0.05;
final measuredPoints1 = <MeasuredPoint>[].obs;
static MapSurveyController get to => Get.find();
@override
void onInit() async {
super.onInit();
@@ -741,7 +773,8 @@ class MapSurveyController extends GetxController {
eov.value.X,
gpsLatitude.value,
gpsLongitude.value,
max(gpsLatitudeError.value, gpsLongitudeError.value),
math.max(
gpsLatitudeError.value, gpsLongitudeError.value),
gpsAltitudeError.value));
print(
"pointWithDescriptionList -> ${pointWithDescriptionList.length}");
@@ -760,7 +793,7 @@ class MapSurveyController extends GetxController {
Border.all(width: 1.0, color: Colors.black)),
)));
await dataFile.writeAsString(
"$pointId;$gpsDateTime;${pointDescriptionController.text};${formatEovForFile.format(eov.value.Y)};${formatEovForFile.format(eov.value.X)};$gpsLatitude;$gpsLongitude;$gpsAltitude;${max(gpsLatitudeError.value, gpsLongitudeError.value)};$gpsAltitudeError;${gpsHeightController.text}\r\n",
"$pointId;$gpsDateTime;${pointDescriptionController.text};${formatEovForFile.format(eov.value.Y)};${formatEovForFile.format(eov.value.X)};$gpsLatitude;$gpsLongitude;$gpsAltitude;${math.max(gpsLatitudeError.value, gpsLongitudeError.value)};$gpsAltitudeError;${gpsHeightController.text}\r\n",
mode: FileMode.append);
_measuredPoints.add({
@@ -772,8 +805,8 @@ class MapSurveyController extends GetxController {
"eovY": formatEovForFile.format(eov.value.Y),
"eovX": formatEovForFile.format(eov.value.X),
"description": pointDescriptionController.text,
"horizontalError":
max(gpsLatitudeError.value, gpsLongitudeError.value),
"horizontalError": math.max(
gpsLatitudeError.value, gpsLongitudeError.value),
"verticalError": gpsAltitudeError.value,
"gpsHeight": gpsHeightController.text
});
@@ -790,8 +823,8 @@ class MapSurveyController extends GetxController {
'eovX': eov.value.X,
'eovY': eov.value.Y,
'poleHeight': double.tryParse(gpsHeightController.text),
'horizontalError':
max(gpsLatitudeError.value, gpsLongitudeError.value),
'horizontalError': math.max(
gpsLatitudeError.value, gpsLongitudeError.value),
'verticalError': gpsAltitudeError.value,
'description': pointDescriptionController.text,
'isDeleted': false,
@@ -932,4 +965,37 @@ class MapSurveyController extends GetxController {
final result = await SharePlus.instance.share(params);
}
void switchMode(MapSurveyMode newMode) {
mode.value = newMode;
if (newMode == MapSurveyMode.measure) {
// Kitűzési célpont törlése
targetName.value = '';
targetEovY.value = 0;
targetEovX.value = 0;
}
}
void setTarget(String name, double y, double x) {
targetName.value = name;
targetEovY.value = y;
targetEovX.value = x;
mode.value = MapSurveyMode.stakeout;
}
Future<void> savePoint(String name, String note) async {
// Mindkét módban ugyanaz a mentési logika
// await AppDatabase.instance.insertMeasuredPoint(MeasuredPoint(
// projectId: ProjectService.to.activeProjectId!,
// name: name,
// eovY: currentEovY.value,
// eovX: currentEovX.value,
// eovZ: currentEovZ.value,
// accuracy: accuracy.value,
// fixQuality: gpsQuality.value,
// note: note,
// timestamp: DateTime.now(),
// ));
// await FeedbackService.to.announcePointSaved(name);
}
}
@@ -0,0 +1,203 @@
import 'dart:io';
import 'dart:math';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map_polywidget/flutter_map_polywidget.dart';
import 'package:get/get.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:rive/rive.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';
import 'package:terepi_seged/pages/map_survey/presentations/views/settings_dialog.dart';
import 'package:terepi_seged/utils/rive_utils.dart';
import 'package:terepi_seged/widgets/coordinate_panel.dart';
import 'package:terepi_seged/widgets/save_point_fab.dart';
import 'package:terepi_seged/widgets/shared_map_widgets.dart';
import 'map_add_point_dialog.dart';
class MapSurveyView extends GetView<MapSurveyController> {
const MapSurveyView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(children: [
const SharedMapWidget(),
Positioned(
top: 8,
right: 8,
left: 8,
child: CoordinatePanel.fromController(controller),
),
Positioned(top: 8, left: 0, right: 0, child: _ModeSelector()),
Positioned(
bottom: 80,
left: 8,
right: 8,
child: Obx(
() => controller.mode.value == MapSurveyMode.stakeout
? _StakeoutPanel() // ΔY, ΔX, távolság, irányszög
: const SizedBox.shrink(),
),
),
Positioned(
bottom: 16,
right: 16,
child: SavePointFab(controller: controller),
),
]);
}
}
class _ModeSelector extends GetView<MapSurveyController> {
const _ModeSelector();
@override
Widget build(BuildContext context) {
return Obx(() => SegmentedButton<MapSurveyMode>(
segments: const [
ButtonSegment(
value: MapSurveyMode.measure,
icon: Icon(Icons.gps_fixed, size: 16),
label: Text('Bemérés'),
),
ButtonSegment(
value: MapSurveyMode.stakeout,
icon: Icon(Icons.my_location, size: 16),
label: Text('Kitűzés'),
),
],
selected: {controller.mode.value},
onSelectionChanged: (s) => controller.switchMode(s.first),
));
}
}
class _StakeoutPanel extends GetView<MapSurveyController> {
const _StakeoutPanel();
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(12),
child: Obx(() {
final onTarget = controller.isOnTarget;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// Célpont neve
Row(children: [
const Icon(Icons.flag, size: 16, color: Colors.orange),
const SizedBox(width: 6),
Text(controller.targetName.value,
style: const TextStyle(fontWeight: FontWeight.w600)),
const Spacer(),
TextButton(
onPressed: _showTargetPicker,
child: const Text('Változtat'),
),
]),
const Divider(height: 16),
// Eltérések
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_DeltaCell(
label: 'ΔY',
value: controller.deltaY,
unit: 'm',
),
_DeltaCell(
label: 'ΔX',
value: controller.deltaX,
unit: 'm',
),
_DeltaCell(
label: 'Táv',
value: controller.distanceToTarget,
unit: 'm',
alwaysPositive: true,
),
],
),
const SizedBox(height: 8),
// Státusz
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 6),
decoration: BoxDecoration(
color: onTarget
? Colors.green.withOpacity(0.12)
: Colors.orange.withOpacity(0.12),
borderRadius: BorderRadius.circular(8),
),
child: Text(
onTarget
? '✓ Célponton — pont rögzíthető'
: '${controller.distanceToTarget.toStringAsFixed(3)} m a céltól',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w500,
color: onTarget ? Colors.green : Colors.orange,
fontSize: 13,
),
),
),
],
);
}),
),
);
}
void _showTargetPicker() {
// Lista a korábban bemért vagy tervezett pontokból
//Get.bottomSheet(const _TargetPickerSheet());
}
}
class _DeltaCell extends StatelessWidget {
final String label;
final double value;
final String unit;
final bool alwaysPositive;
const _DeltaCell({
required this.label,
required this.value,
required this.unit,
this.alwaysPositive = false,
});
@override
Widget build(BuildContext context) {
final display = alwaysPositive ? value.abs() : value;
final prefix = (!alwaysPositive && value > 0) ? '+' : '';
final color = value.abs() < 0.05
? Colors.green
: value.abs() < 0.5
? Colors.orange
: Colors.red;
return Column(
children: [
Text(label, style: const TextStyle(fontSize: 11, color: Colors.grey)),
const SizedBox(height: 2),
Text(
'$prefix${display.toStringAsFixed(3)} $unit',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: color,
),
),
],
);
}
}
@@ -1,423 +0,0 @@
import 'dart:io';
import 'dart:math';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map_polywidget/flutter_map_polywidget.dart';
import 'package:get/get.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:rive/rive.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';
import 'package:terepi_seged/pages/map_survey/presentations/views/settings_dialog.dart';
import 'package:terepi_seged/utils/rive_utils.dart';
import 'map_add_point_dialog.dart';
class MapSurveyView extends GetView<MapSurveyController> {
const MapSurveyView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
late SMIBool gpsTrigger;
return Scaffold(
resizeToAvoidBottomInset: false,
extendBody: true,
appBar: AppBar(
title: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Térkép'),
Text(
"",
style: TextStyle(fontSize: 12.0),
)
],
),
actions: [
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Obx(
() => GestureDetector(
onTap: () {
if (controller.gpsIsConnected.value) {
controller.disconnectFromGps();
} else {
controller.connectToGps();
}
},
child: Icon(Icons.gps_fixed,
size: 26.0,
color: controller.gpsIsConnected.value
? Colors.green
: Colors.red),
),
),
),
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Obx(
() => GestureDetector(
onTap: () {
if (controller.ntripIsConnected.value) {
controller.disconnectFromNtripServer();
} else {
controller.connectToNtripServer();
}
},
child: Icon(
Icons.assistant,
size: 26.0,
color: controller.ntripIsConnected.value
? Colors.green
: Colors.red,
),
),
),
),
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: GestureDetector(
onTap: () {
if (controller.ntripUserName.value.isNotEmpty) {
controller.ntripUsernameController.text =
controller.ntripUserName.value;
}
if (controller.ntripPassword.value.isNotEmpty) {
controller.ntripPasswordController.text =
controller.ntripPassword.value;
}
Get.to(() => SettingsDialog(), transition: Transition.downToUp);
},
child: const Icon(
Icons.more_vert,
size: 26.0,
),
),
)
],
),
body: Column(
children: [
Obx(
() => controller.gpsIsConnected.value
? Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 170.0,
// height: 160.0,
decoration: BoxDecoration(
border: Border.all(
width: 2.0,
color: const Color.fromARGB(
130, 255, 255, 255)),
color:
const Color.fromARGB(130, 255, 255, 255)),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${controller.gpsDateTime} (UTC)",
style: const TextStyle(fontSize: 10.0),
),
const Divider(
height: 5.0,
color: Colors.black,
),
Text(
"EovX: ${controller.formatEov.format(controller.eov.value.Y)}"),
Text(
"EovY: ${controller.formatEov.format(controller.eov.value.X)}"),
Text("Alt: ${controller.gpsAltitude} (m)"),
const Divider(
height: 5.0,
color: Colors.black,
),
Text(
"Hor. error: ${max(controller.gpsLatitudeError.value, controller.gpsLongitudeError.value)} (m)",
style: const TextStyle(fontSize: 14.0),
),
Text(
"Vert. error: ${controller.gpsAltitudeError} (m)",
style: const TextStyle(fontSize: 14.0),
),
const Divider(
height: 5.0,
color: Colors.black,
),
Text(
"GPS quality -> ${controller.getGpsQualityIndicator(quality: controller.gpsQuality.value)} ",
style: const TextStyle(fontSize: 8.0),
),
controller.ntripIsConnected.value
? Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Divider(
height: 5.0,
color: Colors.black,
),
Text(
"Ntrip ${controller.ntripReceivedData} byte(s) (${controller.ntripDataPacketNumbers})",
style:
const TextStyle(fontSize: 10.0),
),
Text(
"GGA last send: ${controller.ggaSendLastTimeStr} (${controller.ggaSenDataPacketNumber})",
style:
const TextStyle(fontSize: 10.0),
),
],
)
: const SizedBox(
width: 0.0,
height: 0.0,
)
],
)),
],
),
)
: const SizedBox(),
),
Expanded(
child: Stack(
children: [
Obx(
() => controller.mapIsInitialized.value
? FlutterMap(
mapController: controller.mapController,
options: MapOptions(
initialCenter: LatLng(
controller.currentLatitude.value,
controller.currentLongitude.value),
maxZoom: 25,
initialZoom: controller.currentZoom.value,
),
children: [
TileLayer(
urlTemplate:
'http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
subdomains: const ['mt0', 'mt1', 'mt2', 'mt3'],
maxNativeZoom: 18,
// urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
// userAgentPackageName: 'hu.app_dev.terepi_seged',
),
MarkerLayer(
markers: controller.pointNotesMarker,
),
MarkerLayer(
markers: controller.currentLocationMarker),
// MarkerLayer(markers: controller.parser.markers),
MarkerLayer(
markers: controller.pointsToMeasureMarker),
// PolylineLayer(
// polylines: controller.parser.polylines),
PolyWidgetLayer(
polyWidgets: controller.pointsToMeasureLabel)
],
)
: const Center(child: CircularProgressIndicator()),
),
// Obx(
// () => controller.gpsIsConnected.value
// ? Positioned(
// left: 4.0,
// top: 4.0,
// child: Container(
// width: 170.0,
// // height: 160.0,
// decoration: BoxDecoration(
// border: Border.all(
// width: 2.0,
// color: const Color.fromARGB(
// 130, 255, 255, 255)),
// color:
// const Color.fromARGB(130, 255, 255, 255)),
// child: Column(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// "${controller.gpsDateTime} (UTC)",
// style: const TextStyle(fontSize: 10.0),
// ),
// const Divider(
// height: 5.0,
// color: Colors.black,
// ),
// Text(
// "EovX: ${controller.formatEov.format(controller.eov.value.Y)}"),
// Text(
// "EovY: ${controller.formatEov.format(controller.eov.value.X)}"),
// Text("Alt: ${controller.gpsAltitude} (m)"),
// const Divider(
// height: 5.0,
// color: Colors.black,
// ),
// Text(
// "Hor. error: ${max(controller.gpsLatitudeError.value, controller.gpsLongitudeError.value)} (m)",
// style: const TextStyle(fontSize: 14.0),
// ),
// Text(
// "Vert. error: ${controller.gpsAltitudeError} (m)",
// style: const TextStyle(fontSize: 14.0),
// ),
// const Divider(
// height: 5.0,
// color: Colors.black,
// ),
// Text(
// "GPS quality -> ${controller.getGpsQualityIndicator(quality: controller.gpsQuality.value)} ",
// style: const TextStyle(fontSize: 8.0),
// ),
// controller.ntripIsConnected.value
// ? Column(
// crossAxisAlignment:
// CrossAxisAlignment.start,
// children: [
// const Divider(
// height: 5.0,
// color: Colors.black,
// ),
// Text(
// "Ntrip ${controller.ntripReceivedData} byte(s) (${controller.ntripDataPacketNumbers})",
// style: const TextStyle(
// fontSize: 10.0),
// ),
// Text(
// "GGA last send: ${controller.ggaSendLastTimeStr} (${controller.ggaSenDataPacketNumber})",
// style: const TextStyle(
// fontSize: 10.0),
// ),
// ],
// )
// : const SizedBox(
// width: 0.0,
// height: 0.0,
// )
// ],
// )),
// )
// : const Positioned(
// child: SizedBox(
// width: 0.0,
// height: 0.0,
// )),
// )
],
),
),
],
),
// bottomNavigationBar: Container(
// padding: const EdgeInsets.all(12),
// margin: const EdgeInsets.symmetric(horizontal: 24),
// decoration: BoxDecoration(
// color: Colors.black.withOpacity(0.5),
// borderRadius: const BorderRadius.all(Radius.circular(24))),
// child: Row(
// children: [
// GestureDetector(
// onTap: () {
// gpsTrigger.change(true);
// Future.delayed(const Duration(seconds: 1), () {
// gpsTrigger.change(false);
// });
// // controller.onBottomNavigationBarTap(0);
// Get.to(() => const MapAddPointDialog(),
// fullscreenDialog: true,
// transition: Transition.downToUp,
// duration: const Duration(milliseconds: 600));
// },
// child: SizedBox(
// height: 36,
// width: 36,
// child: RiveAnimation.asset(
// "assets/RiveAssets/travel_icons_pack.riv",
// artboard: "GPS", onInit: (artboard) {
// StateMachineController controllerRive =
// RiveUtils.getRiveController(artboard,
// stateMachineName: "gps_interactivity");
// gpsTrigger = controllerRive.findSMI("active") as SMIBool;
// }),
// ),
// )
// ],
// ),
// ),
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
floatingActionButton: Wrap(
direction: Axis.horizontal,
children: [
FloatingActionButton(
onPressed: () {
controller.mapZoomOut();
},
heroTag: 'ZoomOut',
tooltip: 'Zoom out',
child: const Icon(Icons.remove_circle_outline_rounded),
),
const SizedBox(
width: 15,
),
FloatingActionButton(
onPressed: () {
controller.mapZoomIn();
},
heroTag: 'ZoomIn',
tooltip: 'Zoom in',
child: const Icon(Icons.add_circle_outline_rounded),
),
const SizedBox(width: 15.0),
FloatingActionButton(
onPressed: () {
// controller.isMapMoveToCenter();
controller.setIsMapMoveToCenter();
},
heroTag: 'Center map',
tooltip: 'Center map',
child: Obx(
() => Icon(Icons.center_focus_strong,
color: controller.isMapMoveToCenter.value
? Colors.green
: Colors.red),
),
),
const SizedBox(
width: 15.0,
),
FloatingActionButton(
onPressed: () {
// controller.addMeasuredPoint();
// controller.onBottomNavigationBarTap(0);
controller.showAddPointDialog();
},
heroTag: 'Pont bemérése',
tooltip: 'Pont bemérése',
child: const Icon(Icons.flag_sharp),
),
const SizedBox(
width: 15.0,
),
FloatingActionButton(
onPressed: () {
// controller.isMapMoveToCenter();
controller.showMeasuredPointsTableDialog();
},
heroTag: 'Database test',
tooltip: 'Pont bemérése',
child: const Icon(Icons.dataset),
),
],
),
);
}
}