fix precision issue on high zoom-levels

This commit is contained in:
Hannes Janetzek 2013-04-18 18:14:09 +02:00
parent 24438c1e68
commit 056289d03b
2 changed files with 22 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 osmdroid
* Copyright 2012 osmdroid authors
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
@ -29,6 +29,7 @@ import org.oscim.overlay.OverlayItem.HotspotPlace;
import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layer.SymbolLayer;
import org.oscim.renderer.overlays.BasicOverlay;
import org.oscim.utils.FastMath;
import org.oscim.view.MapView;
import android.content.res.Resources;
@ -62,7 +63,8 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
Item item;
boolean visible;
boolean changes;
int x, y, px, py;
float x, y;
double px, py;
}
/* package */InternalItem mItems;
@ -73,7 +75,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
private int mSize;
// pre-projected points to zoomlevel 20
private static final byte MAX_ZOOM = 20;
private static final byte MAX_ZOOM = 22;
private final double MAX_SCALE;
class ItemOverlay extends BasicOverlay {
@ -97,11 +99,11 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
mUpdate = false;
int z = curPos.zoomLevel;
int diff = MAX_ZOOM - z;
int zoom = curPos.zoomLevel;
float div = FastMath.pow(zoom - MAX_ZOOM);
int mx = (int) (curPos.x * (Tile.SIZE << z));
int my = (int) (curPos.y * (Tile.SIZE << z));
double mx = curPos.x * (Tile.SIZE << zoom);
double my = curPos.y * (Tile.SIZE << zoom);
// limit could be 1 if we update on every position change
float limit = 1.5f;
@ -124,10 +126,8 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
// check changes
for (InternalItem it = mItems; it != null; it = it.next) {
it.x = (it.px >> diff) - mx;
it.y = (it.py >> diff) - my;
//it.x = it.px - mx;
//it.y = it.py - my;
it.x = (float)((it.px * div) - mx);
it.y = (float)((it.py * div) - my);
if (it.x > max || it.x < -max || it.y > max || it.y < -max) {
if (it.visible) {
@ -173,7 +173,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
mMapPosition.copy(curPos);
// items are placed relative to zoomLevel
mMapPosition.scale = 1 << z;
mMapPosition.scale = 1 << zoom;
layers.clear();
@ -186,13 +186,11 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
continue;
}
Item item = it.item; //mInternalItemList.get(i);
int state = 0;
if (mDrawFocusedItem && (mFocusedItem == item))
if (mDrawFocusedItem && (mFocusedItem == it.item))
state = OverlayItem.ITEM_STATE_FOCUSED_MASK;
Drawable marker = item.getDrawable();
Drawable marker = it.item.getDrawable();
if (marker == null)
marker = mDefaultMarker;
@ -206,7 +204,6 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
}
}
// Log.d("...", "changed " + changedVisible + " " + changesInvisible);
mSymbolLayer.prepare();
layers.textureLayers = mSymbolLayer;
newData = true;
@ -279,10 +276,8 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
// pre-project points
MercatorProjection.project(it.item.mGeoPoint, mMapPoint);
it.px = (int) (mMapPoint.x * MAX_SCALE);
it.py = (int) (mMapPoint.y * MAX_SCALE);
// it.px = (int) MercatorProjection.longitudeToPixelX(p.getLongitude(), MAX_ZOOM);
// it.py = (int) MercatorProjection.latitudeToPixelY(p.getLatitude(), MAX_ZOOM);
it.px = (mMapPoint.x * MAX_SCALE);
it.py = (mMapPoint.y * MAX_SCALE);
}
mUpdate = true;
}

View File

@ -124,7 +124,8 @@ public class PathOverlay extends Overlay {
int x, y, prevX, prevY;
int z = curPos.zoomLevel;
int diff = MAX_ZOOM - z;
float div = FastMath.pow(z - MAX_ZOOM);
int mx = (int) (curPos.x * (Tile.SIZE << z));
int my = (int) (curPos.y * (Tile.SIZE << z));
@ -134,8 +135,8 @@ public class PathOverlay extends Overlay {
int flip = 0;
int flipMax = Tile.SIZE << (z - 1);
x = (mPreprojected[j++] >> diff) - mx;
y = (mPreprojected[j++] >> diff) - my;
x = (int)(mPreprojected[j++] * div) - mx;
y = (int)(mPreprojected[j++] * div) - my;
if (x > flipMax) {
x -= (flipMax * 2);
@ -153,8 +154,8 @@ public class PathOverlay extends Overlay {
prevY = y;
for (; j < size; j += 2) {
x = (mPreprojected[j + 0] >> diff) - mx;
y = (mPreprojected[j + 1] >> diff) - my;
x = (int)(mPreprojected[j + 0] * div) - mx;
y = (int)(mPreprojected[j + 1] * div) - my;
int curFlip = 0;
if (x > flipMax) {