Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-maps): Support marker rotation #1820

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hashpie
Copy link

@hashpie hashpie commented Sep 29, 2023

Add marker missing property "rotation", which has been stated in issue #1428

@christocracy
Copy link

Nice

@Varo95
Copy link

Varo95 commented May 14, 2024

I try it out on my code i have bad news a good news.

The bad one is that this only works on native (Android and iOS) but not on Web.

On the other hand, the good news is that i do this to work on Web, we need @capacitor/device installed and the same image on svg format at the assets folder.

    const deviceType: string = (await Device.getInfo()).platform;
    const iconUrl: string = (deviceType === 'web') ? 'assets/sample.svg' : 'assets/sample.png';
    const rotation: number = 0; //replace the value of whatever u need to rotate
    const markerId: string = await this.map.addMarker({
      rotation,
      coordinate: {
        lat: 0,
        lng: 0
      },
      iconUrl,
      iconSize: {
        width: 50,
        height: 50
      },
      iconAnchor:{
        x: 25,
        y: 10
      }
    });
    if(deviceType === 'web'){
        let rotationAngle: number = 0; //replace with the same value of rotation 
        setInterval(function(): void {
          const elements = document.querySelectorAll(`img[src="${iconUrl}"]`);
          //This rotate all elements, but you can rotate specific element if diferent images on svg
          for(let i: number = 0; i < elements.length; i++){
            const element: HTMLElement = elements[i] as HTMLElement;
            element.style.transform = `rotate(${rotationAngle}deg)`;
          }
          //Logic if new rotation need for update
          rotationAngle += 10; //Degreess added
          rotationAngle %= 360;
      }, 1000); // Interval you want to rotate image
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants