diff --git a/vtm/src/org/oscim/layers/tile/MapTile.java b/vtm/src/org/oscim/layers/tile/MapTile.java index 46167fde..8a213eec 100644 --- a/vtm/src/org/oscim/layers/tile/MapTile.java +++ b/vtm/src/org/oscim/layers/tile/MapTile.java @@ -105,14 +105,6 @@ public class MapTile extends Tile { */ public float distance; - /** - * FIXME move to VectorMapTile - * Tile data set by TileLoader. - */ - - public final List symbols = new List(); - public final List labels = new List(); - /** * Tile is in view region. Set by TileRenderer. */ @@ -242,9 +234,6 @@ public class MapTile extends Tile { data = data.next; } - TextItem.pool.releaseAll(labels.clear()); - SymbolItem.pool.releaseAll(symbols.clear()); - // still needed? state = State.NONE; } diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelLayer.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelLayer.java index bbb36c1d..e5affebc 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelLayer.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelLayer.java @@ -31,6 +31,8 @@ public class LabelLayer extends Layer implements Map.UpdateListener, TileManager static final Logger log = LoggerFactory.getLogger(LabelLayer.class); + public final static String LABEL_DATA = LabelLayer.class.getName(); + private final static long MAX_RELABEL_DELAY = 100; private final LabelPlacement mLabelPlacer; diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java index 9e64df44..9bcc3e3e 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java @@ -18,6 +18,10 @@ import org.oscim.utils.geom.OBB2D; public class LabelPlacement { static final boolean dbg = false; + public final static LabelTileData getLabels(MapTile tile) { + return (LabelTileData) tile.getData(LabelLayer.LABEL_DATA); + } + private final static float MIN_CAPTION_DIST = 5; private final static float MIN_WAY_DIST = 3; @@ -176,7 +180,11 @@ public class LabelPlacement { private Label addWayLabels(MapTile t, Label l, float dx, float dy, double scale) { - for (TextItem ti : t.labels) { + LabelTileData ld = getLabels(t); + if (ld == null) + return l; + + for (TextItem ti : ld.labels) { if (ti.text.caption) continue; @@ -229,7 +237,11 @@ public class LabelPlacement { private Label addNodeLabels(MapTile t, Label l, float dx, float dy, double scale, float cos, float sin) { - O: for (TextItem ti : t.labels) { + LabelTileData ld = getLabels(t); + if (ld == null) + return l; + + O: for (TextItem ti : ld.labels) { if (!ti.text.caption) continue; @@ -447,7 +459,11 @@ public class LabelPlacement { float dy = (float) (t.tileY * Tile.SIZE - tileY); dx = flipLongitude(dx, maxx); - for (SymbolItem ti : t.symbols) { + LabelTileData ld = getLabels(t); + if (ld == null) + continue; + + for (SymbolItem ti : ld.symbols) { if (ti.texRegion == null) continue; diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileData.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileData.java new file mode 100644 index 00000000..6d8fd1bb --- /dev/null +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileData.java @@ -0,0 +1,16 @@ +package org.oscim.layers.tile.vector.labeling; + +import org.oscim.layers.tile.MapTile.TileData; +import org.oscim.renderer.elements.SymbolItem; +import org.oscim.renderer.elements.TextItem; + +public class LabelTileData extends TileData { + public final List symbols = new List(); + public final List labels = new List(); + + @Override + protected void dispose() { + TextItem.pool.releaseAll(labels.clear()); + SymbolItem.pool.releaseAll(symbols.clear()); + } +} diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java index bf087353..b7304b49 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelTileLoaderHook.java @@ -3,27 +3,41 @@ package org.oscim.layers.tile.vector.labeling; import static org.oscim.core.GeometryBuffer.GeometryType.LINE; import static org.oscim.core.GeometryBuffer.GeometryType.POINT; import static org.oscim.core.GeometryBuffer.GeometryType.POLY; +import static org.oscim.layers.tile.vector.labeling.LabelLayer.LABEL_DATA; import org.oscim.core.MapElement; import org.oscim.core.PointF; import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.vector.VectorTileLayer.TileLoaderHook; -import org.oscim.layers.tile.vector.WayDecorator; import org.oscim.renderer.elements.ElementLayers; import org.oscim.renderer.elements.SymbolItem; import org.oscim.renderer.elements.TextItem; import org.oscim.theme.styles.RenderStyle; -import org.oscim.theme.styles.Symbol; -import org.oscim.theme.styles.Text; +import org.oscim.theme.styles.SymbolStyle; +import org.oscim.theme.styles.TextStyle; public class LabelTileLoaderHook implements TileLoaderHook { + //public final static LabelTileData EMPTY = new LabelTileData(); + + private LabelTileData get(MapTile tile) { + // FIXME could be 'this'.. + LabelTileData ld = (LabelTileData) tile.getData(LABEL_DATA); + if (ld == null) { + ld = new LabelTileData(); + tile.addData(LABEL_DATA, ld); + } + return ld; + } + @Override public void render(MapTile tile, ElementLayers layers, MapElement element, RenderStyle style, int level) { - if (style instanceof Text) { - Text text = (Text) style; + if (style instanceof TextStyle) { + LabelTileData ld = get(tile); + + TextStyle text = (TextStyle) style; if (element.type == LINE) { String value = element.tags.getValue(text.textKey); if (value == null || value.length() == 0) @@ -36,7 +50,7 @@ public class LabelTileLoaderHook implements TileLoaderHook { break; WayDecorator.renderText(null, element.points, value, text, - offset, length, tile); + offset, length, ld); offset += length; } } @@ -57,7 +71,7 @@ public class LabelTileLoaderHook implements TileLoaderHook { x /= (n / 2); y /= (n / 2); - tile.labels.push(TextItem.pool.get().set(x, y, value, text)); + ld.labels.push(TextItem.pool.get().set(x, y, value, text)); } else if (element.type == POINT) { String value = element.tags.getValue(text.textKey); @@ -66,22 +80,24 @@ public class LabelTileLoaderHook implements TileLoaderHook { for (int i = 0, n = element.getNumPoints(); i < n; i++) { PointF p = element.getPoint(i); - tile.labels.push(TextItem.pool.get().set(p.x, p.y, value, text)); + ld.labels.push(TextItem.pool.get().set(p.x, p.y, value, text)); } } } - else if ((element.type == POINT) && (style instanceof Symbol)) { - Symbol symbol = (Symbol) style; + else if ((element.type == POINT) && (style instanceof SymbolStyle)) { + SymbolStyle symbol = (SymbolStyle) style; if (symbol.texture == null) return; + LabelTileData ld = get(tile); + for (int i = 0, n = element.getNumPoints(); i < n; i++) { PointF p = element.getPoint(i); SymbolItem it = SymbolItem.pool.get(); it.set(p.x, p.y, symbol.texture, true); - tile.symbols.push(it); + ld.symbols.push(it); } } } diff --git a/vtm/src/org/oscim/layers/tile/vector/WayDecorator.java b/vtm/src/org/oscim/layers/tile/vector/labeling/WayDecorator.java similarity index 97% rename from vtm/src/org/oscim/layers/tile/vector/WayDecorator.java rename to vtm/src/org/oscim/layers/tile/vector/labeling/WayDecorator.java index 0bbb7378..f0802bff 100644 --- a/vtm/src/org/oscim/layers/tile/vector/WayDecorator.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/WayDecorator.java @@ -15,10 +15,9 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.layers.tile.vector; +package org.oscim.layers.tile.vector.labeling; import org.oscim.core.Tile; -import org.oscim.layers.tile.MapTile; import org.oscim.renderer.elements.TextItem; import org.oscim.theme.styles.TextStyle; import org.oscim.utils.geom.GeometryUtils; @@ -27,7 +26,7 @@ import org.oscim.utils.geom.LineClipper; public final class WayDecorator { public static void renderText(LineClipper clipper, float[] coordinates, String string, - TextStyle text, int pos, int len, MapTile tile) { + TextStyle text, int pos, int len, LabelTileData ld) { //TextItem items = textItems; TextItem t = null; @@ -216,7 +215,7 @@ public final class WayDecorator { t.length = (short) segmentLength; t.edges = edge; - tile.labels.push(t); + ld.labels.push(t); i = last; }