From 056289d03baa8ecbd61ef6ccba2a9b0f5393a551 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Thu, 18 Apr 2013 18:14:09 +0200 Subject: [PATCH] fix precision issue on high zoom-levels --- src/org/oscim/overlay/ItemizedOverlay.java | 37 ++++++++++------------ src/org/oscim/overlay/PathOverlay.java | 11 ++++--- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/org/oscim/overlay/ItemizedOverlay.java b/src/org/oscim/overlay/ItemizedOverlay.java index e4f7f70e..57988538 100644 --- a/src/org/oscim/overlay/ItemizedOverlay.java +++ b/src/org/oscim/overlay/ItemizedOverlay.java @@ -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 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 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 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 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 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 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 extends Overlay } } - // Log.d("...", "changed " + changedVisible + " " + changesInvisible); mSymbolLayer.prepare(); layers.textureLayers = mSymbolLayer; newData = true; @@ -279,10 +276,8 @@ public abstract class ItemizedOverlay 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; } diff --git a/src/org/oscim/overlay/PathOverlay.java b/src/org/oscim/overlay/PathOverlay.java index 855f1280..d2049205 100644 --- a/src/org/oscim/overlay/PathOverlay.java +++ b/src/org/oscim/overlay/PathOverlay.java @@ -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) {