From 88a8da98b1ccb04dadb609a5532236c32f45b8cd Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 29 May 2010 14:33:19 +0000 Subject: [PATCH] implement zoom tile for map git-svn-id: https://osmand.googlecode.com/svn/trunk@98 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 11 ++++------- OsmAnd/src/com/osmand/ResourceManager.java | 12 ++++++++---- .../com/osmand/activities/MapActivity.java | 5 ----- .../com/osmand/views/OsmandMapTileView.java | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 5bbfe944fb..b1f3ca9daa 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -6,16 +6,15 @@ package com.osmand; */ public class ToDoConstants { - /** * Write activity to show something about authors / donation .... */ public int DESCRIBE_ABOUT_AUTHORS = 8; // TODO ANDROID -// 25. POI search near to map location (show categories & type). Second cut. (implement incremental search) +// 25. POI search near to map location (show categories & type). Second cut. (implement incremental search) -// 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. +// 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. // 13. Save point as favorite & introduce favorite points dialog // 14. Show zoom level on map @@ -23,7 +22,6 @@ public class ToDoConstants { // 5. Search for city/streets/buildings // 15. Investigate interruption of any long running operation & implement where it is needed. // Fix progress information (loading indices). -// 21. Implement zooming tile (if tile doesn't exist local, we can zoom in previous tile). // 8. Enable change POI directly on map (requires OSM login) // 16. Support open street bugs api. @@ -41,13 +39,13 @@ public class ToDoConstants { // TODO SWING: // 1. Download tiles without using dir tiles // 2. Configure file log & see log from file (add uncaught exception handling) - // 5. Implement supress warning for duplicate id + // 5. Implement suppress warning for duplicate id // 6. Implement renaming/deleting street/building/city // 7. Implement saving bundle of tiles in different folder - // DONE ANDROID : +// 21. Implement zooming tile (if tile doesn't exist local, we can zoom in previous tile). // 11. Print out additional info speed, altitude, number of satellites // 19. Show how map is rotated where north/south on map (do not consider compass) // 23. Implement moving point from center to bottom (for rotating map) @@ -56,7 +54,6 @@ public class ToDoConstants { // 2. Showing compass on the map : use device compass if exists(?) // 18. Implement go to point - // DONE SWING } diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 2aff905174..dcc63edcc0 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -82,15 +82,19 @@ public class ResourceManager { public Bitmap getTileImageForMapAsync(ITileSource map, int x, int y, int zoom, boolean loadFromInternetIfNeeded) { - return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, false); + return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, false, true); + } + + public Bitmap getTileImageFromCache(ITileSource map, int x, int y, int zoom){ + return getTileImageForMap(map, x, y, zoom, false, false, false); } public Bitmap getTileImageForMapSync(ITileSource map, int x, int y, int zoom, boolean loadFromInternetIfNeeded) { - return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, true); + return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, true, true); } protected Bitmap getTileImageForMap(ITileSource map, int x, int y, int zoom, - boolean loadFromInternetIfNeeded, boolean sync) { + boolean loadFromInternetIfNeeded, boolean sync, boolean loadFromFs) { if (map == null) { return null; } @@ -98,7 +102,7 @@ public class ResourceManager { builder.append(map.getName()).append('/').append(zoom). append('/').append(x). append('/').append(y).append(map.getTileFormat()).append(".tile"); String file = builder.toString(); - if (cacheOfImages.get(file) == null) { + if (loadFromFs && cacheOfImages.get(file) == null) { String url = loadFromInternetIfNeeded ? map.getUrlToLoad(x, y, zoom) : null; TileLoadDownloadRequest req = new TileLoadDownloadRequest(dirWithTiles, file, url, new File(dirWithTiles, file), x, y, zoom); diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 9a86e66162..08b267ab58 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -164,11 +164,6 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } public void setLocation(Location location){ - // TODO remove that !! - if(location != null){ - location.setSpeed(30); - location.setBearing(90); - } // Do very strange manipulation to call redraw only once // show point view only if gps enabled diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index e0179d874e..b227d29f0a 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -323,6 +323,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall // used only to save space & reuse protected RectF tilesRect = new RectF(); protected Rect boundsRect = new Rect(); + protected RectF bitmapToDraw = new RectF(); + protected Rect bitmapToZoom = new Rect(); public void refreshMap() { if (OsmandSettings.isUsingInternetToDownloadTiles(getContext())) { @@ -353,9 +355,24 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall for (int j = 0; j< height; j++) { float x1 = (i + left - tileX) * tileSize + w; float y1 = (j + top - tileY) * tileSize + h; + // asking tile image async Bitmap bmp = mgr.getTileImageForMapAsync(map, left + i, top + j, zoom, useInternet); if (bmp == null) { - drawEmptyTile(canvas, (int) x1, (int) y1); + // asking if there is small version of the map (in cache) + if(useInternet){ + bmp = mgr.getTileImageFromCache(map, (left + i) / 2, (top + j) / 2, zoom - 1); + } else { + bmp = mgr.getTileImageForMapAsync(map, (left + i) / 2, (top + j) / 2, zoom - 1, false); + } + if(bmp == null){ + drawEmptyTile(canvas, (int) x1, (int) y1); + } else { + int xZoom = (left + i) % 2 == 0 ? 0 : tileSize / 2; + int yZoom = (top + j) % 2 == 0 ? 0 : tileSize / 2;; + bitmapToZoom.set(xZoom, yZoom, xZoom + tileSize / 2, yZoom + tileSize / 2); + bitmapToDraw.set(x1, y1, x1 + tileSize, y1 + tileSize); + canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap); + } } else { canvas.drawBitmap(bmp, x1, y1, paintBitmap); }