diff --git a/np_gps_map/lib/src/interactive_map/osm.dart b/np_gps_map/lib/src/interactive_map/osm.dart index 876014c0..52d163b6 100644 --- a/np_gps_map/lib/src/interactive_map/osm.dart +++ b/np_gps_map/lib/src/interactive_map/osm.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; @@ -7,6 +8,7 @@ import 'package:latlong2/latlong.dart'; import 'package:np_common/object_util.dart'; import 'package:np_gps_map/src/interactive_map.dart'; import 'package:np_gps_map/src/map_coord.dart'; +import 'package:rxdart/rxdart.dart'; typedef OsmClusterBuilder = Widget Function( BuildContext context, List dataPoints); @@ -43,10 +45,23 @@ class _OsmInteractiveMapState extends State { if (_parentController == null) { _parentController = _ParentController(_controller); widget.onMapCreated?.call(_parentController!); + _subscriptions.add(_controller.mapEventStream.listen((ev) { + _mapRotationRadSubject.add(ev.camera.rotationRad); + })); } }); } + @override + void dispose() { + for (final s in _subscriptions) { + s.cancel(); + } + _mapRotationRadSubject.close(); + _controller.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return FlutterMap( @@ -98,13 +113,22 @@ class _OsmInteractiveMapState extends State { } else { return GestureDetector( onTap: widget.onClusterTap?.let((l) => () => l(dataPoints)), - child: widget.clusterBuilder!(context, dataPoints), + child: StreamBuilder( + stream: _mapRotationRadSubject.stream, + initialData: _mapRotationRadSubject.value, + builder: (context, snapshot) => Transform.rotate( + angle: -snapshot.requireData, + child: widget.clusterBuilder!(context, dataPoints), + ), + ), ); } } _ParentController? _parentController; late final _controller = MapController(); + final _mapRotationRadSubject = BehaviorSubject.seeded(0.0); + final _subscriptions = []; } class _OsmDataPoint extends Marker { diff --git a/np_gps_map/pubspec.yaml b/np_gps_map/pubspec.yaml index 3c7a20ee..6f96be58 100644 --- a/np_gps_map/pubspec.yaml +++ b/np_gps_map/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: path: ../np_common np_platform_util: path: ../np_platform_util + rxdart: ^0.27.7 url_launcher: ^6.1.11 dependency_overrides: