Skip to content
Advertisement

Openlayers 4 Adding Animation Pause/Continue Functionality?

I am using open layers 4. I am moving and stoping marker animation as this example without any problem. But I want to add pause and continue functionality to marker also. I edit some variables and endeavor on the issue with these functions. When I call continueAnimation function at first, the elapsedTime parameter become negative and give exception on moveFeature function. When I secondly call the continueAnimation function. It is working as expected. It is looking like kind of javascript implementation issue.

 function pauseAnimation() {
            animating = false;
            //I hold elapsed time globally
            var index = Math.round($("[id='rightfrm:tbv1:txt1']").val() * elapsedTime / 1000);
            (geoMarker.getGeometry()).setCoordinates(line_coordinates[index].lc);
            map.un('postcompose', moveFeature);
        }

 function continueAnimation() {
    animating = true;
    now = new Date().getTime();
    now = now - 10000 + elapsedTime; // --10000-- for negativeness
    geoMarker.setStyle(null);
    map.on('postcompose', moveFeature);
    map.render();
 }

Advertisement

Answer

I found my problem. It was a logical error. Pause and Continue working now.

now = new Date().getTime() - elapsedTime;

Anyone can use these functions for Pause/Continue functionality.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement