move Label/Symbol data from MapTile to LabelTileData
This commit is contained in:
parent
20d5c20e72
commit
c234507edb
@ -105,14 +105,6 @@ public class MapTile extends Tile {
|
|||||||
*/
|
*/
|
||||||
public float distance;
|
public float distance;
|
||||||
|
|
||||||
/**
|
|
||||||
* FIXME move to VectorMapTile
|
|
||||||
* Tile data set by TileLoader.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final List<SymbolItem> symbols = new List<SymbolItem>();
|
|
||||||
public final List<TextItem> labels = new List<TextItem>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tile is in view region. Set by TileRenderer.
|
* Tile is in view region. Set by TileRenderer.
|
||||||
*/
|
*/
|
||||||
@ -242,9 +234,6 @@ public class MapTile extends Tile {
|
|||||||
data = data.next;
|
data = data.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextItem.pool.releaseAll(labels.clear());
|
|
||||||
SymbolItem.pool.releaseAll(symbols.clear());
|
|
||||||
|
|
||||||
// still needed?
|
// still needed?
|
||||||
state = State.NONE;
|
state = State.NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,8 @@ public class LabelLayer extends Layer implements Map.UpdateListener, TileManager
|
|||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(LabelLayer.class);
|
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 static long MAX_RELABEL_DELAY = 100;
|
||||||
|
|
||||||
private final LabelPlacement mLabelPlacer;
|
private final LabelPlacement mLabelPlacer;
|
||||||
|
|||||||
@ -18,6 +18,10 @@ import org.oscim.utils.geom.OBB2D;
|
|||||||
public class LabelPlacement {
|
public class LabelPlacement {
|
||||||
static final boolean dbg = false;
|
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_CAPTION_DIST = 5;
|
||||||
private final static float MIN_WAY_DIST = 3;
|
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,
|
private Label addWayLabels(MapTile t, Label l, float dx, float dy,
|
||||||
double scale) {
|
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)
|
if (ti.text.caption)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -229,7 +237,11 @@ public class LabelPlacement {
|
|||||||
private Label addNodeLabels(MapTile t, Label l, float dx, float dy,
|
private Label addNodeLabels(MapTile t, Label l, float dx, float dy,
|
||||||
double scale, float cos, float sin) {
|
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)
|
if (!ti.text.caption)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -447,7 +459,11 @@ public class LabelPlacement {
|
|||||||
float dy = (float) (t.tileY * Tile.SIZE - tileY);
|
float dy = (float) (t.tileY * Tile.SIZE - tileY);
|
||||||
dx = flipLongitude(dx, maxx);
|
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)
|
if (ti.texRegion == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@ -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<SymbolItem> symbols = new List<SymbolItem>();
|
||||||
|
public final List<TextItem> labels = new List<TextItem>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dispose() {
|
||||||
|
TextItem.pool.releaseAll(labels.clear());
|
||||||
|
SymbolItem.pool.releaseAll(symbols.clear());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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.LINE;
|
||||||
import static org.oscim.core.GeometryBuffer.GeometryType.POINT;
|
import static org.oscim.core.GeometryBuffer.GeometryType.POINT;
|
||||||
import static org.oscim.core.GeometryBuffer.GeometryType.POLY;
|
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.MapElement;
|
||||||
import org.oscim.core.PointF;
|
import org.oscim.core.PointF;
|
||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
import org.oscim.layers.tile.vector.VectorTileLayer.TileLoaderHook;
|
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.ElementLayers;
|
||||||
import org.oscim.renderer.elements.SymbolItem;
|
import org.oscim.renderer.elements.SymbolItem;
|
||||||
import org.oscim.renderer.elements.TextItem;
|
import org.oscim.renderer.elements.TextItem;
|
||||||
import org.oscim.theme.styles.RenderStyle;
|
import org.oscim.theme.styles.RenderStyle;
|
||||||
import org.oscim.theme.styles.Symbol;
|
import org.oscim.theme.styles.SymbolStyle;
|
||||||
import org.oscim.theme.styles.Text;
|
import org.oscim.theme.styles.TextStyle;
|
||||||
|
|
||||||
public class LabelTileLoaderHook implements TileLoaderHook {
|
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
|
@Override
|
||||||
public void render(MapTile tile, ElementLayers layers, MapElement element,
|
public void render(MapTile tile, ElementLayers layers, MapElement element,
|
||||||
RenderStyle style, int level) {
|
RenderStyle style, int level) {
|
||||||
|
|
||||||
if (style instanceof Text) {
|
if (style instanceof TextStyle) {
|
||||||
Text text = (Text) style;
|
LabelTileData ld = get(tile);
|
||||||
|
|
||||||
|
TextStyle text = (TextStyle) style;
|
||||||
if (element.type == LINE) {
|
if (element.type == LINE) {
|
||||||
String value = element.tags.getValue(text.textKey);
|
String value = element.tags.getValue(text.textKey);
|
||||||
if (value == null || value.length() == 0)
|
if (value == null || value.length() == 0)
|
||||||
@ -36,7 +50,7 @@ public class LabelTileLoaderHook implements TileLoaderHook {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
WayDecorator.renderText(null, element.points, value, text,
|
WayDecorator.renderText(null, element.points, value, text,
|
||||||
offset, length, tile);
|
offset, length, ld);
|
||||||
offset += length;
|
offset += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +71,7 @@ public class LabelTileLoaderHook implements TileLoaderHook {
|
|||||||
x /= (n / 2);
|
x /= (n / 2);
|
||||||
y /= (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) {
|
else if (element.type == POINT) {
|
||||||
String value = element.tags.getValue(text.textKey);
|
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++) {
|
for (int i = 0, n = element.getNumPoints(); i < n; i++) {
|
||||||
PointF p = element.getPoint(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)) {
|
else if ((element.type == POINT) && (style instanceof SymbolStyle)) {
|
||||||
Symbol symbol = (Symbol) style;
|
SymbolStyle symbol = (SymbolStyle) style;
|
||||||
|
|
||||||
if (symbol.texture == null)
|
if (symbol.texture == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
LabelTileData ld = get(tile);
|
||||||
|
|
||||||
for (int i = 0, n = element.getNumPoints(); i < n; i++) {
|
for (int i = 0, n = element.getNumPoints(); i < n; i++) {
|
||||||
PointF p = element.getPoint(i);
|
PointF p = element.getPoint(i);
|
||||||
|
|
||||||
SymbolItem it = SymbolItem.pool.get();
|
SymbolItem it = SymbolItem.pool.get();
|
||||||
it.set(p.x, p.y, symbol.texture, true);
|
it.set(p.x, p.y, symbol.texture, true);
|
||||||
tile.symbols.push(it);
|
ld.symbols.push(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,10 +15,9 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.layers.tile.vector;
|
package org.oscim.layers.tile.vector.labeling;
|
||||||
|
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.layers.tile.MapTile;
|
|
||||||
import org.oscim.renderer.elements.TextItem;
|
import org.oscim.renderer.elements.TextItem;
|
||||||
import org.oscim.theme.styles.TextStyle;
|
import org.oscim.theme.styles.TextStyle;
|
||||||
import org.oscim.utils.geom.GeometryUtils;
|
import org.oscim.utils.geom.GeometryUtils;
|
||||||
@ -27,7 +26,7 @@ import org.oscim.utils.geom.LineClipper;
|
|||||||
public final class WayDecorator {
|
public final class WayDecorator {
|
||||||
|
|
||||||
public static void renderText(LineClipper clipper, float[] coordinates, String string,
|
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 items = textItems;
|
||||||
TextItem t = null;
|
TextItem t = null;
|
||||||
|
|
||||||
@ -216,7 +215,7 @@ public final class WayDecorator {
|
|||||||
t.length = (short) segmentLength;
|
t.length = (short) segmentLength;
|
||||||
|
|
||||||
t.edges = edge;
|
t.edges = edge;
|
||||||
tile.labels.push(t);
|
ld.labels.push(t);
|
||||||
|
|
||||||
i = last;
|
i = last;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user