Skip to content

Commit

Permalink
Fix pointToLatLng with rotation
Browse files Browse the repository at this point in the history
Co-authored-by: Polo <gitpjp@pm.me> and ibrierley 
Update lib/src/map/map.dart
Update lib/src/map/map.dart
Fix trailing lines
  • Loading branch information
HugoHeneault committed May 20, 2022
1 parent 0dad777 commit 3e63a08
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/src/map/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<num> rotatePoint(
CustomPoint<num> mapCenter, CustomPoint<num> 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<MapEvent> get mapEventStream => _mapEventSink.stream;
}
Expand Down

0 comments on commit 3e63a08

Please sign in to comment.