From 0d68fdff4a58ced64083dbddea3000d507905ef0 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 20 Jul 2024 03:28:38 +0800 Subject: [PATCH] Use actual type for map coord --- app/lib/widget/viewer_detail_pane.dart | 6 +++--- np_gps_map/lib/np_gps_map.dart | 1 + np_gps_map/lib/src/gps_map.dart | 3 ++- np_gps_map/lib/src/map_coord.dart | 9 +++++++++ np_gps_map/lib/src/native/google_gps_map.dart | 5 +++-- np_gps_map/lib/src/osm_gps_map.dart | 7 ++++--- 6 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 np_gps_map/lib/src/map_coord.dart diff --git a/app/lib/widget/viewer_detail_pane.dart b/app/lib/widget/viewer_detail_pane.dart index 0c5d4d7a..3e159988 100644 --- a/app/lib/widget/viewer_detail_pane.dart +++ b/app/lib/widget/viewer_detail_pane.dart @@ -399,7 +399,7 @@ class _ViewerDetailPaneState extends State { final lng = exif.gpsLongitudeDeg; if (lat != null && lng != null) { _log.fine("GPS: ($lat, $lng)"); - _gps = (lat: lat, lng: lng); + _gps = MapCoord(lat, lng); _location = _file!.location; } } @@ -497,7 +497,7 @@ class _ViewerDetailPaneState extends State { if (getRawPlatform() == NpPlatform.android) { final intent = AndroidIntent( action: "action_view", - data: Uri.encodeFull("geo:${_gps!.lat},${_gps!.lng}?z=16"), + data: Uri.encodeFull("geo:${_gps!.latitude},${_gps!.longitude}?z=16"), ); intent.launch(); } @@ -591,7 +591,7 @@ class _ViewerDetailPaneState extends State { String? _exposureTime; double? _focalLength; int? _isoSpeedRatings; - ({double lat, double lng})? _gps; + MapCoord? _gps; ImageLocation? _location; final _tags = []; diff --git a/np_gps_map/lib/np_gps_map.dart b/np_gps_map/lib/np_gps_map.dart index 64b96ae2..556e4d6b 100644 --- a/np_gps_map/lib/np_gps_map.dart +++ b/np_gps_map/lib/np_gps_map.dart @@ -1,3 +1,4 @@ library np_gps_map; export 'src/gps_map.dart'; +export 'src/map_coord.dart'; diff --git a/np_gps_map/lib/src/gps_map.dart b/np_gps_map/lib/src/gps_map.dart index 89612d9e..f6fff5ea 100644 --- a/np_gps_map/lib/src/gps_map.dart +++ b/np_gps_map/lib/src/gps_map.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:np_gps_map/src/map_coord.dart'; import 'package:np_gps_map/src/native.dart'; import 'package:np_gps_map/src/native/google_gps_map.dart' if (dart.library.html) 'package:np_gps_map/src/web/google_gps_map.dart'; @@ -49,7 +50,7 @@ class GpsMap extends StatelessWidget { final GpsMapProvider providerHint; /// A pair of latitude and longitude coordinates, stored as degrees - final ({double lat, double lng}) center; + final MapCoord center; final double zoom; final void Function()? onTap; diff --git a/np_gps_map/lib/src/map_coord.dart b/np_gps_map/lib/src/map_coord.dart new file mode 100644 index 00000000..ca35a1df --- /dev/null +++ b/np_gps_map/lib/src/map_coord.dart @@ -0,0 +1,9 @@ +class MapCoord { + const MapCoord(this.latitude, this.longitude); + + @override + String toString() => "MapCoord {latitude: $latitude, longitude: $longitude}"; + + final double latitude; + final double longitude; +} diff --git a/np_gps_map/lib/src/native/google_gps_map.dart b/np_gps_map/lib/src/native/google_gps_map.dart index 72ce0fd4..36b0935e 100644 --- a/np_gps_map/lib/src/native/google_gps_map.dart +++ b/np_gps_map/lib/src/native/google_gps_map.dart @@ -1,5 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'package:np_gps_map/src/map_coord.dart'; class GoogleGpsMap extends StatelessWidget { const GoogleGpsMap({ @@ -11,7 +12,7 @@ class GoogleGpsMap extends StatelessWidget { @override Widget build(BuildContext context) { - final centerLl = LatLng(center.lat, center.lng); + final centerLl = LatLng(center.latitude, center.longitude); return GoogleMap( compassEnabled: false, mapToolbarEnabled: false, @@ -40,7 +41,7 @@ class GoogleGpsMap extends StatelessWidget { ); } - final ({double lat, double lng}) center; + final MapCoord center; final double zoom; final VoidCallback? onTap; } diff --git a/np_gps_map/lib/src/osm_gps_map.dart b/np_gps_map/lib/src/osm_gps_map.dart index 00ee6832..ba56f8a5 100644 --- a/np_gps_map/lib/src/osm_gps_map.dart +++ b/np_gps_map/lib/src/osm_gps_map.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; +import 'package:np_gps_map/src/map_coord.dart'; import 'package:url_launcher/url_launcher_string.dart'; class OsmGpsMap extends StatelessWidget { @@ -14,11 +15,11 @@ class OsmGpsMap extends StatelessWidget { @override Widget build(BuildContext context) { const double pinSize = 48; - final centerLl = LatLng(center.lat, center.lng); + final centerLl = LatLng(center.latitude, center.longitude); return GestureDetector( onTap: () { launchUrlString( - "https://www.openstreetmap.org/?mlat=${center.lat}&mlon=${center.lng}#map=${zoom.toInt()}/${center.lat}/${center.lng}", + "https://www.openstreetmap.org/?mlat=${center.latitude}&mlon=${center.longitude}#map=${zoom.toInt()}/${center.latitude}/${center.longitude}", mode: LaunchMode.externalApplication, ); }, @@ -61,7 +62,7 @@ class OsmGpsMap extends StatelessWidget { ); } - final ({double lat, double lng}) center; + final MapCoord center; final double zoom; final void Function()? onTap; }