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