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

Float the latitude back to equator at the same autoRotate speed #216

Open
hippocalypse opened this issue Sep 16, 2024 · 3 comments
Open

Comments

@hippocalypse
Copy link

I'd like to recommend floating the latitude back to the equator at the current autoRotate speed.

            const LATITUDE_FRAME_STEP = 0.1; //world.controls().getAutoRotateSpeed() is NaN?  
            (function backToEquator(target = 0) {
                let curLat = world.pointOfView().lat;
                let step = Math.min(LATITUDE_FRAME_STEP, Math.abs(curLat - target));
                world.pointOfView({ lat: curLat + step * (curLat > target ? -1 : 1) });
                requestAnimationFrame(() => backToEquator(target));
            })();
@vasturiano
Copy link
Owner

vasturiano commented Sep 17, 2024

@hippocalypse that works, but the raf invocation should be set under a conditional, otherwise the loop will go on forever unnecessarily and cause a memory leak. Like this:

(step === LATITUDE_FRAME_STEP) && requestAnimationFrame(() => backToEquator(target));

@hippocalypse
Copy link
Author

@vasturiano Ah! I gotcha. What event (when rotating the y axis) should I listen for to get back in the loop? onZoom doesn't seem to reduce the amount of invocations.

@vasturiano
Copy link
Owner

I think I now understand better your request, you want it to be perpetually correcting the latitude pov towards the equator, not when the user hits some kind of button or similar, is that right?
In that case, it's ok to just leave the raf loop running throughout and it corrects whenever it leaves the latitude 0.

Otherwise, you can try to do it on camera motion events, by hooking into the controls "change" event, like this:

world.controls().addEventListener('change', () => /* your code */);

But I'm not sure that'll give you exactly the granularity of events you're looking for.

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

No branches or pull requests

2 participants