use AsyncTask for labeling
This commit is contained in:
parent
a873310df2
commit
a8e27574c9
@ -34,8 +34,6 @@ import org.oscim.graphics.Color;
|
|||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
import org.oscim.layers.tile.TileRenderLayer;
|
import org.oscim.layers.tile.TileRenderLayer;
|
||||||
import org.oscim.layers.tile.TileSet;
|
import org.oscim.layers.tile.TileSet;
|
||||||
import org.oscim.renderer.BufferObject;
|
|
||||||
import org.oscim.renderer.GLRenderer;
|
|
||||||
import org.oscim.renderer.GLRenderer.Matrices;
|
import org.oscim.renderer.GLRenderer.Matrices;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
import org.oscim.renderer.sublayers.Layer;
|
import org.oscim.renderer.sublayers.Layer;
|
||||||
@ -49,13 +47,13 @@ import org.oscim.renderer.sublayers.TextureRenderer;
|
|||||||
import org.oscim.theme.renderinstruction.Line;
|
import org.oscim.theme.renderinstruction.Line;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.OBB2D;
|
import org.oscim.utils.OBB2D;
|
||||||
import org.oscim.utils.PausableThread;
|
|
||||||
import org.oscim.utils.pool.LList;
|
import org.oscim.utils.pool.LList;
|
||||||
import org.oscim.utils.pool.Pool;
|
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.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -66,7 +64,7 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
|
|
||||||
private final MapViewPosition mMapViewPosition;
|
private final MapViewPosition mMapViewPosition;
|
||||||
private final TileSet mTileSet;
|
private final TileSet mTileSet;
|
||||||
private final LabelThread mThread;
|
//private final LabelThread mThread;
|
||||||
|
|
||||||
private MapPosition mTmpPos;
|
private MapPosition mTmpPos;
|
||||||
|
|
||||||
@ -107,7 +105,7 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
// list of current labels
|
// list of current labels
|
||||||
private Label mLabels;
|
private Label mLabels;
|
||||||
|
|
||||||
private final float[] mTmpCoords = new float[8];
|
//private final float[] mTmpCoords = new float[8];
|
||||||
|
|
||||||
//private final HashMap<MapTile, LabelTile> mActiveTiles;
|
//private final HashMap<MapTile, LabelTile> mActiveTiles;
|
||||||
|
|
||||||
@ -166,40 +164,49 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
|
|
||||||
/* package */boolean mRun;
|
/* package */boolean mRun;
|
||||||
|
|
||||||
class LabelThread extends PausableThread {
|
class LabelTask extends AsyncTask<Void, Void, Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWork() {
|
protected Integer doInBackground(Void... params) {
|
||||||
SystemClock.sleep(250);
|
SystemClock.sleep(100);
|
||||||
|
if (!isCancelled() && updateLabels())
|
||||||
|
return null;
|
||||||
|
|
||||||
if (!mRun)
|
return Integer.valueOf(1);
|
||||||
return;
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
@Override
|
||||||
|
protected void onPostExecute(Integer result) {
|
||||||
if (updateLabels()) {
|
if (result == null)
|
||||||
mRun = false;
|
|
||||||
mMapView.render();
|
mMapView.render();
|
||||||
} else {
|
|
||||||
mRun = true;
|
if (mRun) {
|
||||||
}
|
mRun = false;
|
||||||
|
mLabelTask = new LabelTask();
|
||||||
|
mLabelTask.execute((Void) null);
|
||||||
|
} else{
|
||||||
|
mLabelTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getThreadName() {
|
protected void onCancelled() {
|
||||||
return "Labeling";
|
cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void cleanup() {
|
||||||
protected boolean hasWork() {
|
mPool.releaseAll(mPrevLabels);
|
||||||
return mRun;
|
mPrevLabels = null;
|
||||||
}
|
mTileSet.clear();
|
||||||
|
mLabelTask = null;
|
||||||
|
mRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float mSquareRadius;
|
private float mSquareRadius;
|
||||||
private int mRelabelCnt;
|
private int mRelabelCnt;
|
||||||
private final TileRenderLayer mTileLayer;
|
private final TileRenderLayer mTileLayer;
|
||||||
|
/* private */AsyncTask<Void, Void, Integer> mLabelTask;
|
||||||
|
|
||||||
public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) {
|
public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) {
|
||||||
super(mapView);
|
super(mapView);
|
||||||
@ -212,9 +219,6 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
|
|
||||||
//mActiveTiles = new HashMap<MapTile, LabelTile>();
|
//mActiveTiles = new HashMap<MapTile, LabelTile>();
|
||||||
mTmpPos = new MapPosition();
|
mTmpPos = new MapPosition();
|
||||||
mThread = new LabelThread();
|
|
||||||
mThread.start();
|
|
||||||
|
|
||||||
mRelabelCnt = 0;
|
mRelabelCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,28 +353,35 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean updateLabels() {
|
boolean updateLabels() {
|
||||||
// could this happen?
|
// nextLayer is not loaded yet
|
||||||
if (mTmpLayer == null)
|
if (mTmpLayer == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// get current tiles
|
// get current tiles
|
||||||
mTileLayer.getVisibleTiles(mTileSet);
|
boolean changedTiles = mTileLayer.getVisibleTiles(mTileSet);
|
||||||
|
boolean changedPos;
|
||||||
|
|
||||||
if (mTileSet.cnt == 0)
|
if (mTileSet.cnt == 0){
|
||||||
|
//Log.d(TAG, "no tiles "+ mTileSet.getSerial());
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
//float[] coords = mTmpCoords;
|
||||||
|
MapPosition pos = mTmpPos;
|
||||||
|
|
||||||
|
synchronized (mMapViewPosition) {
|
||||||
|
changedPos = mMapViewPosition.getMapPosition(pos);
|
||||||
|
//mMapViewPosition.getMapViewProjection(coords);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!changedTiles && !changedPos){
|
||||||
|
Log.d(TAG, "not changed " + changedTiles + " " + changedPos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Layers dbg = null;
|
Layers dbg = null;
|
||||||
if (mMapView.getDebugSettings().debugLabels)
|
if (mMapView.getDebugSettings().debugLabels)
|
||||||
dbg = new Layers();
|
dbg = new Layers();
|
||||||
|
|
||||||
float[] coords = mTmpCoords;
|
|
||||||
MapPosition pos = mTmpPos;
|
|
||||||
|
|
||||||
synchronized (mMapViewPosition) {
|
|
||||||
mMapViewPosition.getMapPosition(pos);
|
|
||||||
mMapViewPosition.getMapViewProjection(coords);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mw = (mMapView.getWidth() + Tile.SIZE) / 2;
|
int mw = (mMapView.getWidth() + Tile.SIZE) / 2;
|
||||||
int mh = (mMapView.getHeight() + Tile.SIZE) / 2;
|
int mh = (mMapView.getHeight() + Tile.SIZE) / 2;
|
||||||
mSquareRadius = mw * mw + mh * mh;
|
mSquareRadius = mw * mw + mh * mh;
|
||||||
@ -699,38 +710,21 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
mTmpPos = tmp;
|
mTmpPos = tmp;
|
||||||
|
|
||||||
this.newData = true;
|
this.newData = true;
|
||||||
|
|
||||||
if (!changed)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHolding)
|
if (!mHolding)
|
||||||
|
runLabelTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runLabelTask() {
|
||||||
|
if (mRun)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!mRun) {
|
if (mLabelTask == null) {
|
||||||
|
mLabelTask = new LabelTask();
|
||||||
|
mLabelTask.execute((Void) null);
|
||||||
|
} else {
|
||||||
mRun = true;
|
mRun = true;
|
||||||
synchronized (mThread) {
|
|
||||||
mThread.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void compile() {
|
|
||||||
int newSize = layers.getSize();
|
|
||||||
|
|
||||||
if (newSize == 0) {
|
|
||||||
isReady = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layers.vbo == null) {
|
|
||||||
layers.vbo = BufferObject.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newSize > 0) {
|
|
||||||
if (GLRenderer.uploadLayers(layers, newSize, true))
|
|
||||||
isReady = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,24 +762,17 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
*/
|
*/
|
||||||
public synchronized void hold(boolean enable) {
|
public synchronized void hold(boolean enable) {
|
||||||
// mHolding = enable;
|
// mHolding = enable;
|
||||||
// if (!enable && !mRun) {
|
// if (!enable)
|
||||||
// mRun = true;
|
// runLabelTask();
|
||||||
// synchronized (mThread) {
|
|
||||||
// mThread.notify();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// mRun = false;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearLabels() {
|
public void clearLabels() {
|
||||||
Log.d(TAG, "clearLabels");
|
Log.d(TAG, "clearLabels");
|
||||||
synchronized (mThread) {
|
if (mLabelTask != null) {
|
||||||
mRun = false;
|
// FIXME not sure, true?
|
||||||
mPool.releaseAll(mPrevLabels);
|
mLabelTask.cancel(false);
|
||||||
mPrevLabels = null;
|
} else {
|
||||||
mTileSet.clear();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user