rotateAroundPointRaw method

MoveAndRotateResult rotateAroundPointRaw(
  1. double degree, {
  2. required Offset? offset,
  3. required bool hasGesture,
  4. required MapEventSource source,
  5. String? id,
})

Internal endpoint to rotate around a point that is not in the center of the map.

Implementation

MoveAndRotateResult rotateAroundPointRaw(
  double degree, {
  required Offset? offset,
  required bool hasGesture,
  required MapEventSource source,
  String? id,
}) {
  if (degree == camera.rotation) {
    return const (moveSuccess: false, rotateSuccess: false);
  }

  if (offset == Offset.zero) {
    return (
      moveSuccess: true,
      rotateSuccess: rotateRaw(
        degree,
        hasGesture: hasGesture,
        source: source,
        id: id,
      ),
    );
  }

  final rotationDiff = degree - camera.rotation;
  final rotationCenter = camera.projectAtZoom(camera.center) +
      offset!.rotate(camera.rotationRad);

  return (
    moveSuccess: moveRaw(
      camera.unprojectAtZoom(
        rotationCenter +
            (camera.projectAtZoom(camera.center) - rotationCenter)
                .rotate(degrees2Radians * rotationDiff),
      ),
      camera.zoom,
      hasGesture: hasGesture,
      source: source,
      id: id,
    ),
    rotateSuccess: rotateRaw(
      camera.rotation + rotationDiff,
      hasGesture: hasGesture,
      source: source,
      id: id,
    ),
  );
}