Fix zoom scale for high density phones (glitch 200-300%)
This commit is contained in:
parent
85a64d0d65
commit
b6273d00c1
15 changed files with 57 additions and 59 deletions
|
@ -9,8 +9,8 @@ public class RotatedTileBox {
|
|||
private float rotate;
|
||||
private float density;
|
||||
private int zoom;
|
||||
private float zoomScale;
|
||||
private float zoomAnimation;
|
||||
private double zoomScale;
|
||||
private double zoomAnimation;
|
||||
private int cx;
|
||||
private int cy;
|
||||
private int pixWidth;
|
||||
|
@ -67,7 +67,7 @@ public class RotatedTileBox {
|
|||
}
|
||||
|
||||
public void calculateDerivedFields() {
|
||||
zoomFactor = Math.pow(2, zoomScale + zoomAnimation) * 256;
|
||||
zoomFactor = Math.pow(2, zoomScale + zoomAnimation ) * 256;
|
||||
double rad = Math.toRadians(this.rotate);
|
||||
rotateCos = Math.cos(rad);
|
||||
rotateSin = Math.sin(rad);
|
||||
|
@ -330,16 +330,16 @@ public class RotatedTileBox {
|
|||
return zoomAnimation != 0;
|
||||
}
|
||||
|
||||
public float getZoomAnimation() {
|
||||
public double getZoomAnimation() {
|
||||
return zoomAnimation;
|
||||
}
|
||||
|
||||
public void setZoomAnimation(float z) {
|
||||
public void setZoomAnimation(double z) {
|
||||
this.zoomAnimation = z;
|
||||
calculateDerivedFields();
|
||||
}
|
||||
|
||||
public void setZoomAndAnimation(int zoom, float zoomAnimation) {
|
||||
public void setZoomAndAnimation(int zoom, double zoomAnimation) {
|
||||
this.zoomAnimation = zoomAnimation;
|
||||
this.zoom = zoom;
|
||||
calculateDerivedFields();
|
||||
|
@ -358,12 +358,13 @@ public class RotatedTileBox {
|
|||
|
||||
}
|
||||
|
||||
public QuadPointDouble getLeftTopTile(float zoom) {
|
||||
public QuadPointDouble getLeftTopTile(double zoom) {
|
||||
checkTileRectangleCalculated();
|
||||
return new QuadPointDouble((tileLT.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
||||
(tileLT.y * MapUtils.getPowZoom(zoom - this.zoom)));
|
||||
}
|
||||
|
||||
|
||||
public QuadPointDouble getRightBottomTile(float zoom) {
|
||||
checkTileRectangleCalculated();
|
||||
return new QuadPointDouble((tileRB.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
||||
|
@ -383,7 +384,7 @@ public class RotatedTileBox {
|
|||
MapUtils.getLongitudeFromTile(zoom, alignTile(tileRB.x)));
|
||||
}
|
||||
|
||||
public void setZoom(int zoom, float zoomScale) {
|
||||
public void setZoom(int zoom, double zoomScale) {
|
||||
this.zoom = zoom;
|
||||
this.zoomScale = zoomScale;
|
||||
calculateDerivedFields();
|
||||
|
@ -394,14 +395,14 @@ public class RotatedTileBox {
|
|||
calculateDerivedFields();
|
||||
}
|
||||
|
||||
public void setZoom(int zoom, float zoomScale, float zoomToAnimate) {
|
||||
public void setZoom(int zoom, double zoomScale, double zoomToAnimate) {
|
||||
this.zoom = zoom;
|
||||
this.zoomScale = zoomScale;
|
||||
this.zoomAnimation = zoomToAnimate;
|
||||
calculateDerivedFields();
|
||||
}
|
||||
|
||||
public float getZoomScale() {
|
||||
public double getZoomScale() {
|
||||
return zoomScale;
|
||||
}
|
||||
|
||||
|
@ -490,7 +491,7 @@ public class RotatedTileBox {
|
|||
return this;
|
||||
}
|
||||
|
||||
public RotatedTileBoxBuilder setZoomAndScale(int zoom, float scale) {
|
||||
public RotatedTileBoxBuilder setZoomAndScale(int zoom, double scale) {
|
||||
tb.zoom = zoom;
|
||||
tb.zoomScale = scale;
|
||||
zoomSet = true;
|
||||
|
|
|
@ -226,11 +226,11 @@ public class MapUtils {
|
|||
return getDistance(ll, ll2) ;
|
||||
}
|
||||
|
||||
public static double getLongitudeFromTile(float zoom, double x) {
|
||||
public static double getLongitudeFromTile(double zoom, double x) {
|
||||
return x / getPowZoom(zoom) * 360.0 - 180.0;
|
||||
}
|
||||
|
||||
public static double getPowZoom(float zoom){
|
||||
public static double getPowZoom(double zoom){
|
||||
if(zoom >= 0 && zoom - Math.floor(zoom) < 0.001f){
|
||||
return 1 << ((int)zoom);
|
||||
} else {
|
||||
|
|
|
@ -198,12 +198,12 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
}
|
||||
if (now - lastTimeAutoZooming > 4500) {
|
||||
lastTimeAutoZooming = now;
|
||||
float settingsZoomScale = mapView.getSettingsZoomScale();
|
||||
float complexZoom = tb.getZoom() + tb.getZoomScale() + zdelta;
|
||||
double settingsZoomScale = mapView.getSettingsZoomScale();
|
||||
double complexZoom = tb.getZoom() + tb.getZoomScale() + zdelta;
|
||||
// round to 0.33
|
||||
float newZoom = Math.round((complexZoom - settingsZoomScale) * 3) / 3f;
|
||||
double newZoom = Math.round((complexZoom - settingsZoomScale) * 3) / 3f;
|
||||
int nz = (int)Math.round(newZoom);
|
||||
float nzscale = newZoom - nz + settingsZoomScale;
|
||||
double nzscale = newZoom - nz + settingsZoomScale;
|
||||
mapView.setComplexZoom(nz, nzscale);
|
||||
// mapView.getAnimatedDraggingThread().startZooming(mapView.getFloatZoom() + zdelta, false);
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
|
||||
public int getRadiusBug(RotatedTileBox tb) {
|
||||
int z;
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
if (zoom < startZoom) {
|
||||
z = 0;
|
||||
} else if (zoom <= 12) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
|
||||
public int getRadiusPoi(RotatedTileBox tb){
|
||||
int r = 0;
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
if(zoom < startZoom){
|
||||
r = 0;
|
||||
} else if(zoom <= 11){
|
||||
|
|
|
@ -22,19 +22,19 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.NativeLibrary.NativeSearchResult;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader.MapIndex;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.QuadPointDouble;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
|
@ -611,8 +611,6 @@ public class MapRenderRepositories {
|
|||
|
||||
// prevent editing
|
||||
requestedBox = new RotatedTileBox(tileRect);
|
||||
|
||||
|
||||
// calculate data box
|
||||
QuadRect dataBox = requestedBox.getLatLonBounds();
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -660,21 +658,20 @@ public class MapRenderRepositories {
|
|||
if(renderingReq.searchRenderingAttribute("polygonMinSizeToDisplay")) {
|
||||
currentRenderingContext.polygonMinSizeToDisplay = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
|
||||
}
|
||||
final QuadPointDouble lt = requestedBox.getLeftTopTile(requestedBox.getZoom());
|
||||
final QuadPointDouble lt = requestedBox.getLeftTopTile(requestedBox.getZoom() + requestedBox.getZoomScale());
|
||||
// LatLon ltn = requestedBox.getLeftTopLatLon();
|
||||
final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale());
|
||||
final double tileDivisor = MapUtils.getPowZoom(31 - requestedBox.getZoom() -
|
||||
requestedBox.getZoomScale());
|
||||
currentRenderingContext.leftX = lt.x * MapUtils.getPowZoom(requestedBox.getZoomScale());
|
||||
// MapUtils.get31TileNumberX(ltn.getLongitude()) / tileDivisor;
|
||||
currentRenderingContext.topY = lt.y * MapUtils.getPowZoom(requestedBox.getZoomScale());
|
||||
//MapUtils.get31TileNumberY(ltn.getLatitude()) / tileDivisor;
|
||||
|
||||
currentRenderingContext.leftX = lt.x;
|
||||
currentRenderingContext.topY = lt.y;
|
||||
currentRenderingContext.zoom = requestedBox.getZoom();
|
||||
currentRenderingContext.rotate = requestedBox.getRotate();
|
||||
currentRenderingContext.width = requestedBox.getPixWidth();
|
||||
currentRenderingContext.height = requestedBox.getPixHeight();
|
||||
currentRenderingContext.nightMode = nightMode;
|
||||
currentRenderingContext.preferredLocale = prefs.MAP_PREFERRED_LOCALE.get();
|
||||
final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale());
|
||||
currentRenderingContext.setDensityValue(mapDensity);
|
||||
//Text/icon scales according to mapDensity (so text is size of road)
|
||||
// currentRenderingContext.textScale = (requestedBox.getDensity()*app.getSettings().TEXT_SCALE.get());
|
||||
|
|
|
@ -547,10 +547,10 @@ public class OsmandRenderer {
|
|||
rc.pointCount ++;
|
||||
double tx = xt / rc.tileDivisor;
|
||||
double ty = yt / rc.tileDivisor;
|
||||
float dTileX = (float) (tx - rc.leftX);
|
||||
float dTileY = (float) (ty - rc.topY);
|
||||
float x = rc.cosRotateTileSize * dTileX - rc.sinRotateTileSize * dTileY;
|
||||
float y = rc.sinRotateTileSize * dTileX + rc.cosRotateTileSize * dTileY;
|
||||
double dTileX = (tx - rc.leftX);
|
||||
double dTileY = (ty - rc.topY);
|
||||
float x = (float) (rc.cosRotateTileSize * dTileX - rc.sinRotateTileSize * dTileY);
|
||||
float y = (float) (rc.sinRotateTileSize * dTileX + rc.cosRotateTileSize * dTileY);
|
||||
rc.tempPoint.set(x, y);
|
||||
if(rc.tempPoint.x >= 0 && rc.tempPoint.x < rc.width &&
|
||||
rc.tempPoint.y >= 0 && rc.tempPoint.y < rc.height){
|
||||
|
|
|
@ -34,7 +34,7 @@ public class AnimateDraggingMapThread {
|
|||
private double targetLatitude = 0;
|
||||
private double targetLongitude = 0;
|
||||
private int targetIntZoom = 0;
|
||||
private float targetZoomScale = 0;
|
||||
private double targetZoomScale = 0;
|
||||
|
||||
private boolean isAnimatingZoom;
|
||||
|
||||
|
@ -118,14 +118,14 @@ public class AnimateDraggingMapThread {
|
|||
startMoving(finalLat, finalLon, endZoom, tileView.getZoomScale(), notifyListener);
|
||||
}
|
||||
|
||||
public void startMoving(final double finalLat, final double finalLon, final int endZoom, final float endZoomScale, final boolean notifyListener){
|
||||
public void startMoving(final double finalLat, final double finalLon, final int endZoom, final double endZoomScale, final boolean notifyListener){
|
||||
stopAnimatingSync();
|
||||
double startLat = tileView.getLatitude();
|
||||
double startLon = tileView.getLongitude();
|
||||
float rotate = tileView.getRotate();
|
||||
final int startZoom = tileView.getZoom();
|
||||
final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy();
|
||||
final float zoomScale = rb.getZoomScale();
|
||||
final double zoomScale = rb.getZoomScale();
|
||||
boolean skipAnimation = false;
|
||||
float mStX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
|
||||
float mStY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
|
||||
|
@ -208,11 +208,11 @@ public class AnimateDraggingMapThread {
|
|||
|
||||
}
|
||||
|
||||
private void animatingZoomInThread(float zoomStart, int zoom, float zoomScale, float animationTime, boolean notifyListener){
|
||||
private void animatingZoomInThread(double zoomStart, int zoom, double zoomScale, float animationTime, boolean notifyListener){
|
||||
try {
|
||||
isAnimatingZoom = true;
|
||||
float curZoom = zoomStart;
|
||||
float zoomEnd = zoom + zoomScale;
|
||||
double curZoom = zoomStart;
|
||||
double zoomEnd = (zoom + zoomScale);
|
||||
animationTime *= Math.abs(zoomEnd - zoomStart);
|
||||
// AccelerateInterpolator interpolator = new AccelerateInterpolator(1);
|
||||
LinearInterpolator interpolator = new LinearInterpolator();
|
||||
|
@ -247,12 +247,12 @@ public class AnimateDraggingMapThread {
|
|||
startZooming(zoomEnd, tileView.getZoomScale(), notifyListener);
|
||||
}
|
||||
|
||||
public void startZooming(final int zoomEnd, final float zoomScale, final boolean notifyListener){
|
||||
public void startZooming(final int zoomEnd, final double zoomScale, final boolean notifyListener){
|
||||
final float animationTime = ZOOM_ANIMATION_TIME;
|
||||
startThreadAnimating(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
final float zoomStart = tileView.getZoom() + tileView.getZoomScale();
|
||||
final double zoomStart = tileView.getZoom() + tileView.getZoomScale();
|
||||
setTargetValues(zoomEnd, zoomScale, tileView.getLatitude(), tileView.getLongitude());
|
||||
animatingZoomInThread(zoomStart, zoomEnd, zoomScale, animationTime, notifyListener);
|
||||
pendingRotateAnimation();
|
||||
|
@ -305,7 +305,7 @@ public class AnimateDraggingMapThread {
|
|||
targetZoomScale = 0;
|
||||
}
|
||||
|
||||
private void setTargetValues(int zoom, float zoomScale, double lat, double lon){
|
||||
private void setTargetValues(int zoom, double zoomScale, double lat, double lon){
|
||||
targetIntZoom = zoom;
|
||||
targetZoomScale = zoomScale;
|
||||
targetLatitude = lat;
|
||||
|
@ -335,7 +335,7 @@ public class AnimateDraggingMapThread {
|
|||
return targetIntZoom;
|
||||
}
|
||||
|
||||
public float getTargetZoomScale() {
|
||||
public double getTargetZoomScale() {
|
||||
return targetZoomScale;
|
||||
}
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
}
|
||||
|
||||
public void setComplexZoom(int zoom, float scale) {
|
||||
public void setComplexZoom(int zoom, double scale) {
|
||||
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
|
||||
animatedDraggingThread.stopAnimating();
|
||||
currentViewport.setZoom(zoom, scale, 0);
|
||||
|
@ -361,11 +361,11 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
return currentViewport.getZoom();
|
||||
}
|
||||
|
||||
public float getSettingsZoomScale() {
|
||||
return getSettings().getSettingsZoomScale() + (float)Math.sqrt(Math.max(0, getDensity() - 1));
|
||||
public double getSettingsZoomScale() {
|
||||
return getSettings().getSettingsZoomScale() + Math.sqrt(Math.max(0, getDensity() - 1));
|
||||
}
|
||||
|
||||
public float getZoomScale() {
|
||||
public double getZoomScale() {
|
||||
return currentViewport.getZoomScale();
|
||||
}
|
||||
|
||||
|
@ -678,7 +678,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
}
|
||||
|
||||
protected void setZoomAnimate(int zoom, float zoomScale, boolean notify) {
|
||||
protected void setZoomAnimate(int zoom, double zoomScale, boolean notify) {
|
||||
currentViewport.setZoom(zoom, zoomScale, 0);
|
||||
refreshMap();
|
||||
if (locationListener != null && notify) {
|
||||
|
@ -687,9 +687,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
|
||||
// for internal usage
|
||||
protected void zoomToAnimate(float tzoom, boolean notify) {
|
||||
protected void zoomToAnimate(double tzoom, boolean notify) {
|
||||
int zoom = getZoom();
|
||||
float zoomToAnimate = tzoom - zoom - getZoomScale();
|
||||
double zoomToAnimate = tzoom - zoom - getZoomScale();
|
||||
if (zoomToAnimate >= 1) {
|
||||
zoom += (int) zoomToAnimate;
|
||||
zoomToAnimate -= (int) zoomToAnimate;
|
||||
|
@ -852,13 +852,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
final RotatedTileBox calc = initialViewport.copy();
|
||||
calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude());
|
||||
|
||||
float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
|
||||
double calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
|
||||
float calcRotate = calc.getRotate() + angle;
|
||||
calc.setRotate(calcRotate);
|
||||
calc.setZoomAnimation(dz);
|
||||
final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
|
||||
setLatLon(r.getLatitude(), r.getLongitude());
|
||||
zoomToAnimate(calcZoom, true);
|
||||
zoomToAnimate((float) calcZoom, true);
|
||||
rotateToAnimate(calcRotate);
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
|
||||
public int getRadiusPoi(RotatedTileBox tb) {
|
||||
int r = 0;
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
if (zoom < startZoom) {
|
||||
r = 0;
|
||||
} else if (zoom <= 15) {
|
||||
|
|
|
@ -177,7 +177,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
|
|||
|
||||
public int getRadiusPoi(RotatedTileBox tb){
|
||||
int r = 0;
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
if(zoom <= 15){
|
||||
r = 10;
|
||||
} else if(zoom <= 16){
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TransportInfoLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
public int getRadius(RotatedTileBox tb){
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
if(zoom <= 16) {
|
||||
return (int) (tb.getDensity() * 8);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
}
|
||||
|
||||
public int getRadiusPoi(RotatedTileBox tb){
|
||||
final float zoom = tb.getZoom() + tb.getZoomScale();
|
||||
final double zoom = tb.getZoom() + tb.getZoomScale();
|
||||
int r;
|
||||
if(zoom < startZoom){
|
||||
r = 0;
|
||||
|
|
|
@ -124,7 +124,7 @@ public class MapZoomControls extends MapControls {
|
|||
zoomShadow.draw(canvas);
|
||||
if (drawZoomLevel) {
|
||||
String zoomText = tb.getZoom() + "";
|
||||
float frac = tb.getZoomScale();
|
||||
double frac = tb.getZoomScale();
|
||||
if (frac != 0) {
|
||||
int ifrac = (int) (frac * 10);
|
||||
boolean pos = ifrac > 0;
|
||||
|
|
|
@ -17,7 +17,7 @@ import android.widget.FrameLayout;
|
|||
public class RulerControl extends MapControls {
|
||||
|
||||
ShadowText cacheRulerText = null;
|
||||
float cacheRulerZoom = 0;
|
||||
double cacheRulerZoom = 0;
|
||||
double cacheRulerTileX = 0;
|
||||
double cacheRulerTileY = 0;
|
||||
float cacheRulerTextLen = 0;
|
||||
|
|
Loading…
Reference in a new issue