move Text/Symbol handling to LabelTileLoaderHook
This commit is contained in:
parent
2d15324ead
commit
20d5c20e72
@ -23,7 +23,6 @@ import java.util.concurrent.CancellationException;
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.PointF;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.core.TagSet;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
@ -34,8 +33,6 @@ import org.oscim.renderer.elements.LineLayer;
|
||||
import org.oscim.renderer.elements.LineTexLayer;
|
||||
import org.oscim.renderer.elements.MeshLayer;
|
||||
import org.oscim.renderer.elements.PolygonLayer;
|
||||
import org.oscim.renderer.elements.SymbolItem;
|
||||
import org.oscim.renderer.elements.TextItem;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.RenderTheme;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
@ -295,69 +292,9 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAreaText(TextStyle text) {
|
||||
// TODO place somewhere on polygon
|
||||
String value = mElement.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
int n = mElement.index[0];
|
||||
|
||||
for (int i = 0; i < n;) {
|
||||
x += mElement.points[i++];
|
||||
y += mElement.points[i++];
|
||||
}
|
||||
x /= (n / 2);
|
||||
y /= (n / 2);
|
||||
|
||||
mTile.labels.push(TextItem.pool.get().set(x, y, value, text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderPointText(TextStyle text) {
|
||||
String value = mElement.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
||||
PointF p = mElement.getPoint(i);
|
||||
mTile.labels.push(TextItem.pool.get().set(p.x, p.y, value, text));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWayText(TextStyle text) {
|
||||
String value = mElement.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
int offset = 0;
|
||||
for (int i = 0, n = mElement.index.length; i < n; i++) {
|
||||
int length = mElement.index[i];
|
||||
if (length < 4)
|
||||
break;
|
||||
|
||||
WayDecorator.renderText(null, mElement.points, value, text,
|
||||
offset, length, mTile);
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderPointSymbol(SymbolStyle symbol) {
|
||||
if (symbol.texture == null)
|
||||
return;
|
||||
|
||||
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
||||
PointF p = mElement.getPoint(i);
|
||||
|
||||
SymbolItem it = SymbolItem.pool.get();
|
||||
it.set(p.x, p.y, symbol.texture, true);
|
||||
mTile.symbols.push(it);
|
||||
}
|
||||
public void renderSymbol(SymbolStyle symbol) {
|
||||
for (TileLoaderHook h : mTileLayer.getLoaderHooks())
|
||||
h.render(mTile, mLayers, mElement, symbol, 0);
|
||||
}
|
||||
|
||||
public void renderExtrusion(ExtrusionStyle extrusion, int level) {
|
||||
@ -366,10 +303,12 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAreaSymbol(SymbolStyle symbol) {
|
||||
public void renderCircle(CircleStyle circle, int level) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderPointCircle(CircleStyle circle, int level) {
|
||||
public void renderText(TextStyle text) {
|
||||
for (TileLoaderHook h : mTileLayer.getLoaderHooks())
|
||||
h.render(mTile, mLayers, mElement, text, 0);
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public class LabelLayer extends Layer implements Map.UpdateListener, TileManager
|
||||
public LabelLayer(Map map, VectorTileLayer l) {
|
||||
super(map);
|
||||
l.getManager().events.bind(this);
|
||||
l.addHook(new LabelTileLoaderHook());
|
||||
|
||||
mLabelPlacer = new LabelPlacement(map, l.tileRenderer());
|
||||
mWorker = new Worker(map);
|
||||
|
@ -0,0 +1,89 @@
|
||||
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 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;
|
||||
|
||||
public class LabelTileLoaderHook implements TileLoaderHook {
|
||||
|
||||
@Override
|
||||
public void render(MapTile tile, ElementLayers layers, MapElement element,
|
||||
RenderStyle style, int level) {
|
||||
|
||||
if (style instanceof Text) {
|
||||
Text text = (Text) style;
|
||||
if (element.type == LINE) {
|
||||
String value = element.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
int offset = 0;
|
||||
for (int i = 0, n = element.index.length; i < n; i++) {
|
||||
int length = element.index[i];
|
||||
if (length < 4)
|
||||
break;
|
||||
|
||||
WayDecorator.renderText(null, element.points, value, text,
|
||||
offset, length, tile);
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
else if (element.type == POLY) {
|
||||
// TODO place somewhere on polygon
|
||||
String value = element.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
int n = element.index[0];
|
||||
|
||||
for (int i = 0; i < n;) {
|
||||
x += element.points[i++];
|
||||
y += element.points[i++];
|
||||
}
|
||||
x /= (n / 2);
|
||||
y /= (n / 2);
|
||||
|
||||
tile.labels.push(TextItem.pool.get().set(x, y, value, text));
|
||||
}
|
||||
else if (element.type == POINT) {
|
||||
String value = element.tags.getValue(text.textKey);
|
||||
if (value == null || value.length() == 0)
|
||||
return;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((element.type == POINT) && (style instanceof Symbol)) {
|
||||
Symbol symbol = (Symbol) style;
|
||||
|
||||
if (symbol.texture == null)
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -85,22 +85,6 @@ public interface IRenderTheme {
|
||||
*/
|
||||
void renderExtrusion(ExtrusionStyle extrusion, int level);
|
||||
|
||||
/**
|
||||
* Renders an area symbol with the given bitmap.
|
||||
*
|
||||
* @param symbol
|
||||
* the symbol to be rendered.
|
||||
*/
|
||||
void renderAreaSymbol(SymbolStyle symbol);
|
||||
|
||||
/**
|
||||
* Renders an area caption with the given text.
|
||||
*
|
||||
* @param text
|
||||
* the text to be rendered.
|
||||
*/
|
||||
void renderAreaText(TextStyle text);
|
||||
|
||||
/**
|
||||
* Renders a point of interest circle with the given parameters.
|
||||
*
|
||||
@ -109,7 +93,7 @@ public interface IRenderTheme {
|
||||
* @param level
|
||||
* the drawing level on which the circle should be rendered.
|
||||
*/
|
||||
void renderPointCircle(CircleStyle circle, int level);
|
||||
void renderCircle(CircleStyle circle, int level);
|
||||
|
||||
/**
|
||||
* Renders a point of interest symbol with the given bitmap.
|
||||
@ -117,15 +101,7 @@ public interface IRenderTheme {
|
||||
* @param symbol
|
||||
* the symbol to be rendered.
|
||||
*/
|
||||
void renderPointSymbol(SymbolStyle symbol);
|
||||
|
||||
/**
|
||||
* Renders a point of interest caption with the given text.
|
||||
*
|
||||
* @param text
|
||||
* the text to be rendered.
|
||||
*/
|
||||
void renderPointText(TextStyle text);
|
||||
void renderSymbol(SymbolStyle symbol);
|
||||
|
||||
/**
|
||||
* Renders a way with the given parameters.
|
||||
@ -140,7 +116,7 @@ public interface IRenderTheme {
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
void renderWayText(TextStyle text);
|
||||
void renderText(TextStyle text);
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,6 @@ public final class CircleStyle extends RenderStyle {
|
||||
|
||||
@Override
|
||||
public void renderNode(Callback renderCallback) {
|
||||
renderCallback.renderPointCircle(this, this.level);
|
||||
renderCallback.renderCircle(this, this.level);
|
||||
}
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ public final class SymbolStyle extends RenderStyle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(Callback renderCallback) {
|
||||
renderCallback.renderPointSymbol(this);
|
||||
public void renderNode(Callback cb) {
|
||||
cb.renderSymbol(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(Callback renderCallback) {
|
||||
renderCallback.renderAreaSymbol(this);
|
||||
public void renderWay(Callback cb) {
|
||||
cb.renderSymbol(this);
|
||||
}
|
||||
}
|
||||
|
@ -182,17 +182,13 @@ public final class TextStyle extends RenderStyle {
|
||||
public final TextureRegion texture;
|
||||
|
||||
@Override
|
||||
public void renderNode(Callback renderCallback) {
|
||||
if (caption)
|
||||
renderCallback.renderPointText(this);
|
||||
public void renderNode(Callback cb) {
|
||||
cb.renderText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(Callback renderCallback) {
|
||||
if (caption)
|
||||
renderCallback.renderAreaText(this);
|
||||
else
|
||||
renderCallback.renderWayText(this);
|
||||
public void renderWay(Callback cb) {
|
||||
cb.renderText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user