From 7b13667d5784589b12cf9222693a9cfc3b748529 Mon Sep 17 00:00:00 2001 From: "pavol.zibrita" Date: Sat, 15 Jan 2011 21:05:31 +0000 Subject: [PATCH] Reintegrating v0.5.1 branch to trunk git-svn-id: https://osmand.googlecode.com/svn/trunk@895 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- DataExtractionOSM/src/messages.properties | 2 ++ .../src/net/osmand/osm/MapUtils.java | 11 ++++-- OsmAnd/AndroidManifest.xml | 2 +- OsmAnd/src/net/osmand/ResourceManager.java | 3 ++ .../activities/DownloadIndexActivity.java | 2 +- .../net/osmand/activities/RouteProvider.java | 2 +- .../osmand/render/MapRenderRepositories.java | 8 +++++ .../net/osmand/views/OsmandMapTileView.java | 34 ++++++++++--------- 8 files changed, 43 insertions(+), 21 deletions(-) diff --git a/DataExtractionOSM/src/messages.properties b/DataExtractionOSM/src/messages.properties index 55d34c45e1..6ce904d50a 100644 --- a/DataExtractionOSM/src/messages.properties +++ b/DataExtractionOSM/src/messages.properties @@ -76,3 +76,5 @@ poi_filter_namefinder = Online NameFinder reading_cached_tiles = Reading cached tiles... version_index_is_not_supported = The version of index ''{0}'' is not supported + +version_index_is_big_for_memory = The index ''{0}'' did not fit into memory diff --git a/DataExtractionOSM/src/net/osmand/osm/MapUtils.java b/DataExtractionOSM/src/net/osmand/osm/MapUtils.java index da63b8e440..1a5fc4ee54 100644 --- a/DataExtractionOSM/src/net/osmand/osm/MapUtils.java +++ b/DataExtractionOSM/src/net/osmand/osm/MapUtils.java @@ -176,7 +176,12 @@ public class MapUtils { public static double getTileNumberY(float zoom, double latitude){ latitude = checkLatitude(latitude); double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) ); - return (1 - eval / Math.PI) / 2 * getPowZoom(zoom); + if (Double.isInfinite(eval) || Double.isNaN(eval)) { + latitude = latitude < 0 ? - 89.9 : 89.9; + eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) ); + } + double result = (1 - eval / Math.PI) / 2 * getPowZoom(zoom); + return result; } public static double getTileEllipsoidNumberY(float zoom, double latitude){ @@ -241,7 +246,9 @@ public class MapUtils { } public static double getLatitudeFromTile(float zoom, double y){ - return Math.atan(Math.sinh(Math.PI * (1 - 2 * y / getPowZoom(zoom)))) * 180d / Math.PI; + int sign = y < 0 ? -1 : 1; + double result = Math.atan(sign*Math.sinh(Math.PI * (1 - 2 * y / getPowZoom(zoom)))) * 180d / Math.PI; + return result; } public static int getLengthXFromMeters(float zoom, double latitude, double longitude, double meters, float tileSize, int widthOfDisplay) { diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index f87fabdac1..124b471b29 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -11,7 +11,7 @@ - + diff --git a/OsmAnd/src/net/osmand/ResourceManager.java b/OsmAnd/src/net/osmand/ResourceManager.java index 21dae59811..077153d8eb 100644 --- a/OsmAnd/src/net/osmand/ResourceManager.java +++ b/OsmAnd/src/net/osmand/ResourceManager.java @@ -422,6 +422,9 @@ public class ResourceManager { } catch (SQLiteException e) { log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$ warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ + } catch (OutOfMemoryError oome) { + log.error("Exception reading " + f.getAbsolutePath(), oome); //$NON-NLS-1$ + warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_big_for_memory"), f.getName())); } } else if(f.getName().endsWith(".map.odb")){ //$NON-NLS-1$ warnings.add(MessageFormat.format(Messages.getMessage("old_map_index_is_not_supported"), f.getName())); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java index 90343157e5..1bbb9b5c8b 100644 --- a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java @@ -719,7 +719,7 @@ public class DownloadIndexActivity extends ListActivity { } else if (toIndex.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)) { manager.indexingTransport(progress, warnings, toIndex); } else if (toIndex.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { - manager.indexingMaps(progress); + warnings.addAll(manager.indexingMaps(progress)); } else if (toIndex.getName().endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { } if(dateModified != null){ diff --git a/OsmAnd/src/net/osmand/activities/RouteProvider.java b/OsmAnd/src/net/osmand/activities/RouteProvider.java index ce7795c5ff..061f500466 100644 --- a/OsmAnd/src/net/osmand/activities/RouteProvider.java +++ b/OsmAnd/src/net/osmand/activities/RouteProvider.java @@ -198,7 +198,7 @@ public class RouteProvider { l.setLatitude(end.getLatitude()); l.setLongitude(end.getLongitude()); minDist = Integer.MAX_VALUE; - for (int i = 0; i < gpxRoute.size(); i++) { + for (int i = startI; i < gpxRoute.size(); i++) { float d = gpxRoute.get(i).distanceTo(l); if (d < minDist) { endI = i + 1; diff --git a/OsmAnd/src/net/osmand/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/render/MapRenderRepositories.java index 29c11b5773..7f92b847c3 100644 --- a/OsmAnd/src/net/osmand/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/render/MapRenderRepositories.java @@ -110,6 +110,14 @@ public class MapRenderRepositories { } } return null; + } catch (OutOfMemoryError oome) { + if(raf != null){ + try { + raf.close(); + } catch (IOException e1) { + } + } + throw oome; } if (log.isDebugEnabled()) { log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ diff --git a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java index c551ccc96f..30050a33b4 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java @@ -28,23 +28,23 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; -import android.graphics.Paint.Style; import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.FloatMath; import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.WindowManager; import android.view.GestureDetector.OnDoubleTapListener; import android.view.GestureDetector.OnGestureListener; +import android.view.MotionEvent; +import android.view.SurfaceHolder; import android.view.SurfaceHolder.Callback; +import android.view.SurfaceView; +import android.view.WindowManager; public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback, AnimateDraggingCallback, OnGestureListener, OnDoubleTapListener, MultiTouchZoomListener { @@ -517,21 +517,23 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - float x1 = (i + left - tileX) * ftileSize + w; - float y1 = (j + top - tileY) * ftileSize + h; - String ordImgTile = mgr.calculateTileId(map, left + i, top + j, nzoom); + int leftPlusI = (int) FloatMath.floor((float)MapUtils.getTileNumberX(nzoom, MapUtils.getLongitudeFromTile(nzoom, left+i))); + int topPlusJ = (int) FloatMath.floor((float)MapUtils.getTileNumberY(nzoom, MapUtils.getLatitudeFromTile(nzoom, top + j))); + float x1 = (left + i - tileX) * ftileSize + w; + float y1 = (top + j - tileY) * ftileSize + h; + String ordImgTile = mgr.calculateTileId(map, leftPlusI, topPlusJ, nzoom); // asking tile image async - boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, left + i, top + j, nzoom); + boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, leftPlusI, topPlusJ, nzoom); Bitmap bmp = null; boolean originalBeLoaded = useInternet && nzoom <= maxLevel; if (imgExist || originalBeLoaded) { - bmp = mgr.getTileImageForMapAsync(ordImgTile, map, left + i, top + j, nzoom, useInternet); + bmp = mgr.getTileImageForMapAsync(ordImgTile, map, leftPlusI, topPlusJ, nzoom, useInternet); } if (bmp == null) { int div = 2; // asking if there is small version of the map (in cache) - String imgTile2 = mgr.calculateTileId(map, (left + i) / 2, (top + j) / 2, nzoom - 1); - String imgTile4 = mgr.calculateTileId(map, (left + i) / 4, (top + j) / 4, nzoom - 2); + String imgTile2 = mgr.calculateTileId(map, leftPlusI / 2, topPlusJ / 2, nzoom - 1); + String imgTile4 = mgr.calculateTileId(map, leftPlusI / 4, topPlusJ / 4, nzoom - 2); if (originalBeLoaded || imgExist) { bmp = mgr.getTileImageFromCache(imgTile2); div = 2; @@ -541,14 +543,14 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } } if (!originalBeLoaded && !imgExist) { - if (mgr.tileExistOnFileSystem(imgTile2, map, (left + i) / 2, (top + j) / 2, nzoom - 1) + if (mgr.tileExistOnFileSystem(imgTile2, map, leftPlusI / 2, topPlusJ / 2, nzoom - 1) || (useInternet && nzoom - 1 <= maxLevel)) { - bmp = mgr.getTileImageForMapAsync(imgTile2, map, (left + i) / 2, (top + j) / 2, nzoom - 1, + bmp = mgr.getTileImageForMapAsync(imgTile2, map, leftPlusI / 2, topPlusJ / 2, nzoom - 1, useInternet); div = 2; - } else if (mgr.tileExistOnFileSystem(imgTile4, map, (left + i) / 4, (top + j) / 4, nzoom - 2) + } else if (mgr.tileExistOnFileSystem(imgTile4, map, leftPlusI / 4, topPlusJ / 4, nzoom - 2) || (useInternet && nzoom - 2 <= maxLevel)) { - bmp = mgr.getTileImageForMapAsync(imgTile4, map, (left + i) / 4, (top + j) / 4, nzoom - 2, + bmp = mgr.getTileImageForMapAsync(imgTile4, map, leftPlusI / 4, topPlusJ / 4, nzoom - 2, useInternet); div = 4; }