added MapLensOverlay

This commit is contained in:
Hannes Janetzek 2013-04-06 17:44:57 +02:00
parent eac8047527
commit a6a729244f
5 changed files with 74 additions and 48 deletions

View File

@ -21,7 +21,10 @@ public class MapPosition {
public double lon;
public double lat;
public int zoomLevel;
public double absX;
public double absY;
public double absScale;
public float scale;
public float angle;
public float tilt;
@ -29,6 +32,7 @@ public class MapPosition {
// map center in tile coordinates of current zoom-level
public double x;
public double y;
public int zoomLevel;
public MapPosition() {
this.zoomLevel = (byte) 1;

View File

@ -294,7 +294,7 @@ public final class PolygonRenderer {
}
}
public static void drawOver(Matrices m) {
public static void drawOver(Matrices m, boolean drawColor, int color) {
if (GLState.useProgram(polygonProgram)) {
GLState.enableVertexArrays(hPolygonVertexPosition, -1);
@ -310,9 +310,13 @@ public final class PolygonRenderer {
* a quad with func 'always' and op 'zero'
*/
// disable drawing to framebuffer (will be re-enabled in fill)
glColorMask(false, false, false, false);
if (drawColor) {
GlUtils.setColor(hPolygonColor, color, 1);
GLState.blend(true);
} else {
// disable drawing to framebuffer (will be re-enabled in fill)
glColorMask(false, false, false, false);
}
// always pass stencil test:
glStencilFunc(GL_ALWAYS, 0x00, 0x00);
// write to all bits
@ -321,7 +325,9 @@ public final class PolygonRenderer {
glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_ZERO);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glColorMask(true, true, true, true);
if (!drawColor)
glColorMask(true, true, true, true);
}
private static float[] debugFillColor = { 0.3f, 0.0f, 0.0f, 0.3f };

View File

@ -22,6 +22,7 @@ import org.oscim.core.MapPosition;
import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layer.Layer;
import org.oscim.utils.FastMath;
import org.oscim.utils.Matrix4;
import android.opengl.GLES20;
@ -44,10 +45,17 @@ public class TileRenderer {
private static Matrices mMatrices;
private static final Matrix4 mProjMatrix = new Matrix4();
static void draw(MapTile[] tiles, int tileCnt, MapPosition pos, Matrices m) {
mDrawCnt = 0;
mMatrices = m;
mProjMatrix.copy(m.viewproj);
// discard z projection from tilt
mProjMatrix.setValue(10, 0);
mProjMatrix.setValue(14, 0);
GLES20.glDepthFunc(GLES20.GL_LESS);
// load texture for line caps
@ -116,11 +124,11 @@ public class TileRenderer {
Matrices m = mMatrices;
m.mvp.setTransScale(x * scale, y * scale, scale / GLRenderer.COORD_SCALE);
m.mvp.multiplyMM(m.viewproj, m.mvp);
m.mvp.multiplyMM(mProjMatrix, m.mvp);
// set depth offset (used for clipping to tile boundaries)
GLES20.glPolygonOffset(1, mDrawCnt++);
if (mDrawCnt > 20)
if (mDrawCnt == 100)
mDrawCnt = 0;
// simple line shader does not take forward shortening into account
@ -160,7 +168,7 @@ public class TileRenderer {
}
// clear clip-region and could also draw 'fade-effect'
PolygonRenderer.drawOver(m);
PolygonRenderer.drawOver(m, true, 0x22000000);
}
private static int drawProxyChild(MapTile tile, MapPosition pos) {

View File

@ -38,14 +38,13 @@ import org.oscim.generator.JobTile;
import org.oscim.generator.MapWorker;
import org.oscim.generator.TileGenerator;
import org.oscim.overlay.BuildingOverlay;
import org.oscim.overlay.GenericOverlay;
import org.oscim.overlay.LabelingOverlay;
import org.oscim.overlay.MapLensOverlay;
import org.oscim.overlay.Overlay;
import org.oscim.overlay.OverlayManager;
import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.GLView;
import org.oscim.renderer.TileManager;
import org.oscim.renderer.overlays.TileOverlay;
import org.oscim.theme.ExternalRenderTheme;
import org.oscim.theme.InternalRenderTheme;
import org.oscim.theme.RenderTheme;
@ -197,8 +196,8 @@ public class MapView extends RelativeLayout {
mOverlayManager.add(new LabelingOverlay(this));
mOverlayManager.add(new GenericOverlay(this, new TileOverlay(this)));
//mOverlayManager.add(new GenericOverlay(this, new TileOverlay(this)));
mOverlayManager.add(new MapLensOverlay(this));
//mOverlayManager.add(new GenericOverlay(this, new CustomOverlay(this)));

View File

@ -157,6 +157,10 @@ public class MapViewPosition {
pos.angle = mRotation;
pos.tilt = mTilt;
pos.absX = mAbsX;
pos.absY = mAbsY;
pos.absScale = mAbsScale;
// for tiling
pos.scale = scale;
pos.zoomLevel = (byte) z;
@ -312,28 +316,33 @@ public class MapViewPosition {
return bbox;
}
// /**
// * For x, y in screen coordinates set Point to map-tile
// * coordinates at returned scale.
// *
// * @param x screen coordinate
// * @param y screen coordinate
// * @param out Point coords will be set
// * @return current map scale
// */
// public synchronized float getScreenPointOnMap(float x, float y, PointD out) {
//
// // scale to -1..1
// float mx = 1 - (x / mWidth * 2);
// float my = 1 - (y / mHeight * 2);
//
// unproject(-mx, my, getZ(-my), mu, 0);
//
// out.x = mCurX + mu[0];
// out.y = mCurY + mu[1];
//
// return (float) mAbsScale;
// }
/**
* For x, y in screen coordinates set Point to map-tile
* coordinates at returned scale.
*
* @param x screen coordinate
* @param y screen coordinate
* @param out Point coords will be set
*/
public synchronized void getScreenPointOnMap(float x, float y, double scale, PointD out) {
// scale to -1..1
float mx = 1 - (x / mWidth * 2);
float my = 1 - (y / mHeight * 2);
unproject(-mx, my, getZ(-my), mu, 0);
//out.x = mCurX + mu[0];
//out.y = mCurY + mu[1];
out.x = mu[0];
out.y = mu[1];
if (scale != 0) {
out.x *= scale / mAbsScale;
out.y *= scale / mAbsScale;
}
}
/**
* Get the GeoPoint for x,y in screen coordinates.
@ -729,23 +738,23 @@ public class MapViewPosition {
mHandler.start(mDuration);
}
synchronized boolean fling(float adv) {
synchronized boolean fling(float adv){
//float delta = (mDuration - millisLeft) / mDuration;
adv = (float) Math.sqrt(adv);
float dx = mVelocityX * adv;
float dy = mVelocityY * adv;
//float delta = (mDuration - millisLeft) / mDuration;
adv = (float)Math.sqrt(adv);
float dx = mVelocityX * adv;
float dy = mVelocityY * adv;
if (dx != 0 || dy != 0) {
moveMap((float) (dx - mScrollX), (float) (dy - mScrollY));
if (dx != 0 || dy != 0){
moveMap((float)(dx - mScrollX), (float)(dy - mScrollY));
mMapView.redrawMap(true);
mScrollX = dx;
mScrollY = dy;
mMapView.redrawMap(true);
mScrollX = dx;
mScrollY = dy;
}
return true;
}
return true;
}
private float mVelocityX;
private float mVelocityY;