use Object as ID for TileData

This commit is contained in:
Hannes Janetzek 2014-03-16 15:29:55 +01:00
parent 7b9f2ac6bd
commit a475aa6c22
5 changed files with 46 additions and 10 deletions

View File

@ -17,12 +17,12 @@
package org.oscim.layers.tile;
import org.oscim.core.Tile;
import org.oscim.layers.tile.vector.VectorTileLoader;
import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook;
import org.oscim.renderer.elements.ElementLayers;
import org.oscim.renderer.elements.SymbolItem;
import org.oscim.renderer.elements.TextItem;
import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.Inlist.List;
import org.oscim.utils.quadtree.Node;
import org.oscim.utils.quadtree.QuadTree;
/**
* Extends Tile class to hold state and data for concurrent use in
@ -65,6 +65,8 @@ public class MapTile extends Tile {
}
public static abstract class TileData extends Inlist<TileData> {
Object id;
protected abstract void dispose();
}
@ -85,6 +87,13 @@ public class MapTile extends Tile {
return state;
}
/**
* List of TileData for rendering. ElementLayers is always at first
* position (for VectorTileLayer). TileLoaderHooks may add additional
* data. See e.g. {@link LabelTileLoaderHook}.
*/
public TileData data;
/**
* absolute tile coordinates: tileX,Y / Math.pow(2, zoomLevel)
*/
@ -104,8 +113,6 @@ public class MapTile extends Tile {
public final List<SymbolItem> symbols = new List<SymbolItem>();
public final List<TextItem> labels = new List<TextItem>();
public TileData data;
/**
* Tile is in view region. Set by TileRenderer.
*/
@ -122,6 +129,7 @@ public class MapTile extends Tile {
*/
int lastDraw = 0;
public final static int PROXY_CHILD1 = 1 << 0;
public final static int PROXY_CHILD2 = 1 << 1;
public final static int PROXY_CHILD3 = 1 << 2;
@ -236,10 +244,32 @@ public class MapTile extends Tile {
state = State.NONE;
}
/**
* Get the default ElementLayers which are added
* by {@link VectorTileLoader}
*/
public ElementLayers getLayers() {
if (!(data instanceof ElementLayers))
return null;
return (ElementLayers) data;
}
public TileData getData(Object id) {
for (TileData d = data; d != null; d = d.next)
if (d.id == id)
return d;
return null;
}
public void addData(Object id, TileData td) {
// keeping ElementLayers at position 0!
td.id = id;
if (data != null) {
td.next = data.next;
data.next = td;
} else {
data = td;
}
}
}

View File

@ -100,6 +100,6 @@ public class BitmapTileLayer extends TileLayer {
@Override
protected TileLoader createLoader() {
return new BitmapTileLoader(this.getManager(), mTileSource);
return new BitmapTileLoader(this, mTileSource);
}
}

View File

@ -23,8 +23,8 @@ import java.util.concurrent.CancellationException;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.Tile;
import org.oscim.layers.tile.MapTile;
import org.oscim.layers.tile.TileLayer;
import org.oscim.layers.tile.TileLoader;
import org.oscim.layers.tile.TileManager;
import org.oscim.renderer.elements.BitmapLayer;
import org.oscim.renderer.elements.ElementLayers;
import org.oscim.tiling.ITileDataSource;
@ -38,8 +38,8 @@ public class BitmapTileLoader extends TileLoader {
private final ITileDataSource mTileDataSource;
public BitmapTileLoader(TileManager tileManager, TileSource tileSource) {
super(tileManager);
public BitmapTileLoader(TileLayer tileLayer, TileSource tileSource) {
super(tileLayer.getManager());
mTileDataSource = tileSource.getDataSource();
}

View File

@ -47,6 +47,7 @@ public class TestTileLayer extends TileLayer {
}
static class TestTileLoader extends TileLoader {
public TestTileLoader(TileLayer tileLayer) {
super(tileLayer.getManager());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012, 2013 Hannes Janetzek
* Copyright 2012-2014 Hannes Janetzek
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
* (and limitations) probably wont make sense in different contexts.
*/
public class ElementLayers extends TileData {
static final Logger log = LoggerFactory.getLogger(ElementLayers.class);
public static void initRenderer(GL20 gl) {
@ -58,6 +59,10 @@ public class ElementLayers extends TileData {
/** Text- and SymbolLayer */
private RenderElement textureLayers;
/**
* FIXME this is somewhat out-of-place, as it is not
* compiled with the other layers
*/
private RenderElement extrusionLayers;
/**