add osmdroid overlays + bonuspack
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
package org.oscim.renderer.overlays;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.renderer.layer.Layer;
|
||||
import org.oscim.renderer.layer.LineLayer;
|
||||
@@ -27,13 +28,13 @@ import android.graphics.Color;
|
||||
import android.graphics.Paint.Cap;
|
||||
import android.util.Log;
|
||||
|
||||
public class OverlayGrid extends Overlay {
|
||||
public class OverlayGrid extends RenderOverlay {
|
||||
|
||||
private float[] mPoints;
|
||||
private short[] mIndex;
|
||||
private Text mText;
|
||||
|
||||
OverlayGrid(MapView mapView) {
|
||||
public OverlayGrid(MapView mapView) {
|
||||
super(mapView);
|
||||
|
||||
int size = Tile.TILE_SIZE;
|
||||
@@ -91,6 +92,8 @@ public class OverlayGrid extends Overlay {
|
||||
tl.addText(ti);
|
||||
}
|
||||
}
|
||||
tl.prepare();
|
||||
|
||||
layers.textureLayers = tl;
|
||||
}
|
||||
|
||||
@@ -107,7 +110,7 @@ public class OverlayGrid extends Overlay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(boolean positionChanged, boolean tilesChanged) {
|
||||
public synchronized void update(MapPosition curPos, boolean positionChanged, boolean tilesChanged) {
|
||||
|
||||
updateMapPosition();
|
||||
|
||||
@@ -134,6 +137,8 @@ public class OverlayGrid extends Overlay {
|
||||
ll.width = 1.5f;
|
||||
ll.addLine(mPoints, mIndex, false);
|
||||
|
||||
Log.d("...", "update labels");
|
||||
|
||||
addLabels(x, y, mCurZ);
|
||||
|
||||
newData = true;
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
*/
|
||||
package org.oscim.renderer.overlays;
|
||||
|
||||
import org.oscim.renderer.layer.Layer;
|
||||
import org.oscim.renderer.layer.LineLayer;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.layer.SymbolItem;
|
||||
import org.oscim.renderer.layer.SymbolLayer;
|
||||
import org.oscim.renderer.layer.TextItem;
|
||||
import org.oscim.theme.renderinstruction.Line;
|
||||
import org.oscim.theme.renderinstruction.BitmapUtils;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint.Cap;
|
||||
|
||||
public class OverlayTest extends Overlay {
|
||||
public class OverlayTest extends RenderOverlay {
|
||||
|
||||
TextItem labels;
|
||||
|
||||
@@ -31,15 +31,16 @@ public class OverlayTest extends Overlay {
|
||||
|
||||
private boolean first = true;
|
||||
|
||||
OverlayTest(MapView mapView) {
|
||||
public OverlayTest(MapView mapView) {
|
||||
super(mapView);
|
||||
|
||||
LineLayer ll = (LineLayer) layers.getLayer(1, Layer.LINE);
|
||||
ll.line = new Line(Color.BLUE, 1.0f, Cap.BUTT);
|
||||
ll.width = 2;
|
||||
float[] points = { -100, -100, 100, -100, 100, 100, -100, 100, -100, -100 };
|
||||
short[] index = { (short) points.length };
|
||||
ll.addLine(points, index, false);
|
||||
// LineLayer ll = (LineLayer) layers.getLayer(1, Layer.LINE);
|
||||
// ll.line = new Line(Color.BLUE, 1.0f, Cap.BUTT);
|
||||
// ll.width = 2;
|
||||
// float[] points = { -100, -100, 100, -100, 100, 100, -100, 100, -100, -100 };
|
||||
// short[] index = { (short) points.length };
|
||||
// ll.addLine(points, index, false);
|
||||
|
||||
//
|
||||
// PolygonLayer pl = (PolygonLayer) layers.getLayer(0, Layer.POLYGON);
|
||||
// pl.area = new Area(Color.argb(128, 255, 0, 0));
|
||||
@@ -53,30 +54,33 @@ public class OverlayTest extends Overlay {
|
||||
// short[] pindex = { (short) ppoints.length };
|
||||
// pl.addPolygon(ppoints, pindex);
|
||||
|
||||
// SymbolLayer sl = new SymbolLayer();
|
||||
// SymbolItem it = new SymbolItem();
|
||||
//
|
||||
// it.x = 0;
|
||||
// it.y = 0;
|
||||
// // billboard always faces camera
|
||||
// it.billboard = true;
|
||||
//
|
||||
// try {
|
||||
// it.bitmap = BitmapUtils.createBitmap("file:/sdcard/cheshire.png");
|
||||
// } catch (IOException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// sl.addSymbol(it);
|
||||
//
|
||||
// SymbolItem it2 = new SymbolItem();
|
||||
// it2.bitmap = it.bitmap;
|
||||
// it2.x = 0;
|
||||
// it2.y = 0;
|
||||
// // billboard always faces camera
|
||||
// it2.billboard = false;
|
||||
//
|
||||
// sl.addSymbol(it2);
|
||||
SymbolLayer sl = new SymbolLayer();
|
||||
SymbolItem it = new SymbolItem();
|
||||
|
||||
it.x = 0;
|
||||
it.y = 0;
|
||||
// billboard always faces camera
|
||||
it.billboard = true;
|
||||
|
||||
try {
|
||||
it.bitmap = BitmapUtils.createBitmap("file:/sdcard/cheshire.png");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
sl.addSymbol(it);
|
||||
|
||||
SymbolItem it2 = new SymbolItem();
|
||||
it2.bitmap = it.bitmap;
|
||||
it2.x = 0;
|
||||
it2.y = 0;
|
||||
// billboard always faces camera
|
||||
it2.billboard = false;
|
||||
|
||||
sl.addSymbol(it2);
|
||||
sl.fixed = false;
|
||||
|
||||
layers.textureLayers = sl;
|
||||
|
||||
// TextLayer tl = new TextLayer();
|
||||
// Text t = Text.createText(20, 2, Color.WHITE, Color.BLACK, false);
|
||||
@@ -92,14 +96,16 @@ public class OverlayTest extends Overlay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(boolean positionChanged, boolean tilesChanged) {
|
||||
public synchronized void update(MapPosition curPos, boolean positionChanged, boolean tilesChanged) {
|
||||
// keep position constant (or update layer relative to new position)
|
||||
mMapView.getMapViewPosition().getMapPosition(mMapPosition, null);
|
||||
//mMapView.getMapViewPosition().getMapPosition(mMapPosition, null);
|
||||
|
||||
if (first) {
|
||||
// fix at initial position
|
||||
// mapView.getMapViewPosition().getMapPosition(mMapPosition, null);
|
||||
updateMapPosition();
|
||||
|
||||
first = false;
|
||||
((SymbolLayer) (layers.textureLayers)).prepare();
|
||||
|
||||
// pass layers to be uploaded and drawn to GL Thread
|
||||
// afterwards never modify 'layers' outside of this function!
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.oscim.renderer.overlays;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.renderer.TileManager;
|
||||
import org.oscim.renderer.MapTile;
|
||||
import org.oscim.renderer.TileManager;
|
||||
import org.oscim.renderer.Tiles;
|
||||
import org.oscim.renderer.layer.TextItem;
|
||||
import org.oscim.renderer.layer.TextLayer;
|
||||
@@ -29,20 +29,23 @@ import org.oscim.view.MapView;
|
||||
import android.os.SystemClock;
|
||||
import android.util.FloatMath;
|
||||
|
||||
public class OverlayText extends Overlay {
|
||||
public class OverlayText extends RenderOverlay {
|
||||
|
||||
private Tiles tiles;
|
||||
private LabelThread mThread;
|
||||
/* package */boolean mRun;
|
||||
/* package */boolean mRerun;
|
||||
|
||||
private MapPosition mWorkPos;
|
||||
private TextLayer mWorkLayer;
|
||||
private TextLayer mNewLayer;
|
||||
|
||||
/* package */boolean mRun;
|
||||
/* package */boolean mRerun;
|
||||
|
||||
class LabelThread extends PausableThread {
|
||||
|
||||
@Override
|
||||
protected void doWork() {
|
||||
SystemClock.sleep(250);
|
||||
SystemClock.sleep(300);
|
||||
mRun = false;
|
||||
updateLabels();
|
||||
mMapView.redrawMap();
|
||||
@@ -70,14 +73,29 @@ public class OverlayText extends Overlay {
|
||||
void updateLabels() {
|
||||
tiles = TileManager.getActiveTiles(tiles);
|
||||
|
||||
// Log.d("...", "relabel " + mRerun + " " + x + " " + y);
|
||||
if (tiles.cnt == 0)
|
||||
return;
|
||||
|
||||
mMapView.getMapViewPosition().getMapPosition(mWorkPos, null);
|
||||
|
||||
// TODO tiles might be from another zoomlevel than the current:
|
||||
TextLayer tl = mWorkLayer;
|
||||
|
||||
if (tl == null)
|
||||
tl = new TextLayer();
|
||||
|
||||
// tiles might be from another zoomlevel than the current:
|
||||
// this scales MapPosition to the zoomlevel of tiles...
|
||||
// TODO create a helper function in MapPosition
|
||||
int diff = tiles.tiles[0].zoomLevel - mWorkPos.zoomLevel;
|
||||
|
||||
if (diff > 1 || diff < -2) {
|
||||
synchronized (this) {
|
||||
mNewLayer = tl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float div = FastMath.pow(diff);
|
||||
|
||||
// fix map position to tile coordinates
|
||||
@@ -89,14 +107,11 @@ public class OverlayText extends Overlay {
|
||||
mWorkPos.zoomLevel += diff;
|
||||
mWorkPos.scale = div;
|
||||
|
||||
// Log.d("...", "relabel " + mRerun + " " + x + " " + y);
|
||||
|
||||
TextLayer tl = new TextLayer();
|
||||
|
||||
float angle = (float) Math.toRadians(mWorkPos.angle);
|
||||
float cos = FloatMath.cos(angle);
|
||||
float sin = FloatMath.sin(angle);
|
||||
|
||||
// TODO more sophisticated placement :)
|
||||
for (int i = 0, n = tiles.cnt; i < n; i++) {
|
||||
MapTile t = tiles.tiles[i];
|
||||
if (!t.isVisible)
|
||||
@@ -104,7 +119,6 @@ public class OverlayText extends Overlay {
|
||||
|
||||
int dx = (t.tileX - x) * Tile.TILE_SIZE;
|
||||
int dy = (t.tileY - y) * Tile.TILE_SIZE;
|
||||
// Log.d("...", "update tiles " + dx + " " + dy);
|
||||
|
||||
for (TextItem ti = t.labels; ti != null; ti = ti.next) {
|
||||
|
||||
@@ -129,20 +143,27 @@ public class OverlayText extends Overlay {
|
||||
}
|
||||
}
|
||||
|
||||
// draw text to bitmaps and create vertices
|
||||
tl.prepare();
|
||||
|
||||
// everything synchronized?
|
||||
synchronized (this) {
|
||||
mWorkLayer = tl;
|
||||
mNewLayer = tl;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(boolean positionChanged, boolean tilesChanged) {
|
||||
public synchronized void update(MapPosition curPos, boolean positionChanged, boolean tilesChanged) {
|
||||
// Log.d("...", "update " + tilesChanged + " " + positionChanged);
|
||||
|
||||
if (mWorkLayer != null) {
|
||||
if (mNewLayer != null) {
|
||||
|
||||
// keep text layer, not recrating its canvas each time...
|
||||
mWorkLayer = (TextLayer) layers.textureLayers;
|
||||
layers.clear();
|
||||
layers.textureLayers = mWorkLayer;
|
||||
mWorkLayer = null;
|
||||
|
||||
layers.textureLayers = mNewLayer;
|
||||
mNewLayer = null;
|
||||
|
||||
// make the 'labeled' MapPosition current
|
||||
MapPosition tmp = mMapPosition;
|
||||
@@ -154,7 +175,6 @@ public class OverlayText extends Overlay {
|
||||
}
|
||||
|
||||
if (tilesChanged || positionChanged) {
|
||||
|
||||
if (!mRun) {
|
||||
mRun = true;
|
||||
synchronized (mThread) {
|
||||
|
||||
@@ -28,12 +28,14 @@ import org.oscim.view.MapView;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.Matrix;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class Overlay {
|
||||
public abstract class RenderOverlay {
|
||||
|
||||
protected final MapView mMapView;
|
||||
// keep the Position for which the Overlay is rendered
|
||||
protected MapPosition mMapPosition;
|
||||
|
||||
// current Layers to draw
|
||||
public final Layers layers;
|
||||
|
||||
// flag to set when data is ready for (re)compilation.
|
||||
@@ -44,19 +46,14 @@ public abstract class Overlay {
|
||||
|
||||
public BufferObject vbo;
|
||||
|
||||
public Overlay(MapView mapView) {
|
||||
public RenderOverlay(MapView mapView) {
|
||||
mMapView = mapView;
|
||||
mMapPosition = new MapPosition();
|
||||
layers = new Layers();
|
||||
}
|
||||
|
||||
synchronized boolean onTouch(boolean down) {
|
||||
Log.d("...", "Overlay handle onTouch " + down);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* update mMapPosition
|
||||
* Utility: update mMapPosition
|
||||
*
|
||||
* @return true if position has changed
|
||||
*/
|
||||
@@ -68,12 +65,13 @@ public abstract class Overlay {
|
||||
// use synchronized (this){} when updating 'layers' from another thread
|
||||
|
||||
/**
|
||||
* @param curPos TODO
|
||||
* @param positionChanged
|
||||
* true when MapPosition has changed
|
||||
* @param tilesChanged
|
||||
* true when loaded tiles changed
|
||||
*/
|
||||
public synchronized void update(boolean positionChanged, boolean tilesChanged) {
|
||||
public synchronized void update(MapPosition curPos, boolean positionChanged, boolean tilesChanged) {
|
||||
// // keep position constant (or update layer relative to new position)
|
||||
// mMapView.getMapViewPosition().getMapPosition(mMapPosition, null);
|
||||
//
|
||||
@@ -110,23 +108,20 @@ public abstract class Overlay {
|
||||
// float scale = curPos.scale / div;
|
||||
|
||||
for (Layer l = layers.textureLayers; l != null;) {
|
||||
|
||||
l = TextureRenderer.draw(l, (mMapPosition.scale / pos.scale) * div, proj, mv,
|
||||
layers.texOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private float setMatrix(MapPosition curPos, float[] matrix) {
|
||||
// TODO if oPos == curPos this could be simplified
|
||||
|
||||
MapPosition oPos = mMapPosition;
|
||||
|
||||
byte z = oPos.zoomLevel;
|
||||
// int diff = curPos.zoomLevel - z;
|
||||
float div = FastMath.pow(z - curPos.zoomLevel);
|
||||
// if (diff < 0)
|
||||
// div = (1 << -diff);
|
||||
// else if (diff > 0)
|
||||
// div = (1.0f / (1 << diff));
|
||||
|
||||
float div = FastMath.pow(z - curPos.zoomLevel);
|
||||
float x = (float) (oPos.x - curPos.x * div);
|
||||
float y = (float) (oPos.y - curPos.y * div);
|
||||
|
||||
@@ -145,8 +140,8 @@ public abstract class Overlay {
|
||||
matrix[12] = x * scale;
|
||||
matrix[13] = y * scale;
|
||||
|
||||
// scale to current tile world coordinates
|
||||
scale = (curPos.scale / oPos.scale) / div;
|
||||
// scale to tile to world coordinates
|
||||
scale /= GLRenderer.COORD_MULTIPLIER;
|
||||
matrix[0] = scale;
|
||||
matrix[5] = scale;
|
||||
Reference in New Issue
Block a user