diff --git a/src/org/oscim/layers/labeling/Debug.java b/src/org/oscim/layers/labeling/Debug.java
new file mode 100644
index 00000000..f4af5e73
--- /dev/null
+++ b/src/org/oscim/layers/labeling/Debug.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2013
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.layers.labeling;
+
+import org.oscim.graphics.Color;
+import org.oscim.renderer.sublayers.Layers;
+import org.oscim.renderer.sublayers.LineLayer;
+import org.oscim.renderer.sublayers.TextItem;
+import org.oscim.theme.renderinstruction.Line;
+
+public class Debug {
+
+ private final static float[] mDebugPoints = new float[4];
+
+ static void addDebugBox(Layers dbg, Label l, TextItem ti, int overlaps, boolean prev,
+ float scale) {
+
+ LineLayer ll;
+ if (prev) {
+ if (overlaps == 1)
+ ll = dbg.getLineLayer(4);
+ else
+ ll = dbg.getLineLayer(5);
+
+ } else {
+ if (ti.width > ti.length * scale) {
+ ll = dbg.getLineLayer(1);
+ overlaps = 3;
+ }
+ else if (overlaps == 1)
+ ll = dbg.getLineLayer(0);
+ else if (overlaps == 2)
+ ll = dbg.getLineLayer(3);
+ else
+ ll = dbg.getLineLayer(2);
+ }
+ float[] points = mDebugPoints;
+ float width = (ti.x2 - ti.x1) / 2f;
+ float height = (ti.y2 - ti.y1) / 2f;
+ points[0] = (l.x - width * scale);
+ points[1] = (l.y - height * scale);
+ points[2] = (l.x + width * scale);
+ points[3] = (l.y + height * scale);
+ ll.addLine(points, null, false);
+
+ if (l.bbox != null && overlaps != 3) {
+ ll.addLine(l.bbox.corner, null, true);
+ }
+ }
+
+ static void addDebugLayers(Layers dbg) {
+ int alpha = 0xaaffffff;
+
+ dbg.clear();
+ dbg.addLineLayer(0, new Line((Color.BLUE & alpha), 2));
+ dbg.addLineLayer(1, new Line((Color.RED & alpha), 2));
+ dbg.addLineLayer(3, new Line((Color.YELLOW & alpha), 2));
+ dbg.addLineLayer(2, new Line((Color.GREEN & alpha), 2));
+ dbg.addLineLayer(4, new Line((Color.CYAN & alpha), 2));
+ dbg.addLineLayer(5, new Line((Color.MAGENTA & alpha), 2));
+ }
+
+}
diff --git a/src/org/oscim/layers/labeling/Label.java b/src/org/oscim/layers/labeling/Label.java
new file mode 100644
index 00000000..5136f544
--- /dev/null
+++ b/src/org/oscim/layers/labeling/Label.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2013 Hannes Janetzek
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.layers.labeling;
+
+import org.oscim.layers.tile.MapTile;
+import org.oscim.renderer.sublayers.TextItem;
+import org.oscim.utils.OBB2D;
+
+class Label extends TextItem {
+ TextItem item;
+
+ //Link blocking;
+ //Link blockedBy;
+ // shared list of all label for a tile
+ //Link siblings;
+
+ MapTile tile;
+
+ //public byte origin;
+ public int active;
+ public OBB2D bbox;
+
+ public TextItem move(TextItem ti, float dx, float dy, float scale) {
+ this.x = (dx + ti.x) * scale;
+ this.y = (dy + ti.y) * scale;
+ return this;
+ }
+
+ public void clone(TextItem ti) {
+ this.string = ti.string;
+ this.text = ti.text;
+ this.width = ti.width;
+ this.length = ti.length;
+ }
+
+ public void setAxisAlignedBBox() {
+ this.x1 = x - width / 2;
+ this.y1 = y - text.fontHeight / 2;
+ this.x2 = x + width / 2;
+ this.y2 = y + text.fontHeight / 2;
+ }
+
+ static int comparePriority(Label l1, Label l2){
+
+
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/src/org/oscim/layers/overlay/LabelingOverlay.java b/src/org/oscim/layers/labeling/LabelLayer.java
similarity index 82%
rename from src/org/oscim/layers/overlay/LabelingOverlay.java
rename to src/org/oscim/layers/labeling/LabelLayer.java
index 619e5b0b..7e7827bf 100644
--- a/src/org/oscim/layers/overlay/LabelingOverlay.java
+++ b/src/org/oscim/layers/labeling/LabelLayer.java
@@ -12,25 +12,24 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see .
*/
-package org.oscim.layers.overlay;
+package org.oscim.layers.labeling;
import org.oscim.core.MapPosition;
+import org.oscim.layers.InputLayer;
import org.oscim.layers.tile.TileRenderLayer;
-import org.oscim.renderer.layers.TextRenderLayer;
import org.oscim.view.MapView;
import android.util.Log;
import android.view.MotionEvent;
-/**
- * @author Hannes Janetzek
- */
-public class LabelingOverlay extends Overlay {
- private final static String TAG = LabelingOverlay.class.getName();
+public class LabelLayer extends InputLayer {
+ private final static String TAG = LabelLayer.class.getName();
final TextRenderLayer mTextLayer;
- public LabelingOverlay(MapView mapView, TileRenderLayer tileRenderLayer) {
+ public LabelLayer(MapView mapView, TileRenderLayer tileRenderLayer) {
super(mapView);
+
+ //mTextLayer = new org.oscim.renderer.layers.TextRenderLayer(mapView, tileRenderLayer);
mTextLayer = new TextRenderLayer(mapView, tileRenderLayer);
mLayer = mTextLayer;
}
diff --git a/src/org/oscim/layers/labeling/TextRenderLayer.java b/src/org/oscim/layers/labeling/TextRenderLayer.java
new file mode 100644
index 00000000..c9b3215a
--- /dev/null
+++ b/src/org/oscim/layers/labeling/TextRenderLayer.java
@@ -0,0 +1,698 @@
+/*
+ * Copyright 2012 Hannes Janetzek
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+
+package org.oscim.layers.labeling;
+
+// TODO
+// 1. rewrite :)
+// 1.1 test if label is actually visible
+// 2. compare previous to current state
+// 2.1 test for new labels to be placed
+// 2.2 handle collisions
+// 2.3 try to place labels along a way
+// 2.4 use 4 point labeling
+// 3 join segments that belong to one feature
+// 4 handle zoom-level changes
+// 5 R-Tree might be handy
+//
+
+import org.oscim.core.MapPosition;
+import org.oscim.core.Tile;
+import org.oscim.layers.tile.MapTile;
+import org.oscim.layers.tile.TileRenderLayer;
+import org.oscim.layers.tile.TileSet;
+import org.oscim.renderer.GLRenderer.Matrices;
+import org.oscim.renderer.GLState;
+import org.oscim.renderer.layers.BasicRenderLayer;
+import org.oscim.renderer.sublayers.Layer;
+import org.oscim.renderer.sublayers.Layers;
+import org.oscim.renderer.sublayers.LineRenderer;
+import org.oscim.renderer.sublayers.PolygonRenderer;
+import org.oscim.renderer.sublayers.TextItem;
+import org.oscim.renderer.sublayers.TextLayer;
+import org.oscim.renderer.sublayers.TextureRenderer;
+import org.oscim.utils.FastMath;
+import org.oscim.utils.OBB2D;
+import org.oscim.utils.pool.LList;
+import org.oscim.utils.pool.Pool;
+import org.oscim.view.MapView;
+import org.oscim.view.MapViewPosition;
+
+import android.opengl.GLES20;
+import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Looper;
+
+public class TextRenderLayer extends BasicRenderLayer {
+ private final static String TAG = TextRenderLayer.class.getName();
+ private final static float MIN_CAPTION_DIST = 5;
+ private final static float MIN_WAY_DIST = 3;
+
+ private final static long MAX_RELABEL_DELAY = 200;
+
+ private final MapViewPosition mMapViewPosition;
+ private final TileSet mTileSet;
+
+ private MapPosition mTmpPos;
+
+ // TextLayer that is updating
+ private TextLayer mTmpLayer;
+ // TextLayer that is ready to be added to 'layers'
+ private TextLayer mNextLayer;
+
+ // thread local pool
+ class LabelPool extends Pool {
+ Label releaseAndGetNext(Label l) {
+ if (l.item != null)
+ TextItem.pool.release(l.item);
+
+ // drop references
+ l.item = null;
+ l.tile = null;
+ l.string = null;
+
+ Label ret = (Label) l.next;
+
+ super.release(l);
+
+ return ret;
+ }
+
+ @Override
+ protected TextItem createItem() {
+ return new Label();
+ }
+ }
+
+ private final LabelPool mPool = new LabelPool();
+
+ // list of previous labels
+ private Label mPrevLabels;
+
+ // list of current labels
+ private Label mLabels;
+
+ //private final float[] mTmpCoords = new float[8];
+
+ //private final HashMap mActiveTiles;
+
+ class LabelTile {
+ Tile tile;
+ LList