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

Indiana Jones like path animation #162

Open
hugomrazek opened this issue Oct 24, 2023 · 2 comments
Open

Indiana Jones like path animation #162

hugomrazek opened this issue Oct 24, 2023 · 2 comments

Comments

@hugomrazek
Copy link

Dear Vasturiano,

Is there a way to animate paths Indiana Jones style? An example of what I mean can be found here.
Provided example - random paths seems to sort of do it, but when I try to recreate the effect to be slower and in an controlled way, I am not succeeding.

Thanks in advance

@vasturiano
Copy link
Owner

@hugomrazek yes I believe that should be doable with the paths layer. It should just be a matter of calibrating the pathDashInitialGap and pathDashAnimateTime to get it just right.

And if you get to do it, please send an example, I'd love to see it. 😃

@hugomrazek
Copy link
Author

I am really trying hard but I am starting to believe I am missing something 😄

What I was able to come up with is this: A rotating globe onto which a path segments are added. However, the segments of the path are popping into a view, I have trouble animating them.
pathDashInitialGap does not seem to do anything. I thought if I set pathDashInitialGap to 1 (i.e. whole line) and pathDashGap to 0 (i.e. no gap) it will get the job done. But it does not. Here is an example of what I achieved so far. I must be not seeing/not understanding correctly something. What am I missing?

import {useEffect, useRef, useState} from 'react';
import Globe, {GlobeMethods} from "react-globe.gl";

let points = [{
    lat: 35.6764,
    lng: 139.6500,
    altitude: 0.4
}, {
    lat: 50.0755,
    lng: 14.4378,
    altitude: 0.4
}, {
    lat: 59.9139,
    lng: 10.7522,
    altitude: 0.4
}]

const App = () => {
    const globeRef = useRef<GlobeMethods>();

    const [currPointIdx, setCurrPointIdx] = useState(0)
    const [pathPoints, setPathPoints] = useState<number[][][]>([[[]]])

    const handleInterval = () => {
        setCurrPointIdx((currPointIdx) => {
            if(currPointIdx === points.length - 1) return 0;
            else return currPointIdx + 1;
        })
    }

    useEffect(() => {
        const interval = setInterval(handleInterval, 2000)
        globeRef.current?.pointOfView(points[currPointIdx], 2000);
        setPathPoints( [[...points.slice(0, currPointIdx + 1).map(({ lat, lng }) => [ lat, lng, -1 ])]]);

        return () => { clearInterval(interval) }
    }, [ currPointIdx ])

    return (
        <Globe
            ref={globeRef}

            globeImageUrl="/globe.png"
            pathsData={pathPoints}
            pathColor={() => ['yellow', 'yellow']}
            pathDashLength={1}
            pathDashInitialGap={1}
            pathDashGap={0}
            pathPointAlt={0.01}
            pathStroke={5}
            pathTransitionDuration={0}
            pathDashAnimateTime={2000}
            backgroundColor={"black"}
        />
    )
};

export default App;

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