Implement map switching
This commit is contained in:
parent
de1faa64bf
commit
9664043bb9
5 changed files with 30 additions and 21 deletions
|
@ -45,7 +45,7 @@ public class DownloadTilesDialog {
|
|||
|
||||
public void openDialog(){
|
||||
final ITileSource mapSource = mapView.getMap();
|
||||
if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
|
||||
if(mapSource == null || mapView.isVectorDataVisible() || !mapSource.couldBeDownloadedFromInternet()){
|
||||
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -808,12 +808,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
((SQLiteTileSource)mapView.getMap()).closeDB();
|
||||
}
|
||||
rm.updateMapSource(vectorData, newSource);
|
||||
|
||||
mapView.setMap(vectorData ? null : newSource);
|
||||
mapView.setMap(newSource);
|
||||
mapView.setVectorData(vectorData);
|
||||
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.ZoomControls);
|
||||
zoomControls.setIsZoomInEnabled(mapView.getZoom() + 1 < mapView.getMaximumShownMapZoom());
|
||||
zoomControls.setIsZoomOutEnabled(mapView.getZoom() + 1 > mapView.getMinimumShownMapZoom());
|
||||
rendererLayer.setVisible(vectorData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -827,7 +826,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
boolean showTiles = !settings.isUsingMapVectorData();
|
||||
ITileSource source = showTiles ? settings.getMapTileSource() : null;
|
||||
if (showTiles != !rendererLayer.isVisible() || !Algoritms.objectEquals(mapView.getMap(), source)) {
|
||||
if (showTiles != !mapView.isVectorData() || !Algoritms.objectEquals(mapView.getMap(), source)) {
|
||||
updateMapSource();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import net.osmand.FavouritePoint;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.AmenityIndexRepository;
|
||||
import net.osmand.plus.AmenityIndexRepositoryOdb;
|
||||
|
@ -124,6 +125,11 @@ public class MapActivityActions {
|
|||
builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final ITileSource mapSource = mapView.getMap();
|
||||
if(mapSource == null || mapView.isVectorDataVisible() || !mapSource.couldBeDownloadedFromInternet()){
|
||||
Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Rect pixRect = new Rect(0, 0, mapView.getWidth(), mapView.getHeight());
|
||||
RectF tilesRect = new RectF();
|
||||
mapView.calculateTileRectangle(pixRect, mapView.getCenterPointX(), mapView.getCenterPointY(),
|
||||
|
|
|
@ -22,7 +22,6 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
private Paint paintImg;
|
||||
|
||||
private RectF destImage = new RectF();
|
||||
private boolean visible = false;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -54,7 +53,7 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
|
||||
Integer zoom = view.getSettings().LEVEL_TO_SWITCH_VECTOR_RASTER.get();
|
||||
if (view.getZoom() >= Math.max(zoom, startZoom) && visible) {
|
||||
if (view.getZoom() >= Math.max(zoom, startZoom) && view.isVectorDataVisible()) {
|
||||
if (!view.isZooming()){
|
||||
pixRect.set(0, 0, view.getWidth(), view.getHeight());
|
||||
updateRotatedTileBox();
|
||||
|
@ -101,15 +100,6 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
view.refreshMap();
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongPressEvent(PointF point) {
|
||||
return false;
|
||||
|
|
|
@ -86,6 +86,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
// name of source map
|
||||
private ITileSource map = null;
|
||||
|
||||
private boolean vectorData;
|
||||
|
||||
private IMapLocationListener locationListener;
|
||||
|
||||
|
@ -225,7 +227,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
* Returns real tile size in pixels for float zoom .
|
||||
*/
|
||||
public float getTileSize() {
|
||||
float res = map == null ? 256 : map.getTileSize();
|
||||
float res = getSourceTileSize();
|
||||
if (zoom != (int) zoom) {
|
||||
res *= (float) Math.pow(2, zoom - (int) zoom);
|
||||
}
|
||||
|
@ -240,7 +242,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
|
||||
public int getSourceTileSize() {
|
||||
return map == null ? 256 : map.getTileSize();
|
||||
return map == null || vectorData ? 256 : map.getTileSize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,7 +260,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
|
||||
public int getMaximumShownMapZoom(){
|
||||
if(map == null){
|
||||
if(map == null || vectorData){
|
||||
return 21;
|
||||
} else {
|
||||
return map.getMaximumZoomSupported() + OVERZOOM_IN;
|
||||
|
@ -266,7 +268,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
|
||||
public int getMinimumShownMapZoom(){
|
||||
if(map == null){
|
||||
if(map == null || vectorData){
|
||||
return 1;
|
||||
} else {
|
||||
return map.getMinimumZoomSupported();
|
||||
|
@ -378,6 +380,18 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVectorData() {
|
||||
return vectorData;
|
||||
}
|
||||
|
||||
public boolean isVectorDataVisible() {
|
||||
return vectorData && zoom >= settings.LEVEL_TO_SWITCH_VECTOR_RASTER.get();
|
||||
}
|
||||
|
||||
public void setVectorData(boolean vectorData) {
|
||||
this.vectorData = vectorData;
|
||||
}
|
||||
|
||||
public int getCenterPointX() {
|
||||
return getWidth() / 2;
|
||||
|
@ -507,7 +521,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
latlonRect.left = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.left);
|
||||
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.bottom);
|
||||
latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right);
|
||||
if (map != null) {
|
||||
if (map != null && !isVectorDataVisible()) {
|
||||
ResourceManager mgr = getApplication().getResourceManager();
|
||||
useInternet = useInternet && settings.isInternetConnectionAvailable()
|
||||
&& map.couldBeDownloadedFromInternet();
|
||||
|
|
Loading…
Reference in a new issue