From c90d31486fc476e4a2b6c9e59ba35f51463c3554 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 28 Sep 2013 01:00:10 +0200 Subject: [PATCH] Modify layers --- .../src/net/osmand/data/RotatedTileBox.java | 2 +- OsmAnd/res/values/strings.xml | 1 + .../plus/views/AnimateDraggingMapThread.java | 32 +++++------- .../osmand/plus/views/MapControlsLayer.java | 50 +++++++++++++++++++ .../net/osmand/plus/views/MapTileLayer.java | 2 +- .../osmand/plus/views/OsmandMapTileView.java | 26 +++++----- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java b/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java index 730e7e8f01..554f43dba2 100644 --- a/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java +++ b/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java @@ -415,7 +415,7 @@ public class RotatedTileBox { final double lat1 = getLatFromPixel(pixX, pixY); final double lon1 = getLonFromPixel(pixX, pixY); final double lat2 = getLatFromPixel(pixX2, pixY2); - final double lon2 = getLatFromPixel(pixX2, pixY2); + final double lon2 = getLonFromPixel(pixX2, pixY2); return MapUtils.getDistance(lat1,lon1, lat2, lon2); } diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 082f86a6e7..1413e7cba5 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Map magnifier base world map Map Styles OsmAnd supports displaying the offline vector maps in different map styles to suit your to needs: diff --git a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java index 146ba0f560..50e76bdac8 100644 --- a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java @@ -153,7 +153,7 @@ public class AnimateDraggingMapThread { public void run() { setTargetValues(endZoom, endZoomScale, finalLat, finalLon); if(moveZoom != startZoom){ - animatingZoomInThread(startZoom, moveZoom, ZOOM_MOVE_ANIMATION_TIME, notifyListener); + animatingZoomInThread(startZoom, (int) moveZoom, moveZoom - (int) moveZoom, ZOOM_MOVE_ANIMATION_TIME, notifyListener); } if(!stopped){ @@ -164,7 +164,7 @@ public class AnimateDraggingMapThread { } if (!stopped && moveZoom != endZoom) { - animatingZoomInThread(moveZoom, endZoom + endZoomScale, ZOOM_MOVE_ANIMATION_TIME, notifyListener); + animatingZoomInThread(moveZoom, endZoom, endZoomScale, ZOOM_MOVE_ANIMATION_TIME, notifyListener); } if(!stopped){ tileView.setZoomAnimate(endZoom, endZoomScale, notifyListener); @@ -205,8 +205,9 @@ public class AnimateDraggingMapThread { } - private void animatingZoomInThread(float zoomStart, float zoomEnd, float animationTime, boolean notifyListener){ + private void animatingZoomInThread(float zoomStart, int zoom, float zoomScale, float animationTime, boolean notifyListener){ float curZoom = zoomStart; + float zoomEnd = zoom + zoomScale; animationTime *= Math.abs(zoomEnd - zoomStart); // AccelerateInterpolator interpolator = new AccelerateInterpolator(1); LinearInterpolator interpolator = new LinearInterpolator(); @@ -227,30 +228,21 @@ public class AnimateDraggingMapThread { stopped = true; } } - - if(curZoom != ((int) Math.round(curZoom))){ - if(Math.abs(curZoom - zoomEnd) > 2){ - if(zoomStart > zoomEnd){ - curZoom = (float) Math.floor(curZoom); - } else { - curZoom = (float) Math.ceil(curZoom); - } - tileView.zoomToAnimate(curZoom, notifyListener); - } else { - tileView.zoomToAnimate(zoomEnd, notifyListener); - } - } + tileView.setZoomAnimate(zoom, zoomScale, notifyListener); + } + + public void startZooming(final int zoomEnd, final boolean notifyListener){ + startZooming(zoomEnd, tileView.getZoomScale(), notifyListener); } - - public void startZooming(final int zoomEnd, final boolean notifyListener){ + public void startZooming(final int zoomEnd, final float zoomScale, final boolean notifyListener){ final float animationTime = ZOOM_ANIMATION_TIME; startThreadAnimating(new Runnable(){ @Override public void run() { final float zoomStart = tileView.getZoom() + tileView.getZoomScale(); - setTargetValues(zoomEnd, tileView.getZoomScale(), tileView.getLatitude(), tileView.getLongitude()); - animatingZoomInThread(zoomStart, zoomEnd, animationTime, notifyListener); + setTargetValues(zoomEnd, zoomScale, tileView.getLatitude(), tileView.getLongitude()); + animatingZoomInThread(zoomStart, zoomEnd, zoomScale, animationTime, notifyListener); pendingRotateAnimation(); } }); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 90a0e58f89..49ad0740a0 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -1,5 +1,8 @@ package net.osmand.plus.views; +import android.app.AlertDialog; +import android.content.DialogInterface; +import gnu.trove.list.array.TIntArrayList; import net.londatiga.android.ActionItem; import net.londatiga.android.QuickAction; import net.osmand.data.RotatedTileBox; @@ -31,6 +34,9 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; +import java.util.ArrayList; +import java.util.List; + public class MapControlsLayer extends OsmandMapLayer { private static final int SHOW_ZOOM_LEVEL_MSG_ID = 3; @@ -334,6 +340,50 @@ public class MapControlsLayer extends OsmandMapLayer { } }); + zoomInButton.setOnLongClickListener(new View.OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext()); + float scale = view.getZoomScale(); + int p = (int) Math.round(scale * scale * 100) + 100; + final TIntArrayList tlist = new TIntArrayList(new int[] {100, 150, 200, 300, 400}); + final List values = new ArrayList(); + int i = -1; + for(int k = 0; k <= tlist.size(); k++) { + final boolean end = k == tlist.size(); + if(i == -1) { + if ((end || p < tlist.get(k))) { + values.add(p + "%"); + i = k; + } else if (p == tlist.get(k)) { + i = k; + } + + } + if(k < tlist.size()) { + values.add(tlist.get(k) + "%"); + } + } + if(values.size() != tlist.size() ) { + tlist.insert(i, p); + } + + bld.setTitle(R.string.map_magnifier); + bld.setSingleChoiceItems(values.toArray(new String[values.size()]), + i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + float newScale = (float) Math.sqrt((tlist.get(which) - 100f)/ 100f); + view.getAnimatedDraggingThread().startZooming(view.getZoom(), newScale, false); + dialog.dismiss(); + + } + }); + bld.show(); + return true; + } + }); zoomOutButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java index 7eceecef79..f38ad9d895 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java @@ -157,7 +157,7 @@ public class MapTileLayer extends BaseMapLayer { int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI); int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1); int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ); - int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ); + int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1); // TODO elliptic // float y1 = (top + j - tileY) * ftileSize + h; String ordImgTile = mgr.calculateTileId(map, leftPlusI, topPlusJ, nzoom); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 8ba230daf7..c2bf17af99 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -170,7 +170,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall dm = new DisplayMetrics(); mgr.getDefaultDisplay().getMetrics(dm); currentViewport = new RotatedTileBox.RotatedTileBoxBuilder(). - setLocation(0, 0).setZoomAndScale(3, 1).setPixelDimensions(getWidth(), getHeight()).build(); + setLocation(0, 0).setZoomAndScale(3, 0).setPixelDimensions(getWidth(), getHeight()).build(); currentViewport.setDensity(dm.density); } @@ -249,7 +249,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall public void setIntZoom(int zoom) { if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) { animatedDraggingThread.stopAnimating(); - currentViewport.setZoom(zoom, currentViewport.getZoomScale()); + currentViewport.setZoom(zoom, currentViewport.getZoomScale(), 0); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 ); refreshMap(); } @@ -457,10 +457,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall return handler.hasMessages(1); } - public boolean mapIsAnimating() { - return animatedDraggingThread != null && animatedDraggingThread.isAnimating(); - } - // this method could be called in non UI thread public void refreshMap() { refreshMap(false); @@ -555,7 +551,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall zoomToAnimate -= (int) zoomToAnimate; } while (zoomToAnimate < 0) { - zoom++; + zoom--; zoomToAnimate += 1; } if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) { @@ -645,9 +641,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public void onZoomEnded(float distance, float relativeToStart) { - float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5); - float calcZoom = initialViewport.getZoom() + dz; - changeZoomPosition(dz); + float dz = (float) (Math.log(relativeToStart) / Math.log(2)); //* 1.5); + final int rz = Math.round(dz); + setIntZoom(rz + initialViewport.getZoom()); + final int newZoom = getZoom(); if (application.getInternalAPI().accessibilityEnabled()) { if (newZoom != initialViewport.getZoom()) { @@ -678,7 +675,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public void onZooming(float distance, float relativeToStart) { - float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5); + float dz = (float) (Math.log(relativeToStart) / Math.log(2)); // * 1.5); if (Math.abs(dz) > 0.05) { changeZoomPosition(dz); } @@ -687,13 +684,14 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private void changeZoomPosition(float dz) { float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale(); final QuadPoint cp = initialViewport.getCenterPixelPoint(); - float dx = initialMultiTouchCenterPoint.x - cp.x; - float dy = initialMultiTouchCenterPoint.y - cp.y; + float dx = cp.x - initialMultiTouchCenterPoint.x ; + float dy = cp.y - initialMultiTouchCenterPoint.y ; final RotatedTileBox calc = initialViewport.copy(); calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude()); + calc.setZoom(initialViewport.getZoom(), dz + initialViewport.getZoomScale()); final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy); - zoomToAnimate(calcZoom, true); setLatLon(r.getLatitude(), r.getLongitude()); + zoomToAnimate(calcZoom, true); } }