0
votes

I have created a component called compass component in my map application , when I rotate the map , I want to programmatically rotate that compass with animation also , Im using angular animation ,

import { Component, OnInit, OnDestroy, Output, Input, EventEmitter, ViewChild, AfterViewInit, ElementRef } from '@angular/core'; import { trigger, transition, state, animate, style, keyframes } from '@angular/animations'; import { UtilService } from '../utils/util.service';

@Component({
  selector: "app-compasstool",
  template: require("./compasstool.component.html"),
  styles: [require("./compasstool.component.scss")],

  animations: [
    trigger('flyInOut', [
      state('start', style({ transform: 'rotate(0rad)' })),
      state('end', style({ transform: 'rotate(0.9rad)' })),
      transition('* => start', [
        animate("5s", keyframes([
          style({ transform: 'rotate(0rad)' }),// offset = 0         
        ]))
      ]),
      transition('* => end', [
        animate("2s", keyframes([
          style({ transform: 'rotate(0rad)' }),// offset = 0
          style({ transform: 'rotate(0.2rad)' }), // offset = 0.33
          style({ transform: 'rotate(0.6rad)' }), // offset = 0.66
          style({ transform: 'rotate(0.9rad)' }) // offset = 1
        ]))
      ]),
    ]),
  ],


})

I will get map rotation in radius , when you give with component , it will only work at initial time . How i will invoke animation with rotation inside component ?

1
On the thing that should rotate, add [@flyInOut]="myVar" where myVar should have either start or end as values.user4676340
you are right , that will work , but i need to modify transform radius and generate new animation variable , start from the current rotation radian to latest rotationAhammadaliPK
I just answered your question, I don't know or care about your animation, do what suits you best !user4676340
i need to rotate the compass , whenver user rotates the map , can we programmatically change that radian value ?AhammadaliPK

1 Answers

0
votes

Since your rotation is dynamic and the animation must be based on the property of rotation i.e. radians you might want to consider using AnimationBuilder.

Try this example where I tried to rotate a .needle element https://stackblitz.com/edit/angular-animation-builder-pl9qkn

It uses AnimationBuilder to build AnimationPlayer and then it plays. In that it uses the radions to transform

  animationFactory = this.animationBuilder
    .build([
      style({ transform: `rotate(${this.lastRadians}rad)` }),
      animate(200, style({ transform: `rotate(${this.radians}rad)` }))
    ]);