Replace implementation type with our type in map

This commit is contained in:
Ming Ming 2024-10-30 22:14:52 +08:00
parent 92286372cb
commit c13e023d87
10 changed files with 41 additions and 30 deletions

View file

@ -2,7 +2,6 @@ library np_gps_map;
export 'src/gps_map.dart'; export 'src/gps_map.dart';
export 'src/interactive_map.dart'; export 'src/interactive_map.dart';
export 'src/map_coord.dart';
export 'src/place_picker.dart'; export 'src/place_picker.dart';
export 'src/type.dart'; export 'src/type.dart';
export 'src/util.dart' show initGpsMap; export 'src/util.dart' show initGpsMap;

View file

@ -1,8 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:np_gps_map/src/map_coord.dart';
import 'package:np_gps_map/src/native/google_gps_map.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'; if (dart.library.html) 'package:np_gps_map/src/web/google_gps_map.dart';
import 'package:np_gps_map/src/osm_gps_map.dart'; import 'package:np_gps_map/src/osm_gps_map.dart';
import 'package:np_gps_map/src/type.dart';
import 'package:np_gps_map/src/util.dart'; import 'package:np_gps_map/src/util.dart';
import 'package:np_platform_util/np_platform_util.dart'; import 'package:np_platform_util/np_platform_util.dart';

View file

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:np_gps_map/src/gps_map.dart'; import 'package:np_gps_map/src/gps_map.dart';
import 'package:np_gps_map/src/interactive_map/google.dart'; import 'package:np_gps_map/src/interactive_map/google.dart';
import 'package:np_gps_map/src/interactive_map/osm.dart'; import 'package:np_gps_map/src/interactive_map/osm.dart';
import 'package:np_gps_map/src/map_coord.dart';
import 'package:np_gps_map/src/type.dart'; import 'package:np_gps_map/src/type.dart';
import 'package:np_gps_map/src/util.dart'; import 'package:np_gps_map/src/util.dart';
import 'package:np_platform_util/np_platform_util.dart'; import 'package:np_platform_util/np_platform_util.dart';

View file

@ -3,10 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart'; import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:latlong2/latlong.dart' as type;
import 'package:np_common/object_util.dart'; import 'package:np_common/object_util.dart';
import 'package:np_gps_map/src/interactive_map.dart'; import 'package:np_gps_map/src/interactive_map.dart';
import 'package:np_gps_map/src/map_coord.dart';
import 'package:np_gps_map/src/type.dart' as type; import 'package:np_gps_map/src/type.dart' as type;
typedef GoogleClusterBuilder = FutureOr<BitmapDescriptor> Function( typedef GoogleClusterBuilder = FutureOr<BitmapDescriptor> Function(
@ -28,7 +26,7 @@ class GoogleInteractiveMap extends StatefulWidget {
@override @override
State<StatefulWidget> createState() => _GoogleInteractiveMapState(); State<StatefulWidget> createState() => _GoogleInteractiveMapState();
final MapCoord? initialPosition; final type.MapCoord? initialPosition;
final double? initialZoom; final double? initialZoom;
final List<DataPoint>? dataPoints; final List<DataPoint>? dataPoints;
final GoogleClusterBuilder? clusterBuilder; final GoogleClusterBuilder? clusterBuilder;
@ -64,10 +62,7 @@ class _GoogleInteractiveMapState extends State<GoogleInteractiveMap> {
onCameraMove: (position) { onCameraMove: (position) {
_clusterManager.onCameraMove(position); _clusterManager.onCameraMove(position);
widget.onCameraMove?.call(type.CameraPosition( widget.onCameraMove?.call(type.CameraPosition(
center: type.LatLng( center: position.target.toMapCoord(),
position.target.latitude,
position.target.longitude,
),
zoom: position.zoom, zoom: position.zoom,
rotation: position.bearing, rotation: position.bearing,
)); ));
@ -134,7 +129,7 @@ class _ParentController implements InteractiveMapController {
const _ParentController(this.controller); const _ParentController(this.controller);
@override @override
void setPosition(MapCoord position) { void setPosition(type.MapCoord position) {
controller controller
.animateCamera(CameraUpdate.newLatLngZoom(position.toLatLng(), 10)); .animateCamera(CameraUpdate.newLatLngZoom(position.toLatLng(), 10));
} }
@ -142,7 +137,7 @@ class _ParentController implements InteractiveMapController {
final GoogleMapController controller; final GoogleMapController controller;
} }
extension on MapCoord { extension on type.MapCoord {
LatLng toLatLng() => LatLng(latitude, longitude); LatLng toLatLng() => LatLng(latitude, longitude);
} }

View file

@ -7,7 +7,6 @@ import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:np_common/object_util.dart'; import 'package:np_common/object_util.dart';
import 'package:np_gps_map/src/interactive_map.dart'; import 'package:np_gps_map/src/interactive_map.dart';
import 'package:np_gps_map/src/map_coord.dart';
import 'package:np_gps_map/src/type.dart'; import 'package:np_gps_map/src/type.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
@ -51,7 +50,7 @@ class _OsmInteractiveMapState extends State<OsmInteractiveMap> {
_subscriptions.add(_controller.mapEventStream.listen((ev) { _subscriptions.add(_controller.mapEventStream.listen((ev) {
_mapRotationRadSubject.add(ev.camera.rotationRad); _mapRotationRadSubject.add(ev.camera.rotationRad);
widget.onCameraMove?.call(CameraPosition( widget.onCameraMove?.call(CameraPosition(
center: ev.camera.center, center: ev.camera.center.toMapCoord(),
zoom: ev.camera.zoom, zoom: ev.camera.zoom,
rotation: (360 - ev.camera.rotation) % 360, rotation: (360 - ev.camera.rotation) % 360,
)); ));

View file

@ -1,9 +0,0 @@
class MapCoord {
const MapCoord(this.latitude, this.longitude);
@override
String toString() => "MapCoord {latitude: $latitude, longitude: $longitude}";
final double latitude;
final double longitude;
}

View file

@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:np_gps_map/src/map_coord.dart'; import 'package:np_gps_map/src/type.dart' as type;
class GoogleGpsMap extends StatelessWidget { class GoogleGpsMap extends StatelessWidget {
const GoogleGpsMap({ const GoogleGpsMap({
@ -46,7 +46,7 @@ class GoogleGpsMap extends StatelessWidget {
); );
} }
final MapCoord center; final type.MapCoord center;
final double zoom; final double zoom;
final VoidCallback? onTap; final VoidCallback? onTap;
} }

View file

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:np_gps_map/src/map_coord.dart'; import 'package:np_gps_map/src/type.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
class OsmGpsMap extends StatelessWidget { class OsmGpsMap extends StatelessWidget {

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:np_gps_map/src/gps_map.dart'; import 'package:np_gps_map/src/gps_map.dart';
import 'package:np_gps_map/src/interactive_map.dart'; import 'package:np_gps_map/src/interactive_map.dart';
import 'package:np_gps_map/src/map_coord.dart';
import 'package:np_gps_map/src/type.dart'; import 'package:np_gps_map/src/type.dart';
class PlacePickerView extends StatelessWidget { class PlacePickerView extends StatelessWidget {

View file

@ -1,17 +1,46 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' as gmap;
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:np_common/type.dart'; import 'package:np_common/type.dart';
/// A pair of latitude and longitude coordinates, stored as degrees
class MapCoord {
const MapCoord(this.latitude, this.longitude);
MapCoord.fromJson(JsonObj json)
: latitude = json["lat"],
longitude = json["lng"];
@override
String toString() => "MapCoord {latitude: $latitude, longitude: $longitude}";
JsonObj toJson() => {
"lat": latitude,
"lng": longitude,
};
final double latitude;
final double longitude;
}
extension GLatLngExtension on gmap.LatLng {
MapCoord toMapCoord() => MapCoord(latitude, longitude);
}
extension LatLngExtension on LatLng {
MapCoord toMapCoord() => MapCoord(latitude, longitude);
}
class CameraPosition with EquatableMixin { class CameraPosition with EquatableMixin {
const CameraPosition({ const CameraPosition({
required this.center, required this.center,
required this.zoom, required this.zoom,
required this.rotation, this.rotation = 0,
}); });
factory CameraPosition.fromJson(JsonObj json) { factory CameraPosition.fromJson(JsonObj json) {
return CameraPosition( return CameraPosition(
center: LatLng.fromJson(json["center"]), center: MapCoord.fromJson(json["center"]),
zoom: json["zoom"], zoom: json["zoom"],
rotation: json["rotation"], rotation: json["rotation"],
); );
@ -35,7 +64,7 @@ class CameraPosition with EquatableMixin {
@override @override
List<Object?> get props => [center, zoom, rotation]; List<Object?> get props => [center, zoom, rotation];
final LatLng center; final MapCoord center;
final double zoom; final double zoom;
// The camera's bearing in degrees, measured clockwise from north. // The camera's bearing in degrees, measured clockwise from north.
// //