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();
|
resumeLoaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileManager getManager() {
|
||||||
|
return mTileManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,19 @@
|
|||||||
package org.oscim.layers.tile.vector.labeling;
|
package org.oscim.layers.tile.vector.labeling;
|
||||||
|
|
||||||
import org.oscim.core.MapPosition;
|
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.event.MotionEvent;
|
||||||
import org.oscim.layers.Layer;
|
import org.oscim.layers.Layer;
|
||||||
import org.oscim.map.Map;
|
import org.oscim.map.Map;
|
||||||
import org.oscim.tiling.TileRenderer;
|
import org.oscim.tiling.TileRenderer;
|
||||||
|
import org.oscim.tiling.TileManager;
|
||||||
import org.oscim.utils.async.SimpleWorker;
|
import org.oscim.utils.async.SimpleWorker;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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);
|
static final Logger log = LoggerFactory.getLogger(LabelLayer.class);
|
||||||
|
|
||||||
private final static long MAX_RELABEL_DELAY = 100;
|
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) {
|
public LabelLayer(Map map, TileRenderer tileRenderer) {
|
||||||
super(map);
|
super(map);
|
||||||
|
l.getManager().events.bind(this);
|
||||||
mLabelPlacer = new LabelPlacement(map, tileRenderer);
|
mLabelPlacer = new LabelPlacement(map, tileRenderer);
|
||||||
mWorker = new Worker(map);
|
mWorker = new Worker(map);
|
||||||
mRenderer = new TextRenderer(mWorker);
|
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.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
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.Map;
|
||||||
import org.oscim.map.Viewport;
|
import org.oscim.map.Viewport;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
@ -39,6 +41,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class TileManager {
|
public class TileManager {
|
||||||
static final Logger log = LoggerFactory.getLogger(TileManager.class);
|
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 mCacheLimit;
|
||||||
private int mCacheReduce;
|
private int mCacheReduce;
|
||||||
|
|
||||||
@ -130,8 +136,9 @@ public class TileManager {
|
|||||||
|
|
||||||
mTilesSize = 0;
|
mTilesSize = 0;
|
||||||
mTilesForUpload = 0;
|
mTilesForUpload = 0;
|
||||||
|
|
||||||
mUpdateSerial = 0;
|
mUpdateSerial = 0;
|
||||||
|
|
||||||
|
events = new EventDispatcher<TileManager, MapTile>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] mZoomTable;
|
private int[] mZoomTable;
|
||||||
@ -388,6 +395,9 @@ public class TileManager {
|
|||||||
if (t == null)
|
if (t == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (t.state != STATE_CANCEL && t.state != STATE_LOADING)
|
||||||
|
events.tell(TILE_REMOVED, t);
|
||||||
|
|
||||||
synchronized (t) {
|
synchronized (t) {
|
||||||
// still belongs to TileLoader thread
|
// still belongs to TileLoader thread
|
||||||
if (t.state != STATE_LOADING)
|
if (t.state != STATE_LOADING)
|
||||||
@ -396,6 +406,7 @@ public class TileManager {
|
|||||||
t.state = STATE_CANCEL;
|
t.state = STATE_CANCEL;
|
||||||
mIndex.removeItem(t);
|
mIndex.removeItem(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
mTilesCount--;
|
mTilesCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,21 +543,30 @@ public class TileManager {
|
|||||||
* Tile ready for upload in TileRenderLayer
|
* Tile ready for upload in TileRenderLayer
|
||||||
* @return caller does not care
|
* @return caller does not care
|
||||||
*/
|
*/
|
||||||
public void jobCompleted(MapTile tile, boolean success) {
|
public void jobCompleted(final MapTile tile, final boolean success) {
|
||||||
if (!success || tile.state == STATE_CANCEL) {
|
mMap.post(new Runnable() {
|
||||||
tile.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tile.state = STATE_NEW_DATA;
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!success || tile.state == STATE_CANCEL) {
|
||||||
|
tile.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// is volatile
|
tile.state = STATE_NEW_DATA;
|
||||||
mTilesForUpload += 1;
|
|
||||||
|
events.tell(TILE_LOADED, tile);
|
||||||
|
|
||||||
|
// is volatile
|
||||||
|
mTilesForUpload += 1;
|
||||||
|
|
||||||
|
// locked means the tile is visible or referenced by
|
||||||
|
// a tile that might be visible.
|
||||||
|
if (tile.isLocked())
|
||||||
|
mMap.render();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// locked means the tile is visible or referenced by
|
|
||||||
// a tile that might be visible.
|
|
||||||
if (tile.isLocked())
|
|
||||||
mMap.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ScanBox mScanBox = new ScanBox() {
|
private final ScanBox mScanBox = new ScanBox() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user