add TileManager TILE_LOADED/REMOVED events
This commit is contained in:
parent
655136f52d
commit
db780d9939
@ -103,4 +103,8 @@ public class VectorTileLayer extends TileLayer<VectorTileLoader> {
|
||||
|
||||
resumeLoaders();
|
||||
}
|
||||
|
||||
public TileManager getManager() {
|
||||
return mTileManager;
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,19 @@
|
||||
package org.oscim.layers.tile.vector.labeling;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.event.EventDispatcher.Event;
|
||||
import org.oscim.event.EventDispatcher.Listener;
|
||||
import org.oscim.event.MotionEvent;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.tiling.TileRenderer;
|
||||
import org.oscim.tiling.TileManager;
|
||||
import org.oscim.utils.async.SimpleWorker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LabelLayer extends Layer implements Map.InputListener, Map.UpdateListener {
|
||||
public class LabelLayer extends Layer implements Map.InputListener, Map.UpdateListener,
|
||||
Listener<MapTile> {
|
||||
static final Logger log = LoggerFactory.getLogger(LabelLayer.class);
|
||||
|
||||
private final static long MAX_RELABEL_DELAY = 100;
|
||||
@ -35,6 +39,7 @@ public class LabelLayer extends Layer implements Map.InputListener, Map.UpdateLi
|
||||
|
||||
public LabelLayer(Map map, TileRenderer tileRenderer) {
|
||||
super(map);
|
||||
l.getManager().events.bind(this);
|
||||
mLabelPlacer = new LabelPlacement(map, tileRenderer);
|
||||
mWorker = new Worker(map);
|
||||
mRenderer = new TextRenderer(mWorker);
|
||||
@ -115,4 +120,13 @@ public class LabelLayer extends Layer implements Map.InputListener, Map.UpdateLi
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(Object source, Event e, MapTile tile) {
|
||||
if (e == TileManager.TILE_LOADED) {
|
||||
log.debug("tile loaded: {}", tile);
|
||||
} else if (e == TileManager.TILE_REMOVED) {
|
||||
log.debug("tile removed: {}", tile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.event.EventDispatcher;
|
||||
import org.oscim.event.EventDispatcher.Event;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
@ -39,6 +41,10 @@ import org.slf4j.LoggerFactory;
|
||||
public class TileManager {
|
||||
static final Logger log = LoggerFactory.getLogger(TileManager.class);
|
||||
|
||||
public final static Event TILE_LOADED = new Event();
|
||||
public final static Event TILE_REMOVED = new Event();
|
||||
public final EventDispatcher<TileManager, MapTile> events;
|
||||
|
||||
private int mCacheLimit;
|
||||
private int mCacheReduce;
|
||||
|
||||
@ -130,8 +136,9 @@ public class TileManager {
|
||||
|
||||
mTilesSize = 0;
|
||||
mTilesForUpload = 0;
|
||||
|
||||
mUpdateSerial = 0;
|
||||
|
||||
events = new EventDispatcher<TileManager, MapTile>(this);
|
||||
}
|
||||
|
||||
private int[] mZoomTable;
|
||||
@ -388,6 +395,9 @@ public class TileManager {
|
||||
if (t == null)
|
||||
return;
|
||||
|
||||
if (t.state != STATE_CANCEL && t.state != STATE_LOADING)
|
||||
events.tell(TILE_REMOVED, t);
|
||||
|
||||
synchronized (t) {
|
||||
// still belongs to TileLoader thread
|
||||
if (t.state != STATE_LOADING)
|
||||
@ -396,6 +406,7 @@ public class TileManager {
|
||||
t.state = STATE_CANCEL;
|
||||
mIndex.removeItem(t);
|
||||
}
|
||||
|
||||
mTilesCount--;
|
||||
}
|
||||
|
||||
@ -532,7 +543,11 @@ public class TileManager {
|
||||
* Tile ready for upload in TileRenderLayer
|
||||
* @return caller does not care
|
||||
*/
|
||||
public void jobCompleted(MapTile tile, boolean success) {
|
||||
public void jobCompleted(final MapTile tile, final boolean success) {
|
||||
mMap.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!success || tile.state == STATE_CANCEL) {
|
||||
tile.clear();
|
||||
return;
|
||||
@ -540,6 +555,8 @@ public class TileManager {
|
||||
|
||||
tile.state = STATE_NEW_DATA;
|
||||
|
||||
events.tell(TILE_LOADED, tile);
|
||||
|
||||
// is volatile
|
||||
mTilesForUpload += 1;
|
||||
|
||||
@ -548,6 +565,9 @@ public class TileManager {
|
||||
if (tile.isLocked())
|
||||
mMap.render();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private final ScanBox mScanBox = new ScanBox() {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user