Fix 1-3 zoom visibility

This commit is contained in:
vshcherb 2013-10-20 00:19:44 +02:00
parent 1098c84bd4
commit a8b029e91e
4 changed files with 69 additions and 25 deletions

View file

@ -189,13 +189,23 @@ public class RotatedTileBox {
double t = Math.min(Math.min(y1, y2), Math.min(y3, y4)) ;
double b = Math.max(Math.max(y1, y2), Math.max(y3, y4)) ;
tileBounds = new QuadRect((float)l, (float)t,(float) r, (float)b);
float top = (float) MapUtils.getLatitudeFromTile(zoom, tileBounds.top);
float left = (float) MapUtils.getLongitudeFromTile(zoom, tileBounds.left);
float bottom = (float) MapUtils.getLatitudeFromTile(zoom, tileBounds.bottom);
float right = (float) MapUtils.getLongitudeFromTile(zoom, tileBounds.right);
float top = (float) MapUtils.getLatitudeFromTile(zoom, alignTile(tileBounds.top));
float left = (float) MapUtils.getLongitudeFromTile(zoom, alignTile(tileBounds.left));
float bottom = (float) MapUtils.getLatitudeFromTile(zoom, alignTile(tileBounds.bottom));
float right = (float) MapUtils.getLongitudeFromTile(zoom, alignTile(tileBounds.right));
latLonBounds = new QuadRect(left, top, right, bottom);
}
private double alignTile(double tile) {
if(tile < 0) {
return 0;
}
if(tile >= MapUtils.getPowZoom(zoom)) {
return MapUtils.getPowZoom(zoom) - .000001;
}
return tile;
}
public int getPixWidth() {
return pixWidth;
@ -212,6 +222,13 @@ public class RotatedTileBox {
return getPixXFromTile(xTile, yTile);
}
public int getPixXFromTile(double tileX, double tileY, float zoom) {
double pw = MapUtils.getPowZoom(zoom - this.zoom);
float xTile = (float) (tileX / pw);
float yTile = (float) (tileY / pw);
return getPixXFromTile(xTile, yTile);
}
protected int getPixXFromTile(double xTile, double yTile) {
double rotX;
final double dTileX = xTile - oxTile;
@ -232,6 +249,13 @@ public class RotatedTileBox {
return getPixYFromTile(xTile, yTile);
}
public int getPixYFromTile(double tileX, double tileY, float zoom) {
double pw = MapUtils.getPowZoom(zoom - this.zoom);
float xTile = (float) (tileX / pw);
float yTile = (float) (tileY / pw);
return getPixYFromTile(xTile, yTile);
}
protected int getPixYFromTile(float xTile, float yTile) {
final double dTileX = xTile - oxTile;
final double dTileY = yTile - oyTile;
@ -346,21 +370,34 @@ public class RotatedTileBox {
public LatLon getLeftTopLatLon() {
checkTileRectangleCalculated();
return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileLT.y),
MapUtils.getLongitudeFromTile(zoom, tileLT.x));
return new LatLon(MapUtils.getLatitudeFromTile(zoom, alignTile(tileLT.y)),
MapUtils.getLongitudeFromTile(zoom, alignTile(tileLT.x)));
}
public QuadPoint getLeftTopTile(float zoom) {
checkTileRectangleCalculated();
return new QuadPoint((float) (tileLT.x * MapUtils.getPowZoom(zoom - this.zoom)),
(float) (tileLT.y * MapUtils.getPowZoom(zoom - this.zoom)));
}
public QuadPoint getRightBottomTile(float zoom) {
checkTileRectangleCalculated();
return new QuadPoint((float) (tileRB.x * MapUtils.getPowZoom(zoom - this.zoom)),
(float) (tileRB.y * MapUtils.getPowZoom(zoom - this.zoom)));
}
private void checkTileRectangleCalculated() {
if(tileBounds == null){
calculateTileRectangle();;
calculateTileRectangle();
}
}
public LatLon getRightBottomLatLon() {
checkTileRectangleCalculated();
return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileRB.y),
MapUtils.getLongitudeFromTile(zoom, tileRB.x));
return new LatLon(MapUtils.getLatitudeFromTile(zoom, alignTile(tileRB.y)),
MapUtils.getLongitudeFromTile(zoom, alignTile(tileRB.x)));
}
public void setZoom(int zoom, float zoomScale) {

View file

@ -30,6 +30,7 @@ import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
@ -554,13 +555,15 @@ public class MapRenderRepositories {
currentRenderingContext.shadowRenderingMode = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
currentRenderingContext.shadowRenderingColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_SHADOW_COLOR);
}
// final QuadPoint lt = requestedBox.getLeftTopTilePoint();
LatLon lt = requestedBox.getLeftTopLatLon();
final QuadPoint lt = requestedBox.getLeftTopTile(requestedBox.getZoom() +
requestedBox.getZoomScale());
//LatLon lt = requestedBox.getLeftTopLatLon();
final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale());
final float tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom() -
requestedBox.getZoomScale());
currentRenderingContext.leftX = MapUtils.get31TileNumberX(lt.getLongitude()) / tileDivisor;
currentRenderingContext.topY = MapUtils.get31TileNumberY(lt.getLatitude()) / tileDivisor;
currentRenderingContext.leftX = lt.x;
//MapUtils.get31TileNumberX(lt.getLongitude()) / tileDivisor;
currentRenderingContext.topY = lt.y;//MapUtils.get31TileNumberY(lt.getLatitude()) / tileDivisor;
currentRenderingContext.zoom = requestedBox.getZoom();
currentRenderingContext.rotate = requestedBox.getRotate();
currentRenderingContext.width = requestedBox.getPixWidth();

View file

@ -2,6 +2,7 @@ package net.osmand.plus.render;
import android.graphics.*;
import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.views.BaseMapLayer;
@ -103,15 +104,16 @@ public class MapVectorLayer extends BaseMapLayer {
boolean shown = false;
if (bmp != null && bmpLoc != null) {
float rot = - bmpLoc.getRotate();
final LatLon lt = bmpLoc.getLeftTopLatLon();
final LatLon rb = bmpLoc.getRightBottomLatLon();
int cz = currentViewport.getZoom();
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
final RotatedTileBox calc = currentViewport.copy();
calc.setRotate(bmpLoc.getRotate());
final int x1 = calc.getPixXFromLatLon(lt.getLatitude(), lt.getLongitude());
final int x2 = calc.getPixXFromLatLon(rb.getLatitude(), rb.getLongitude());
final int y1 = calc.getPixYFromLatLon(lt.getLatitude(), lt.getLongitude());
final int y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
QuadPoint lt = bmpLoc.getLeftTopTile(cz);
QuadPoint rb = bmpLoc.getRightBottomTile(cz);
final int x1 = calc.getPixXFromTile(lt.x, lt.y, cz);
final int x2 = calc.getPixXFromTile(rb.x, rb.y, cz);
final int y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
final int y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
destImage.set(x1, y1, x2, y2);
if(!bmp.isRecycled()){
canvas.drawBitmap(bmp, null, destImage, paintImg);

View file

@ -389,15 +389,17 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private void drawBasemap(Canvas canvas) {
if(bufferImgLoc != null) {
float rot = - bufferImgLoc.getRotate();
final LatLon lt = bufferImgLoc.getLeftTopLatLon();
final LatLon rb = bufferImgLoc.getRightBottomLatLon();
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
final RotatedTileBox calc = currentViewport.copy();
calc.setRotate(bufferImgLoc.getRotate());
final int x1 = calc.getPixXFromLatLon(lt.getLatitude(), lt.getLongitude());
final int x2 = calc.getPixXFromLatLon(rb.getLatitude(), rb.getLongitude());
final int y1 = calc.getPixYFromLatLon(lt.getLatitude(), lt.getLongitude());
final int y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
int cz = getZoom();
QuadPoint lt = bufferImgLoc.getLeftTopTile(cz);
QuadPoint rb = bufferImgLoc.getRightBottomTile(cz);
final int x1 = calc.getPixXFromTile(lt.x, lt.y, cz);
final int x2 = calc.getPixXFromTile(rb.x, rb.y, cz);
final int y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
final int y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
if(!bufferBitmap.isRecycled()){
canvas.drawBitmap(bufferBitmap, null, new RectF(x1, y1, x2, y2), paintImg);
}