TileManager, pass params for min/max zoom-level and cache size in constructor

This commit is contained in:
Hannes Janetzek 2013-07-23 21:36:43 +02:00
parent 419c83e88d
commit e29c36d6e7
4 changed files with 17 additions and 18 deletions

View File

@ -16,7 +16,6 @@ package org.oscim.layers.tile.bitmap;
import java.net.URL; import java.net.URL;
import org.oscim.backend.Log;
import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.gdx.client.GwtBitmap; import org.oscim.gdx.client.GwtBitmap;
@ -36,13 +35,11 @@ import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.RootPanel;
public class BitmapTileLayer extends TileLayer<TileLoader> { public class BitmapTileLayer extends TileLayer<TileLoader> {
private static final int TIMEOUT_CONNECT = 5000;
private static final int TIMEOUT_READ = 10000;
final TileSource mTileSource; final TileSource mTileSource;
public BitmapTileLayer(MapView mapView, TileSource tileSource) { public BitmapTileLayer(MapView mapView, TileSource tileSource) {
super(mapView, tileSource.getZoomLevelMax()); super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100);
mTileSource = tileSource; mTileSource = tileSource;
} }
@ -57,7 +54,6 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
img.addLoadHandler(new LoadHandler() { img.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) { public void onLoad(LoadEvent event) {
Log.d("sup", "got image " + url);
Bitmap bitmap = new GwtBitmap(img); Bitmap bitmap = new GwtBitmap(img);
tile.layers = new Layers(); tile.layers = new Layers();
@ -83,7 +79,6 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
URL url; URL url;
try { try {
url = mTileSource.getTileUrl(tile); url = mTileSource.getTileUrl(tile);
Log.d("sup", "load image " + url);
loadImage(tile, url.toString()); loadImage(tile, url.toString());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -23,6 +23,8 @@ import org.oscim.view.MapView;
public abstract class TileLayer<T extends TileLoader> extends Layer { public abstract class TileLayer<T extends TileLoader> extends Layer {
//private final static String TAG = TileLayer.class.getName(); //private final static String TAG = TileLayer.class.getName();
private final static int MAX_ZOOMLEVEL = 17; private final static int MAX_ZOOMLEVEL = 17;
private final static int MIN_ZOOMLEVEL = 2;
private final static int CACHE_LIMIT = 250;
protected final TileManager mTileManager; protected final TileManager mTileManager;
protected final TileRenderLayer mRenderLayer; protected final TileRenderLayer mRenderLayer;
@ -33,15 +35,15 @@ public abstract class TileLayer<T extends TileLoader> extends Layer {
protected boolean mInitial = true; protected boolean mInitial = true;
public TileLayer(MapView mapView) { public TileLayer(MapView mapView) {
this(mapView, MAX_ZOOMLEVEL); this(mapView, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT);
} }
public TileLayer(MapView mapView, int maxZoom) { public TileLayer(MapView mapView, int minZoom, int maxZoom, int cacheLimit) {
super(mapView); super(mapView);
// TileManager responsible for adding visible tiles // TileManager responsible for adding visible tiles
// to load queue and managing in-memory tile cache. // to load queue and managing in-memory tile cache.
mTileManager = new TileManager(mapView, this, maxZoom); mTileManager = new TileManager(mapView, this, minZoom, maxZoom, cacheLimit);
// Instantiate TileLoader threads // Instantiate TileLoader threads
mTileLoader = new ArrayList<T>(); mTileLoader = new ArrayList<T>();

View File

@ -38,12 +38,11 @@ import org.oscim.view.MapViewPosition;
* 'renderer' -> tilemap? - make it general for reuse in tile-overlays * 'renderer' -> tilemap? - make it general for reuse in tile-overlays
*/ */
public class TileManager { public class TileManager {
private static final int CACHE_TILES_MAX = 250;
static final String TAG = TileManager.class.getName(); static final String TAG = TileManager.class.getName();
private final static int MIN_ZOOMLEVEL = 2;
private final int mMaxZoom; private int mCacheLimit;
private int mMinZoom;
private int mMaxZoom;
// limit number tiles with new data not uploaded to GL // limit number tiles with new data not uploaded to GL
// TODO this should depend on the number of tiles displayed // TODO this should depend on the number of tiles displayed
@ -113,15 +112,18 @@ public class TileManager {
private final float[] mMapPlane = new float[8]; private final float[] mMapPlane = new float[8];
private final TileLayer<?> mTileLayer; private final TileLayer<?> mTileLayer;
public TileManager(MapView mapView, TileLayer<?> tileLayer, int maxZoom) { public TileManager(MapView mapView, TileLayer<?> tileLayer, int minZoom, int maxZoom, int cacheLimit) {
mMapView = mapView; mMapView = mapView;
mTileLayer = tileLayer; mTileLayer = tileLayer;
mMaxZoom = maxZoom; mMaxZoom = maxZoom;
mMinZoom = minZoom;
mCacheLimit = cacheLimit;
mMapViewPosition = mapView.getMapViewPosition(); mMapViewPosition = mapView.getMapViewPosition();
jobQueue = new JobQueue(); jobQueue = new JobQueue();
mJobs = new ArrayList<MapTile>(); mJobs = new ArrayList<MapTile>();
mTiles = new MapTile[CACHE_TILES_MAX]; mTiles = new MapTile[mCacheLimit];
mTilesSize = 0; mTilesSize = 0;
mTilesForUpload = 0; mTilesForUpload = 0;
@ -196,7 +198,7 @@ public class TileManager {
// load some tiles more than currently visible (* 0.75) // load some tiles more than currently visible (* 0.75)
double scale = pos.scale * 0.9f; double scale = pos.scale * 0.9f;
int tileZoom = FastMath.clamp(pos.zoomLevel, MIN_ZOOMLEVEL, mMaxZoom); int tileZoom = FastMath.clamp(pos.zoomLevel, mMinZoom, mMaxZoom);
if (mZoomTable != null) { if (mZoomTable != null) {
int match = 0; int match = 0;
@ -276,7 +278,7 @@ public class TileManager {
mJobs.clear(); mJobs.clear();
/* limit cache items */ /* limit cache items */
int remove = mTilesCount - CACHE_TILES_MAX; int remove = mTilesCount - mCacheLimit;
if (remove > CACHE_THRESHOLD || if (remove > CACHE_THRESHOLD ||
mTilesForUpload > MAX_TILES_IN_QUEUE) mTilesForUpload > MAX_TILES_IN_QUEUE)

View File

@ -39,7 +39,7 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
final TileSource mTileSource; final TileSource mTileSource;
public BitmapTileLayer(MapView mapView, TileSource tileSource) { public BitmapTileLayer(MapView mapView, TileSource tileSource) {
super(mapView, tileSource.getZoomLevelMax()); super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100);
mTileSource = tileSource; mTileSource = tileSource;
} }