rotateAroundPoint method
MoveAndRotateResult
rotateAroundPoint(
- double degree, {
- CustomPoint<
double> ? point, - Offset? offset,
- bool hasGesture = false,
- required MapEventSource source,
- 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,
),
);
}