diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index 97132983fb..548e7bad36 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -126,6 +126,19 @@ public class BinaryMapIndexReader { return mapIndexes.size() > 0; } + public boolean containsMapData(int tile31x, int tile31y, int zoom){ + for(MapIndex mapIndex : mapIndexes){ + for(MapRoot root : mapIndex.getRoots()){ + if (root.minZoom <= zoom && root.maxZoom >= zoom) { + if (tile31x >= root.left && tile31x <= root.right && root.top <= tile31y && root.bottom >= tile31y) { + return true; + } + } + } + } + return false; + } + public boolean containsAddressData(){ return addressIndexes.size() > 0; } diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 355bb59429..427bcaa19e 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description"> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 3ef83e6b8c..a25bdb9b30 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,6 +1,8 @@ - + Vector maps doesn\'t contain that place, you can switch source in menu (Layers -> Map Source... -> Vector OSM maps) to see the map. + You can switch to vector maps using menu (Layers -> Map Source... -> Vector OSM maps) to see the map. + Successful. You can switch to vector maps on menu Layers -> Map Source... -> Vector OSM maps. Voice guidance stream Choose channel to provide voice guidance (depends on system configuration) Voice call stream diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 61341cb2a3..f03411ef70 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -545,7 +545,7 @@ public class DownloadIndexActivity extends ListActivity { is.close(); } } - if(length != fileread){ + if(length != fileread || length == 0){ throw new IOException("File was not fully read"); //$NON-NLS-1$ } @@ -643,6 +643,11 @@ public class DownloadIndexActivity extends ListActivity { manager.indexingPoi(progress, warnings, toIndex); } else if (toIndex.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { warnings.addAll(manager.indexingMaps(progress)); + if(warnings.isEmpty() && !OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.get()){ + warnings.add(getString(R.string.binary_map_download_success)); + // Is it proper way to switch every tome to vector data? + OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.set(true); + } } else if (toIndex.getName().endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { } if(dateModified != null){ diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index abfa763f55..9fc75e84d1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -92,10 +92,10 @@ public class MapActivityLayers { RoutingHelper routingHelper = ((OsmandApplication) getApplication()).getRoutingHelper(); - underlayLayer = new MapTileLayer(); + underlayLayer = new MapTileLayer(false); // mapView.addLayer(underlayLayer, -0.5f); - mapTileLayer = new MapTileLayer(); + mapTileLayer = new MapTileLayer(true); mapView.addLayer(mapTileLayer, 0.0f); mapView.setMainLayer(mapTileLayer); @@ -103,7 +103,7 @@ public class MapActivityLayers { mapVectorLayer = new MapVectorLayer(mapTileLayer); mapView.addLayer(mapVectorLayer, 0.5f); - overlayLayer = new MapTileLayer(); + overlayLayer = new MapTileLayer(false); // mapView.addLayer(overlayLayer, 0.7f); // 0.9 gpx layer diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index e5939119c1..6ba6460e4e 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -142,6 +142,17 @@ public class MapRenderRepositories { } } + public boolean containsLatLonMapData(double lat, double lon, int zoom) { + int x = MapUtils.get31TileNumberX(lon); + int y = MapUtils.get31TileNumberY(lat); + for (BinaryMapIndexReader reader : files.values()) { + if (reader.containsMapData(x, y, zoom)) { + return true; + } + } + return false; + } + public void clearAllResources(){ clearCache(); for(String f : new ArrayList(files.keySet())){ diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index 265e109c5b..3d0fc56c72 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -1,6 +1,7 @@ package net.osmand.plus.render; import net.osmand.osm.MapUtils; +import net.osmand.plus.R; import net.osmand.plus.ResourceManager; import net.osmand.plus.RotatedTileBox; import net.osmand.plus.views.BaseMapLayer; @@ -12,6 +13,7 @@ import android.graphics.Paint; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; +import android.widget.Toast; public class MapVectorLayer extends BaseMapLayer { @@ -99,7 +101,16 @@ public class MapVectorLayer extends BaseMapLayer { pixRect.set(-view.getWidth()/3, -view.getHeight() / 4, 4 * view.getWidth() /3, 5 * view.getHeight() / 4); updateRotatedTileBox(); resourceManager.updateRendererMap(rotatedTileBox); + // does it slow down Map refreshing ? + // Arguments : 1. Map request to read data slows whole process // 2. It works in operating memory + if(!warningToSwitchMapShown){ + if(!resourceManager.getRenderer().containsLatLonMapData(view.getLatitude(), view.getLongitude(), view.getZoom())){ + Toast.makeText(view.getContext(), R.string.switch_to_raster_map_to_see, Toast.LENGTH_LONG).show(); + warningToSwitchMapShown = true; + } + } } + } MapRenderRepositories renderer = resourceManager.getRenderer(); diff --git a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java index c8557d4bb0..413f0d61fd 100644 --- a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java @@ -3,6 +3,7 @@ package net.osmand.plus.views; public abstract class BaseMapLayer implements OsmandMapLayer { private int alpha = 255; + protected boolean warningToSwitchMapShown = false; public int getMaximumShownMapZoom(){ return 21; diff --git a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java index c2941ca5a7..38b3223049 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java @@ -2,6 +2,7 @@ package net.osmand.plus.views; import net.osmand.map.ITileSource; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; import net.osmand.plus.ResourceManager; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -10,16 +11,17 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.util.FloatMath; +import android.widget.Toast; public class MapTileLayer extends BaseMapLayer { protected final int emptyTileDivisor = 16; public static final int OVERZOOM_IN = 2; + private final boolean mainMap; protected ITileSource map = null; Paint paintBitmap; - protected RectF tilesRect = new RectF(); protected RectF latlonRect = new RectF(); protected RectF bitmapToDraw = new RectF(); @@ -30,6 +32,11 @@ public class MapTileLayer extends BaseMapLayer { protected ResourceManager resourceManager; private OsmandSettings settings; private boolean visible = true; + + + public MapTileLayer(boolean mainMap){ + this.mainMap = mainMap; + } @Override public boolean drawInScreenPixels() { @@ -93,19 +100,10 @@ public class MapTileLayer extends BaseMapLayer { && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet(); int maxLevel = Math.min(view.getSettings().MAX_LEVEL_TO_DOWNLOAD_TILE.get(), map.getMaximumZoomSupported()); int tileSize = map.getTileSize(); + boolean oneTileShown = false; 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.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; @@ -149,14 +147,23 @@ public class MapTileLayer extends BaseMapLayer { bitmapToZoom.set(xZoom, yZoom, xZoom + tileSize / div, yZoom + tileSize / div); bitmapToDraw.set(x1, y1, x1 + ftileSize, y1 + ftileSize); canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap); + oneTileShown = true; } } else { bitmapToZoom.set(0, 0, tileSize, tileSize); bitmapToDraw.set(x1, y1, x1 + ftileSize, y1 + ftileSize); canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap); + oneTileShown = true; } } } + + if(mainMap && !oneTileShown && !useInternet && !warningToSwitchMapShown){ + if(resourceManager.getRenderer().containsLatLonMapData(view.getLatitude(), view.getLongitude(), nzoom)){ + Toast.makeText(view.getContext(), R.string.switch_to_vector_map_to_see, Toast.LENGTH_LONG).show(); + warningToSwitchMapShown = true; + } + } } public int getSourceTileSize() { diff --git a/OsmAnd/src/net/osmand/plus/views/YandexTrafficLayer.java b/OsmAnd/src/net/osmand/plus/views/YandexTrafficLayer.java index ffa07aa59f..e121e316b5 100644 --- a/OsmAnd/src/net/osmand/plus/views/YandexTrafficLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/YandexTrafficLayer.java @@ -28,6 +28,10 @@ public class YandexTrafficLayer extends MapTileLayer { private long lastTimestampUpdated; private String mTimestamp = null; private boolean updateThreadRan = false; + + public YandexTrafficLayer() { + super(false); + } public void setVisible(boolean visible) { if(isVisible() != visible){