Android Open Source - hellomap3d-android Animated Raster Map Activity






From Project

Back to project page hellomap3d-android.

License

The source code is released under:

MIT License

If you think the Android project hellomap3d-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nutiteq.advancedmap3;
// w  ww  . ja v  a  2 s.  c om
import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.os.Bundle;

import com.nutiteq.advancedmap3.datasource.MyAnimatedTileDataSource;
import com.nutiteq.datasources.CompressedCacheTileDataSource;
import com.nutiteq.datasources.HTTPTileDataSource;
import com.nutiteq.datasources.TileDataSource;
import com.nutiteq.layers.RasterTileLayer;
import com.nutiteq.layers.TileLoadListener;

public class AnimatedRasterMapActivity extends VectorMapSampleBaseActivity {

    private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
    private static final int ANIMATION_FRAME_TIME_MS = 300;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // MapSampleBaseActivity creates and configures mapView  
        super.onCreate(savedInstanceState);
        
        mapView.setZoom(6, 0);
        
        // Animated raster tile datasource
        final int[] hours = new int[]{5, 7, 9, 11, 15, 19, 23, 27};
        ArrayList<TileDataSource> animatedRasterTileDataSources = new ArrayList<TileDataSource>();
        for (int hour : hours) {
            CompressedCacheTileDataSource dataSource = new CompressedCacheTileDataSource( 
                    new HTTPTileDataSource(4, 7, "http://www.openportguide.org/tiles/actual/wind_vector/" + hour + "/{zoom}/{x}/{y}.png"));
            // Reduce the size a bit (default is 6 mb)
            dataSource.setCapacity((long) (0.5f * 1024 * 1024));
            animatedRasterTileDataSources.add(dataSource);
        }
        MyAnimatedTileDataSource animatedRasterTileDataSource = new MyAnimatedTileDataSource(0, 24, animatedRasterTileDataSources);
        
        // Initialize an animated raster layer
        final RasterTileLayer animatedRasterTileLayer = new RasterTileLayer( animatedRasterTileDataSource);
        animatedRasterTileLayer.setSynchronizedRefresh(true);
        animatedRasterTileLayer.setPreloading(false);
        // Set the tile load listener, which will be used to change the animation frames
        animatedRasterTileLayer.setTileLoadListener(new TileLoadListener() {
            private boolean inProgress;
            
            public void onVisibleTilesLoaded() {
                // All visible tiles have been loaded, change the frame 
                Runnable task = new Runnable() {
                    public void run() {
                        synchronized (worker) {
                            inProgress = false;
                            animatedRasterTileLayer.setFrameNr((animatedRasterTileLayer.getFrameNr() + 1) % hours.length);
                        }
                    }
                };
                synchronized (worker) {
                    if (!inProgress) {
                        inProgress = true;
                        worker.schedule(task, ANIMATION_FRAME_TIME_MS, TimeUnit.MILLISECONDS);
                    }
                }
            }
            
            public void onPreloadingTilesLoaded() {}
        });
        // Add the previous raster layer to the map
        mapView.getLayers().add(animatedRasterTileLayer);
        
    }
}




Java Source Code List

com.nutiteq.advancedmap3.AerialMapActivity.java
com.nutiteq.advancedmap3.AnimatedRasterMapActivity.java
com.nutiteq.advancedmap3.Const.java
com.nutiteq.advancedmap3.CustomRasterDataSourceActivity.java
com.nutiteq.advancedmap3.GraphhopperRouteActivity.java
com.nutiteq.advancedmap3.LauncherList.java
com.nutiteq.advancedmap3.MapListenerActivity.java
com.nutiteq.advancedmap3.MapSampleBaseActivity.java
com.nutiteq.advancedmap3.MbtilesActivity.java
com.nutiteq.advancedmap3.OfflineVectorMapActivity.java
com.nutiteq.advancedmap3.Overlays2DActivity.java
com.nutiteq.advancedmap3.Overlays3DActivity.java
com.nutiteq.advancedmap3.PinMapActivity.java
com.nutiteq.advancedmap3.RasterOverlayActivity.java
com.nutiteq.advancedmap3.VectorMapSampleBaseActivity.java
com.nutiteq.advancedmap3.datasource.MyAnimatedTileDataSource.java
com.nutiteq.advancedmap3.datasource.MyMergedRasterTileDataSource.java
com.nutiteq.advancedmap3.listener.MyMapEventListener.java
com.nutiteq.advancedmap3.listener.RouteMapEventListener.java
com.nutiteq.filepicker.FilePickerActivity.java
com.nutiteq.filepicker.FilePickerIconAdapter.java
com.nutiteq.filepicker.FilePicker.java
com.nutiteq.hellomap3.MainActivity.java
com.nutiteq.hellomap3.util.AssetCopy.java