diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index 336d74a25..0b434ef67 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -92,10 +92,28 @@ class MapControllerImpl implements MapController { final mapCenter = _state.options.crs.latLngToPoint(_state.center, _state.zoom); - final point = mapCenter - localPointCenterDistance; + var point = mapCenter - localPointCenterDistance; + + if (_state.rotation != 0.0) { + point = rotatePoint(mapCenter, point); + } + return _state.options.crs.pointToLatLng(point, _state.zoom); } + CustomPoint rotatePoint( + CustomPoint mapCenter, CustomPoint point) { + final m = Matrix4.identity() + ..translate(mapCenter.x.toDouble(), mapCenter.y.toDouble()) + ..rotateZ(-_state.rotationRad) + ..translate(-mapCenter.x.toDouble(), -mapCenter.y.toDouble()); + + final tp = MatrixUtils.transformPoint( + m, Offset(point.x.toDouble(), point.y.toDouble())); + + return CustomPoint(tp.dx, tp.dy); + } + @override Stream get mapEventStream => _mapEventSink.stream; }