use AsyncTask for labeling task
This commit is contained in:
parent
5b16f6b085
commit
29b70ecf5b
@ -28,8 +28,6 @@ package org.oscim.layers.labeling;
|
|||||||
// 5 R-Tree might be handy
|
// 5 R-Tree might be handy
|
||||||
//
|
//
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
@ -55,13 +53,8 @@ import org.oscim.utils.pool.Pool;
|
|||||||
import org.oscim.view.MapView;
|
import org.oscim.view.MapView;
|
||||||
import org.oscim.view.MapViewPosition;
|
import org.oscim.view.MapViewPosition;
|
||||||
|
|
||||||
//import android.os.AsyncTask;
|
|
||||||
//import android.os.Handler;
|
|
||||||
//import android.os.Looper;
|
|
||||||
|
|
||||||
class TextRenderLayer extends BasicRenderLayer {
|
class TextRenderLayer extends BasicRenderLayer {
|
||||||
private final static String TAG = TextRenderLayer.class.getName();
|
private final static String TAG = TextRenderLayer.class.getName();
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private final static float MIN_CAPTION_DIST = 5;
|
private final static float MIN_CAPTION_DIST = 5;
|
||||||
private final static float MIN_WAY_DIST = 3;
|
private final static float MIN_WAY_DIST = 3;
|
||||||
@ -606,11 +599,11 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
public synchronized void update(MapPosition pos, boolean changed,
|
public synchronized void update(MapPosition pos, boolean changed,
|
||||||
Matrices matrices) {
|
Matrices matrices) {
|
||||||
|
|
||||||
if (System.currentTimeMillis() - lastDraw > 1000){
|
//if (System.currentTimeMillis() - lastDraw > 1000){
|
||||||
updateLabels();
|
// updateLabels();
|
||||||
lastDraw = System.currentTimeMillis();
|
// lastDraw = System.currentTimeMillis();
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
if (mNextLayer.ready) {
|
if (mNextLayer.ready) {
|
||||||
// exchange current with next layers
|
// exchange current with next layers
|
||||||
TextureLayers tmp = mCurLayer;
|
TextureLayers tmp = mCurLayer;
|
||||||
@ -633,13 +626,14 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
this.newData = true;
|
this.newData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//if (!mHolding)
|
//if (!mHolding)
|
||||||
// postLabelTask((mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis());
|
postLabelTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private */LabelTask mLabelTask;
|
/* private */LabelTask mLabelTask;
|
||||||
/* private */long mLastRun;
|
/* private */long mLastRun;
|
||||||
|
/* private */boolean mRequestRun;
|
||||||
|
/* private */boolean mRelabel;
|
||||||
|
|
||||||
class LabelTask implements Runnable {
|
class LabelTask implements Runnable {
|
||||||
boolean isCancelled;
|
boolean isCancelled;
|
||||||
@ -650,14 +644,22 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
//Log.d(TAG, "relabel after " + (now - mLastRun));
|
||||||
|
mLastRun = now;
|
||||||
|
|
||||||
labelsChanged = updateLabels();
|
labelsChanged = updateLabels();
|
||||||
|
|
||||||
if (!isCancelled && labelsChanged)
|
if (!isCancelled && labelsChanged)
|
||||||
mMapView.render();
|
mMapView.render();
|
||||||
|
|
||||||
mLastRun = System.currentTimeMillis();
|
|
||||||
mLabelTask = null;
|
mLabelTask = null;
|
||||||
|
mRequestRun = false;
|
||||||
|
|
||||||
|
if (mRelabel) {
|
||||||
|
mRelabel = false;
|
||||||
|
postLabelTask();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,32 +670,28 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
mLabelTask = null;
|
mLabelTask = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private final Runnable mLabelUpdate = new Runnable() {
|
private final Runnable mLabelUpdate = new Runnable() {
|
||||||
// @Override
|
@Override
|
||||||
// public void run() {
|
public void run() {
|
||||||
// if (mLabelTask == null) {
|
if (mLabelTask == null) {
|
||||||
// mLabelTask = new LabelTask();
|
mLabelTask = new LabelTask();
|
||||||
// mLabelTask.execute();
|
mMapView.addTask(mLabelTask);
|
||||||
// Log.d(TAG, "relabel run");
|
}
|
||||||
// } else {
|
}
|
||||||
// postLabelTask(50);
|
};
|
||||||
// }
|
|
||||||
// }
|
/* private */void postLabelTask() {
|
||||||
// };
|
synchronized (mLabelUpdate) {
|
||||||
// private Handler mLabelHandler;
|
if (mRequestRun) {
|
||||||
//
|
mRelabel = true;
|
||||||
// /* private */void postLabelTask(long delay) {
|
} else {
|
||||||
// if (mLabelHandler == null) {
|
mRequestRun = true;
|
||||||
// mLabelHandler = new Handler(Looper.getMainLooper());
|
long delay = (mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis();
|
||||||
// }
|
//Log.d(TAG, "relabel in: " + delay);
|
||||||
//
|
mMapView.postDelayed(mLabelUpdate, Math.max(delay, 0));
|
||||||
// mLabelHandler.removeCallbacks(mLabelUpdate);
|
}
|
||||||
//
|
}
|
||||||
// if (delay > 0)
|
}
|
||||||
// mLabelHandler.postDelayed(mLabelUpdate, delay);
|
|
||||||
// else
|
|
||||||
// mLabelHandler.post(mLabelUpdate);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void render(MapPosition pos, Matrices m) {
|
public synchronized void render(MapPosition pos, Matrices m) {
|
||||||
@ -722,7 +720,7 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
l = TextureRenderer.draw(l, scale, m);
|
l = TextureRenderer.draw(l, scale, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mHolding;
|
//private boolean mHolding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param enable layer updates
|
* @param enable layer updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user