Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Could not intercept requestAnimationFrame from Google Maps #1024

Closed
wtubog opened this issue Feb 21, 2018 · 7 comments · May be fixed by #1027
Closed

Could not intercept requestAnimationFrame from Google Maps #1024

wtubog opened this issue Feb 21, 2018 · 7 comments · May be fixed by #1027

Comments

@wtubog
Copy link

wtubog commented Feb 21, 2018

Background: Google Maps triggers requestAnimationFrame when zooming in and out of the map and when panning, I want to intercept these requestAnimationFrame via Zone.js to debounce it and may be improve performance on mobile devices...

I created a simple repro code on StackBlitz (please open console to see logs)

The problem here is that I can't seem to intercept the requestAnimationFrame on the onScheduleTask method defined on the ZoneSpec of the created Zone called mapZone (but I'm seeing intercepted events such as setTimeout inside the map when it's being instantiated) ... as you can see on the repro code, I ran the initialization of Google Maps inside the created Zone

I'm newbie on Zone.js, this probably might be a simple problem, but I can't seem to find a solution... what do you think am I missing here? :)

Thanks so much in advance!

@JiaLiPassion
Copy link
Collaborator

@wtubog , requestAnimationFrame is in the zone, https://stackblitz.com/edit/typescript-jxdndx?file=index.ts, I created a demo based on your stackblitz.

@wtubog
Copy link
Author

wtubog commented Feb 21, 2018

Hi @JiaLiPassion thanks for the quick reply.

Please try to zoom in and out on map and notice that requestAnimationFrame isn't being intercepted inside the forked Zone... I knew that Google Maps is triggering requestAnimationFrame because when you go to the Performance tab of chrome devtools, you'll see the call stack, and it triggers it when you zoom in, out and pan on the map...

@JiaLiPassion
Copy link
Collaborator

@wtubog , the reason zoom not trigger reqeustAnimationFrame in mapZone, because it is in root zone, the wheel event listener was added to google map when loading https://maps.googleapis.com/maps/api/js, so it is not in mapZone.

If there are gmaps api that can add customized wheel event handler, you can add it into mapZone.

@wtubog
Copy link
Author

wtubog commented Feb 21, 2018

A map instance has a method addListener and then you specify the event name, in this case zoom_changed and then the callback function (https://stackblitz.com/edit/typescript-ugi7tp?file=index.ts).. I think that the underlying implementation of addListener uses that wheel event handler that has been registered to the root zone...

Is there a way to tap into the root zone?

@JiaLiPassion
Copy link
Collaborator

@wtubog , there is no way to change root zone, there maybe some hack to intercept the requestAnimationFrame, but your first post said you want to improve performance, let zone to intercept requestAnimationFrame or wheel may slow down performance.

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Feb 23, 2018

@wtubog , I created a sample to override root zone, you can try it for performance test.
https://github.com/JiaLiPassion/customize-root-zone
I just deleted the google map key, for test , you need to add your key in index.html

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 23, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 23, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 23, 2018
@JiaLiPassion
Copy link
Collaborator

close for now.

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

Successfully merging a pull request may close this issue.

2 participants