Proj4 refraktorálás a CoordConverterService osztályba. MapController refraktorálás.
This commit is contained in:
parent
7ee47e65bd
commit
81f1fa5cd7
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:terepi_seged/routes/app_pages.dart';
|
||||
import 'package:terepi_seged/services/coord_converter_service.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -13,6 +14,8 @@ Future<void> main() async {
|
||||
anonKey:
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogImFub24iLAogICJpc3MiOiAic3VwYWJhc2UiLAogICJpYXQiOiAxNzQwMjY1MjAwLAogICJleHAiOiAxODk4MDMxNjAwCn0.4cMVfAnBLxne1lq0fm94rgtXLBJdRx-0f-E4Jd_jFwI');
|
||||
|
||||
await Get.putAsync(() => CoordConverterService().onInit());
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
|
||||
@ -29,9 +29,9 @@ import 'package:terepi_seged/gnss_sentences/gngst.dart';
|
||||
import 'package:terepi_seged/gnss_sentences/gnrmc.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;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:terepi_seged/pages/map/presentation/views/measured_points_table_dialog.dart';
|
||||
import 'package:terepi_seged/services/coord_converter_service.dart';
|
||||
|
||||
class MapViewController extends GetxController {
|
||||
// String gpsAddress = "E8:31:CD:14:8B:B2";
|
||||
@ -124,7 +124,6 @@ class MapViewController extends GetxController {
|
||||
late Directory? directory;
|
||||
late File dataFile;
|
||||
|
||||
late proj4.Projection eovProj, wgsProj;
|
||||
RxBool mapIsInitialized = false.obs;
|
||||
|
||||
// GeoJsonParser parser =
|
||||
@ -147,18 +146,7 @@ class MapViewController extends GetxController {
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
final bytes = (await rootBundle.load('assets/Grids/etrs2eov_notowgs.gsb'))
|
||||
.buffer
|
||||
.asUint8List();
|
||||
proj4.Projection.nadgrid('Etrs2Eov', bytes);
|
||||
// var def =
|
||||
// '+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +towgs84=52.17,-71.82,-14.9,0,0,0,0 +units=m +nadgrids=@ignorable,Etrs2Eov,null +no_defs';
|
||||
var def =
|
||||
'+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +towgs84=52.17,-71.82,-14.9,0,0,0,0 +units=m +nadgrids=Etrs2Eov +no_defs';
|
||||
|
||||
// Named Projection signature, later find it from anywhere via Projection.get('EPSG:23700')
|
||||
eovProj = proj4.Projection.add('EPSG:23700', def);
|
||||
wgsProj = proj4.Projection.WGS84;
|
||||
//Loading, Success, Error handle with 1 line of code
|
||||
nmeaDecoder
|
||||
..registerTalkerSentence("GGA", (line) => Gngga(raw: line))
|
||||
@ -500,8 +488,8 @@ class MapViewController extends GetxController {
|
||||
pointsToMeasure[pointsToMeasureSelectedValue.value].coordX;
|
||||
double coordY =
|
||||
pointsToMeasure[pointsToMeasureSelectedValue.value].coordY;
|
||||
var eovCoord = proj4.Point(x: coordX, y: coordY);
|
||||
var wgsCoord = eovProj.transform(wgsProj, eovCoord);
|
||||
var wgsCoord =
|
||||
CoordConverterService.to.eovToWgsPoint(coordX, coordY);
|
||||
distance.value = calculateDistance(
|
||||
LatLng(gpsLatitude.value, gpsLongitude.value),
|
||||
LatLng(wgsCoord.y, wgsCoord.x));
|
||||
@ -906,8 +894,8 @@ class MapViewController extends GetxController {
|
||||
pointsToMeasure
|
||||
.add(PointToMeasure(id: id, coordX: coordX, coordY: coordY));
|
||||
|
||||
var eovCoord = proj4.Point(x: coordX, y: coordY);
|
||||
var wgsCoord = eovProj.transform(wgsProj, eovCoord);
|
||||
var wgsCoord =
|
||||
CoordConverterService.to.eovToWgsPoint(coordX, coordY);
|
||||
|
||||
print("Lat -> ${wgsCoord.x}, Long -> ${wgsCoord.y}");
|
||||
|
||||
@ -980,8 +968,7 @@ class MapViewController extends GetxController {
|
||||
pointsToMeasure
|
||||
.add(PointToMeasure(id: id, coordX: coordX, coordY: coordY));
|
||||
|
||||
var eovCoord = proj4.Point(x: coordX, y: coordY);
|
||||
var wgsCoord = eovProj.transform(wgsProj, eovCoord);
|
||||
var wgsCoord = CoordConverterService.to.eovToWgsPoint(coordX, coordY);
|
||||
|
||||
print("Lat -> ${wgsCoord.x}, Long -> ${wgsCoord.y}");
|
||||
|
||||
|
||||
37
lib/services/coord_converter_service.dart
Normal file
37
lib/services/coord_converter_service.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:proj4dart/proj4dart.dart' as proj4;
|
||||
|
||||
class CoordConverterService extends GetxService {
|
||||
static CoordConverterService get to => Get.find();
|
||||
|
||||
late proj4.Projection eovProj;
|
||||
late proj4.Projection wgsProj;
|
||||
|
||||
@override
|
||||
Future<void> onInit() async {
|
||||
super.onInit();
|
||||
|
||||
final bytes = (await rootBundle.load('assets/Grids/etrs2eov_notowgs.gsb'))
|
||||
.buffer
|
||||
.asUint8List();
|
||||
|
||||
proj4.Projection.nadgrid('Etrs2Eov', bytes);
|
||||
|
||||
const def =
|
||||
'+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 '
|
||||
'+k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 '
|
||||
'+towgs84=52.17,-71.82,-14.9,0,0,0,0 '
|
||||
'+units=m +nadgrids=Etrs2Eov +no_defs';
|
||||
|
||||
eovProj = proj4.Projection.add('EPSG:23700', def);
|
||||
wgsProj = proj4.Projection.WGS84;
|
||||
}
|
||||
|
||||
// Segédmetódusok — nem kötelező, de tisztább
|
||||
proj4.Point wgsToEovPoint(double lon, double lat) =>
|
||||
wgsProj.transform(eovProj, proj4.Point(x: lon, y: lat));
|
||||
|
||||
proj4.Point eovToWgsPoint(double y, double x) =>
|
||||
eovProj.transform(wgsProj, proj4.Point(x: y, y: x));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user