focusOnCoordinates method

void focusOnCoordinates(
  1. GlobeCoordinates coordinates, {
  2. required bool animate,
  3. required Duration? duration,
})

Focus on the specified coordinates on the sphere.

Implementation

void focusOnCoordinates(GlobeCoordinates coordinates,
    {required bool animate, required Duration? duration}) {
  double latRad = radians(coordinates.latitude);
  double lonRad = radians(-coordinates.longitude);
  final targetRotationZ = -lonRad;
  final targetRotationY = latRad;
  final targetRotationX = latRad;
  if (animate) {
    final initialRotationZ = rotationZ;
    final initialRotationX = rotationX;
    final initialRotationY = rotationY;

    final rZ = targetRotationZ - initialRotationZ;
    final rX = targetRotationX - initialRotationX;
    final rY = targetRotationY - initialRotationY;

    genericAnimationController = AnimationController(
      vsync: this,
      duration: duration,
    )
      ..addListener(() {
        double animationFactor = genericAnimationController?.value ?? 1;
        rotationX = initialRotationX + rX * animationFactor;
        rotationY = initialRotationY + rY * animationFactor;
        rotationZ = initialRotationZ + rZ * animationFactor;

        setState(() {});
      })
      ..forward();
  } else {
    rotationX = targetRotationX;
    rotationY = targetRotationY;
    rotationZ = targetRotationZ;
    setState(() {});
  }
}