rotatePoint method

Offset rotatePoint(
  1. Offset mapCenter,
  2. Offset point, {
  3. bool counterRotation = true,
})

Sometimes we need to make allowances that a rotation already exists, so it needs to be reversed (pointToLatLng), and sometimes we want to use the same rotation to create a new position (latLngToScreenpoint). counterRotation just makes allowances this for this.

Implementation

Offset rotatePoint(
  Offset mapCenter,
  Offset point, {
  bool counterRotation = true,
}) {
  //TODO what is the difference between this and the extension method on Offset.rotate?????!?!?!
  final counterRotationFactor = counterRotation ? -1 : 1;

  final m = Matrix4.identity()
    ..translate(mapCenter.dx, mapCenter.dy)
    ..rotateZ(rotationRad * counterRotationFactor)
    ..translate(-mapCenter.dx, -mapCenter.dy);

  return MatrixUtils.transformPoint(m, point);
}