rotateAroundPoint method

MoveAndRotateResult rotateAroundPoint(
  1. double degree, {
  2. CustomPoint<double>? point,
  3. Offset? offset,
  4. bool hasGesture = false,
  5. required MapEventSource source,
  6. String? id,
})

Implementation

MoveAndRotateResult rotateAroundPoint(
  double degree, {
  CustomPoint<double>? point,
  Offset? offset,
  bool hasGesture = false,
  required MapEventSource source,
  String? id,
}) {
  if (point != null && offset != null) {
    throw ArgumentError('Only one of `point` or `offset` may be non-null');
  }
  if (point == null && offset == null) {
    throw ArgumentError('One of `point` or `offset` must be non-null');
  }

  if (degree == rotation) return MoveAndRotateResult(false, false);

  if (offset == Offset.zero) {
    return MoveAndRotateResult(
      true,
      rotate(
        degree,
        hasGesture: hasGesture,
        source: source,
        id: id,
      ),
    );
  }

  final rotationDiff = degree - rotation;
  final rotationCenter = project(center, zoom) +
      (point != null
              ? (point - (nonrotatedSize / 2.0))
              : CustomPoint(offset!.dx, offset.dy))
          .rotate(rotationRad);

  return MoveAndRotateResult(
    move(
      unproject(
        rotationCenter +
            (project(center) - rotationCenter)
                .rotate(degToRadian(rotationDiff)),
      ),
      zoom,
      hasGesture: hasGesture,
      source: source,
      id: id,
    ),
    rotate(
      rotation + rotationDiff,
      hasGesture: hasGesture,
      source: source,
      id: id,
    ),
  );
}