diff --git a/np_gps_map/assets/2.0x/map_compass.png b/np_gps_map/assets/2.0x/map_compass.png new file mode 100644 index 00000000..64f8cef8 Binary files /dev/null and b/np_gps_map/assets/2.0x/map_compass.png differ diff --git a/np_gps_map/assets/2.0x/map_compass_dark.png b/np_gps_map/assets/2.0x/map_compass_dark.png new file mode 100644 index 00000000..40588525 Binary files /dev/null and b/np_gps_map/assets/2.0x/map_compass_dark.png differ diff --git a/np_gps_map/assets/3.0x/map_compass.png b/np_gps_map/assets/3.0x/map_compass.png new file mode 100644 index 00000000..ff804f7a Binary files /dev/null and b/np_gps_map/assets/3.0x/map_compass.png differ diff --git a/np_gps_map/assets/3.0x/map_compass_dark.png b/np_gps_map/assets/3.0x/map_compass_dark.png new file mode 100644 index 00000000..66992b8e Binary files /dev/null and b/np_gps_map/assets/3.0x/map_compass_dark.png differ diff --git a/np_gps_map/assets/map_compass.png b/np_gps_map/assets/map_compass.png new file mode 100644 index 00000000..b47c6cc7 Binary files /dev/null and b/np_gps_map/assets/map_compass.png differ diff --git a/np_gps_map/assets/map_compass_dark.png b/np_gps_map/assets/map_compass_dark.png new file mode 100644 index 00000000..cd489bac Binary files /dev/null and b/np_gps_map/assets/map_compass_dark.png differ diff --git a/np_gps_map/lib/src/interactive_map/osm.dart b/np_gps_map/lib/src/interactive_map/osm.dart index 864d4fed..1f892280 100644 --- a/np_gps_map/lib/src/interactive_map/osm.dart +++ b/np_gps_map/lib/src/interactive_map/osm.dart @@ -107,6 +107,21 @@ class _OsmInteractiveMapState extends State { source: Text("OpenStreetMap contributors"), ), ), + Align( + alignment: AlignmentDirectional.topStart, + child: Padding( + padding: EdgeInsets.fromLTRB( + 8, MediaQuery.of(context).padding.top + 8, 8, 0), + child: _CompassIcon( + mapRotationRadSubject: _mapRotationRadSubject, + onTap: () { + if (_controller.camera.rotation != 0) { + _controller.rotate(0); + } + }, + ), + ), + ), ], ); } @@ -135,6 +150,42 @@ class _OsmInteractiveMapState extends State { final _subscriptions = []; } +class _CompassIcon extends StatelessWidget { + const _CompassIcon({ + required this.mapRotationRadSubject, + this.onTap, + }); + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: mapRotationRadSubject.stream, + initialData: mapRotationRadSubject.value, + builder: (context, snapshot) => Transform.rotate( + angle: snapshot.requireData, + child: GestureDetector( + onTap: () { + onTap?.call(); + }, + child: Opacity( + opacity: .8, + child: Image( + image: Theme.of(context).brightness == Brightness.light + ? const AssetImage( + "packages/np_gps_map/assets/map_compass.png") + : const AssetImage( + "packages/np_gps_map/assets/map_compass_dark.png"), + ), + ), + ), + ), + ); + } + + final BehaviorSubject mapRotationRadSubject; + final VoidCallback? onTap; +} + class _OsmDataPoint extends Marker { _OsmDataPoint({ required this.original,