Fix rotation, fix yandex traffic layer

This commit is contained in:
Victor Shcherb 2011-05-28 11:27:03 +02:00
parent 0b68af3e7d
commit f83597ef13
7 changed files with 76 additions and 24 deletions

View file

@ -206,7 +206,7 @@ public class MapUtils {
final double M2 = (double) Math.log((1 + Math.sin(E2))
/ (1 - Math.sin(E2)))/ 2- J2 * Math.log((1 + J2 * Math.sin(E2))/ (1 - J2 * Math.sin(E2))) / 2;
final double B2 = getPowZoom(zoom);
return Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI);
return B2 / 2 - M2 * B2 / 2 / Math.PI;
}
public static double getLatitudeFromEllipsoidTileY(float zoom, float tileNumberY){
@ -344,6 +344,41 @@ public class MapUtils {
}
return c;
}
/**
* Calculate rotation diff D, that R (rotate) + D = T (targetRotate)
* D is between -180, 180
* @param rotate
* @param targetRotate
* @return
*/
public static float unifyRotationDiff(float rotate, float targetRotate) {
float d = targetRotate - rotate;
while(d >= 180){
d -= 360;
}
while(d < -180){
d += 360;
}
return d;
}
/**
* Calculate rotation diff D, that R (rotate) + D = T (targetRotate)
* D is between -180, 180
* @param rotate
* @param targetRotate
* @return
*/
public static float unifyRotationTo360(float rotate) {
while(rotate < 0){
rotate += 360;
}
while(rotate > 360){
rotate -= 360;
}
return rotate;
}
}

View file

@ -45,12 +45,7 @@ public class AnimateDraggingMapThread {
boolean conditionToCountinue = true;
while (conditionToCountinue && !stopped) {
conditionToCountinue = false;
float rotationDiff = targetRotate - tileView.getRotate();
if (Math.abs((rotationDiff + 360) % 360) < Math.abs((rotationDiff - 360) % 360)) {
rotationDiff = (rotationDiff + 360) % 360;
} else {
rotationDiff = (rotationDiff - 360) % 360;
}
float rotationDiff = MapUtils.unifyRotationDiff(tileView.getRotate(), targetRotate);
float absDiff = Math.abs(rotationDiff);
if (absDiff > 0) {
Thread.sleep(DEFAULT_SLEEP_TO_REDRAW);
@ -58,7 +53,7 @@ public class AnimateDraggingMapThread {
tileView.rotateToAnimate(targetRotate);
} else {
conditionToCountinue = true;
tileView.rotateToAnimate(((absDiff / 10) * Math.signum(rotationDiff) + tileView.getRotate()) % 360);
tileView.rotateToAnimate(rotationDiff / 5 + tileView.getRotate());
}
}
}

View file

@ -63,10 +63,18 @@ public class MapTileLayer extends BaseMapLayer {
ResourceManager mgr = resourceManager;
int nzoom = view.getZoom();
float tileX = view.getXTile();
float tileY = map.isEllipticYTile() ? view.getEllipticYTile() : view.getYTile();
float tileY = view.getYTile();
float w = view.getCenterPointX();
float h = view.getCenterPointY();
float ftileSize = view.getTileSize();
// recalculate for ellipsoid coordinates
if (map.isEllipticYTile()) {
float ellipticYTile = view.getEllipticYTile();
tilesRect.bottom += (ellipticYTile - tileY);
tilesRect.top += (ellipticYTile - tileY);
tileY = ellipticYTile;
}
int left = (int) FloatMath.floor(tilesRect.left);
int top = (int) FloatMath.floor(tilesRect.top);
@ -80,15 +88,18 @@ public class MapTileLayer extends BaseMapLayer {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int leftPlusI = (int) FloatMath.floor((float) MapUtils
.getTileNumberX(nzoom, MapUtils.getLongitudeFromTile(nzoom, left + i)));
float topTileY;
if(map.isEllipticYTile()){
topTileY = (float) MapUtils.getTileEllipsoidNumberY(nzoom, MapUtils.getLatitudeFromTile(nzoom, top + j));
} else {
topTileY = (float) MapUtils.getTileNumberY(nzoom, MapUtils.getLatitudeFromTile(nzoom, top + j));
}
int topPlusJ = (int) FloatMath.floor(topTileY);
// int leftPlusI = (int) FloatMath.floor((float) MapUtils
// .getTileNumberX(nzoom, MapUtils.getLongitudeFromTile(nzoom, left + i)));
// float topTileY;
// if(map.isEllipticYTile()){
// topTileY = (float) MapUtils.getTileEllipsoidNumberY(nzoom, MapUtils.getLatitudeFromEllipsoidTileY(nzoom, top + j));
// } else {
// topTileY = (float) MapUtils.getTileNumberY(nzoom, MapUtils.getLatitudeFromTile(nzoom, top + j));
// }
// int topPlusJ = (int) FloatMath.floor(topTileY);
int leftPlusI = left + i;
int topPlusJ = top + j;
float x1 = (left + i - tileX) * ftileSize + w;
float y1 = (top + j - tileY) * ftileSize + h;
String ordImgTile = mgr.calculateTileId(map, leftPlusI, topPlusJ, nzoom);

View file

@ -265,8 +265,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
public void setRotate(float rotate) {
float diff = rotate-this.rotate;
if (Math.min(Math.abs((diff + 360) % 360), Math.abs((diff - 360) % 360)) > 5) { // check smallest rotation
float diff = MapUtils.unifyRotationDiff(rotate, this.rotate);
if (Math.abs(diff) > 5) { // check smallest rotation
animatedDraggingThread.startRotate(rotate);
}
}
@ -601,7 +601,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
}
protected void rotateToAnimate(float rotate) {
this.rotate = rotate;
this.rotate = MapUtils.unifyRotationTo360(rotate);
float rotateRad = (float) Math.toRadians(rotate);
this.rotateCos = FloatMath.cos(rotateRad);
this.rotateSin = FloatMath.sin(rotateRad);

View file

@ -21,12 +21,12 @@ import android.widget.Toast;
public class YandexTrafficLayer extends MapTileLayer {
private final static Log log = LogUtil.getLog(MapTileLayer.class);
private final static String YANDEX_PREFFIX = ".YandexTraffic_";
private static final long DELTA = 10 * 60 * 1000;
private long lastTimestampUpdated;
private String mTimestamp = null;
private final static Log log = LogUtil.getLog(MapTileLayer.class);
private final static String YANDEX_PREFFIX = ".YandexTraffic_";
private boolean updateThreadRan = false;
public void setVisible(boolean visible) {
@ -88,7 +88,8 @@ public class YandexTrafficLayer extends MapTileLayer {
if (!newTimestamp.equals(mTimestamp)) {
mTimestamp = newTimestamp;
TileSourceTemplate template = new TileSourceTemplate(YANDEX_PREFFIX + mTimestamp,
"http://jgo.maps.yandex.net/tiles?l=trf&x={1}&y={2}&z={3}&tm" + mTimestamp, ".png", 17, 7, 256, 8, 18000);
"http://jgo.maps.yandex.net/tiles?l=trf&x={1}&y={2}&z={0}&tm=" + mTimestamp, ".png", 17, 7, 256, 8, 18000);
template.setEllipticYTile(true);
clearCache();
this.map = template;
}

View file

@ -0,0 +1,6 @@
<?php
header('Content-type: application/xml');
header('Content-Disposition: attachment; filename="tile_sources.xml"');
readfile('tile_sources.xml');
?>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<tile_sources>
<tile_source />
</tile_sources>