/*******************************************************************************
 * Copyright 2014, 2017 gwt-ol3
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
/**
 *
 */
package com.github.tdesjardins.ol3.demo.client.example;

import com.github.tdesjardins.ol3.demo.client.constants.DemoConstants;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;

import java.util.Arrays;
import java.util.List;

import ol.Collection;
import ol.Coordinate;
import ol.Map;
import ol.MapOptions;
import ol.View;
import ol.animation.AnimationOptions;
import ol.control.MousePosition;
import ol.control.MousePositionOptions;
import ol.control.ScaleLine;
import ol.layer.Base;
import ol.layer.LayerOptions;
import ol.layer.Tile;
import ol.proj.Projection;
import ol.proj.ProjectionOptions;
import ol.source.Osm;
import ol.source.XyzOptions;

/**
 * Example for animations.
 *
 * @author Tino Desjardins
 */
public class AnimationExample implements Example {

    private int currentLocationIndex = 0;

    /* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
    @Override
    public void show(String exampleId) {

        Coordinate centerCoordinate = new Coordinate(13.37, 52.52);
        Coordinate transformedMidPoint = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);

        // create an OSM-layer
        XyzOptions osmSourceOptions = new XyzOptions();
        Osm osmSource = new Osm(osmSourceOptions);
        LayerOptions osmLayerOptions = new LayerOptions();
        osmLayerOptions.setSource(osmSource);
        Tile osmLayer = new Tile(osmLayerOptions);

        // create a view
        View view = new View();

        view.setCenter(transformedMidPoint);
        view.setZoom(16);

        // create the map
        MapOptions mapOptions = new MapOptions();
        mapOptions.setLoadTilesWhileAnimating(true);
        mapOptions.setTarget(exampleId);
        mapOptions.setView(view);

        Collection<Base> lstLayer = new Collection<Base>();
        lstLayer.push(osmLayer);
        mapOptions.setLayers(lstLayer);
        Map map = new Map(mapOptions);

        // add some controls
        map.addControl(new ScaleLine());

        MousePositionOptions mousePositionOptions = new MousePositionOptions();
        ProjectionOptions projectionOptions = new ProjectionOptions();
        projectionOptions.setCode(DemoConstants.EPSG_4326);
        mousePositionOptions.setProjection(new Projection(projectionOptions));

        MousePosition mousePosition = new MousePosition(mousePositionOptions);
        mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
        map.addControl(mousePosition);

        Coordinate tvTowerCoordinate = Projection.transform(new Coordinate(13.409, 52.52), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
        Coordinate pplaceCoordinate = Projection.transform(new Coordinate(13.377, 52.509), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
        Coordinate zooCoordinate = Projection.transform(new Coordinate(13.338, 52.508), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);

        final List<Coordinate> coordinates = Arrays.asList(transformedMidPoint, tvTowerCoordinate, pplaceCoordinate, zooCoordinate);

        Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {

            @Override
            public boolean execute() {

                int index = getNextIndex(coordinates.size());

                AnimationOptions panAnimationOptions = new AnimationOptions();
                panAnimationOptions.setDuration(2000);
                // Switch this to rotate the animation while animating.
                // panAnimationOptions.setRotation(view.getRotation() + 2 * Math.PI);
                panAnimationOptions.setCenter(coordinates.get(index));

                view.animate(panAnimationOptions);

                AnimationOptions zoomOutAnimationOptions = new AnimationOptions();
                zoomOutAnimationOptions.setDuration(1000);
                zoomOutAnimationOptions.setResolution(view.getResolution() + 4);

                AnimationOptions zoomInAnimationOptions = new AnimationOptions();
                zoomInAnimationOptions.setDuration(1000);
                zoomInAnimationOptions.setResolution(view.getResolution());

                view.animate(zoomOutAnimationOptions, zoomInAnimationOptions);

                return true;

            }

        }, 6000);

    }

    private int getNextIndex(int range) {
        int index = (int)(Math.random() * range);
        if (this.currentLocationIndex == index) {
            index = this.getNextIndex(range);
        }

        this.currentLocationIndex = index;

        return index;
    }

}

@@ -96,17 +96,17 @@
 014, 201
-7
+8
  gwt-ol3
@@ -932,70 +932,8 @@
 ler;
-%0Aimport com.google.gwt.core.client.Scheduler.RepeatingCommand;
 %0A%0Aim
@@ -3871,100 +3871,17 @@
 iod(
-new RepeatingCommand() %7B%0A%0A            @Override%0A            public boolean execute() %7B%0A%0A    
+() -%3E %7B%0A%0A
     
@@ -3939,36 +3939,32 @@
 );%0A%0A            
-  
-  
 AnimationOptions
@@ -4014,36 +4014,32 @@
 ();%0A            
-    
 panAnimationOpti
@@ -4057,28 +4057,24 @@
 tion(2000);%0A
-    
             
@@ -4141,20 +4141,16 @@
         
-    
 // panAn
@@ -4215,36 +4215,32 @@
 I);%0A            
-    
 panAnimationOpti
@@ -4283,36 +4283,32 @@
 );%0A%0A            
-  
-  
 view.animate(pan
@@ -4319,36 +4319,32 @@
 ationOptions);%0A%0A
-    
             Anim
@@ -4398,36 +4398,32 @@
 ationOptions();%0A
-    
             zoom
@@ -4465,36 +4465,32 @@
 0);%0A            
-    
 zoomOutAnimation
@@ -4535,28 +4535,24 @@
 on() + 4);%0A%0A
-    
             
@@ -4621,36 +4621,32 @@
 ();%0A            
-  
-  
 zoomInAnimationO
@@ -4663,36 +4663,32 @@
 Duration(1000);%0A
-    
             zoom
@@ -4740,28 +4740,24 @@
 lution());%0A%0A
-    
             
@@ -4828,28 +4828,24 @@
             
-    
 return true;
@@ -4850,23 +4850,8 @@
 e;%0A%0A
-            %7D%0A%0A
     

Use lamdas