Refactor layers add new map main layer
This commit is contained in:
parent
c1f731eb22
commit
630b423efd
9 changed files with 182 additions and 154 deletions
|
@ -10,19 +10,24 @@ public class ToDoConstants {
|
|||
|
||||
// == Osmand application (TODO 127) ==
|
||||
|
||||
// Map Refactoring
|
||||
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
||||
// Fix issue with min/max zoom
|
||||
// Refactoring animation (no need source tile size?)
|
||||
// Refactoring ResourceManager with cached images (tiles density)
|
||||
// YandexLayer goes to MapTileLayer
|
||||
// Add transparency filter to bitmap layers
|
||||
// Download layers from internet (?) and allow to add own tile sources
|
||||
// Manage tile sources and allow to compact them into sqlite db
|
||||
|
||||
// === Refactoring issues ===
|
||||
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
||||
|
||||
|
||||
|
||||
|
||||
// === Common issues ===
|
||||
// || 104 || Add activity to show current loaded indexes and information about them (Issue 366) ||
|
||||
// || 123 || Improve gpx file showing (very slow for big files) (Issue 412) ||
|
||||
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
||||
// || 122 || Frozen sqlite db images (bug?). When images are loaded into sqlite the whole map is frozen (issue 413) ||
|
||||
// || 120 || Show icons over poi circle (issue 414) ||
|
||||
// || 110 || Use android voice for pronounce command (could be used in future to pronounce street) (Issue 70) ||
|
||||
// || 119 || Dialog on main screen tips and tricks (Issue 415) ||
|
||||
// || 118 || Config switching between maps on different zoom levels <14 (using raster), > 14 vector (Issue 419) ||
|
||||
// || 97 || For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m (Issue 420) ||
|
||||
// || 111 || Investigate showing street name while driving (Issue 286) ||
|
||||
// || 86 || Allow to add/edit custom tags to POI objects (Issue 44) ||
|
||||
|
@ -46,6 +51,10 @@ public class ToDoConstants {
|
|||
/////////////////////////// DONE //////////////////////////////
|
||||
// DONE ANDROID :
|
||||
// || 112 || Investigate exiting/minimizing app (Issue 214) ||
|
||||
// || 122 || Frozen sqlite db images (bug?). When images are loaded into sqlite the whole map is frozen (issue 413) ||
|
||||
// || 120 || Show icons over poi circle (issue 414) ||
|
||||
// || 119 || Dialog on main screen tips and tricks (Issue 415) ||
|
||||
// || 118 || Config switching between maps on different zoom levels <14 (using raster), > 14 vector (Issue 419) ||
|
||||
|
||||
// DONE SWING
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ import net.osmand.map.ITileSource;
|
|||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.ResourceManager;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -44,8 +46,12 @@ public class DownloadTilesDialog {
|
|||
|
||||
|
||||
public void openDialog(){
|
||||
final ITileSource mapSource = mapView.getMap();
|
||||
if(mapSource == null || mapView.isVectorDataVisible() || !mapSource.couldBeDownloadedFromInternet()){
|
||||
BaseMapLayer mainLayer = mapView.getMainLayer();
|
||||
if(!(mainLayer instanceof MapTileLayer) || ((MapTileLayer) mainLayer).isVisible()){
|
||||
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
|
||||
if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
|
||||
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -35,13 +35,14 @@ import net.osmand.plus.activities.search.SearchActivity;
|
|||
import net.osmand.plus.activities.search.SearchPoiFilterActivity;
|
||||
import net.osmand.plus.activities.search.SearchTransportActivity;
|
||||
import net.osmand.plus.render.MapRenderRepositories;
|
||||
import net.osmand.plus.render.RendererLayer;
|
||||
import net.osmand.plus.render.MapVectorLayer;
|
||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.FavoritesLayer;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmBugsLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.POIMapLayer;
|
||||
|
@ -124,7 +125,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
private ImageButton backToLocation;
|
||||
|
||||
// the order of layer should be preserved ! when you are inserting new layer
|
||||
private RendererLayer rendererLayer;
|
||||
private MapTileLayer mapTileLayer;
|
||||
private MapVectorLayer mapVectorLayer;
|
||||
private GPXLayer gpxLayer;
|
||||
private RouteLayer routeLayer;
|
||||
private YandexTrafficLayer trafficLayer;
|
||||
|
@ -221,9 +223,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
mapView.setMapLocationListener(this);
|
||||
routingHelper = ((OsmandApplication) getApplication()).getRoutingHelper();
|
||||
|
||||
mapTileLayer = new MapTileLayer();
|
||||
mapView.addLayer(mapTileLayer, 0.0f);
|
||||
mapView.setMainLayer(mapTileLayer);
|
||||
|
||||
// 0.5 layer
|
||||
rendererLayer = new RendererLayer();
|
||||
mapView.addLayer(rendererLayer, 0.5f);
|
||||
mapVectorLayer = new MapVectorLayer(mapTileLayer);
|
||||
mapView.addLayer(mapVectorLayer, 0.5f);
|
||||
|
||||
// 0.6 gpx layer
|
||||
gpxLayer = new GPXLayer();
|
||||
|
@ -401,7 +407,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
// TODO keep this check?
|
||||
if(routingHelper.isFollowingMode()){
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
mNotificationManager.notify(APP_NOTIFICATION_ID, getNotification());
|
||||
|
@ -771,16 +776,19 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
}
|
||||
}
|
||||
ITileSource newSource = settings.getMapTileSource();
|
||||
if(mapView.getMap() instanceof SQLiteTileSource){
|
||||
((SQLiteTileSource)mapView.getMap()).closeDB();
|
||||
ITileSource oldMap = mapTileLayer.getMap();
|
||||
if(oldMap instanceof SQLiteTileSource){
|
||||
((SQLiteTileSource)oldMap).closeDB();
|
||||
}
|
||||
rm.updateMapSource(vectorData, newSource);
|
||||
mapView.setMap(newSource);
|
||||
mapView.setVectorData(vectorData);
|
||||
// TODO move to another place
|
||||
// ZoomControls zoomControls = (ZoomControls) findViewById(R.id.ZoomControls);
|
||||
// zoomControls.setIsZoomInEnabled(mapView.getZoom() + 1 < mapView.getMaximumShownMapZoom());
|
||||
// zoomControls.setIsZoomOutEnabled(mapView.getZoom() + 1 > mapView.getMinimumShownMapZoom());
|
||||
mapTileLayer.setMap(newSource);
|
||||
mapTileLayer.setVisible(!vectorData);
|
||||
mapVectorLayer.setVisible(vectorData);
|
||||
if(vectorData){
|
||||
mapView.setMainLayer(mapVectorLayer);
|
||||
} else {
|
||||
mapView.setMainLayer(mapTileLayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -794,7 +802,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
boolean showTiles = !settings.isUsingMapVectorData();
|
||||
ITileSource source = showTiles ? settings.getMapTileSource() : null;
|
||||
if (showTiles != !mapView.isVectorData() || !Algoritms.objectEquals(mapView.getMap(), source)) {
|
||||
if (showTiles != mapTileLayer.isVisible() || !Algoritms.objectEquals(mapTileLayer.getMap(), source)) {
|
||||
updateMapSource();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import net.osmand.plus.AmenityIndexRepository;
|
|||
import net.osmand.plus.AmenityIndexRepositoryOdb;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -125,8 +127,12 @@ 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()){
|
||||
BaseMapLayer mainLayer = mapView.getMainLayer();
|
||||
if(!(mainLayer instanceof MapTileLayer) || ((MapTileLayer) mainLayer).isVisible()){
|
||||
Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
|
||||
if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
|
||||
Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
@ -141,7 +147,7 @@ public class MapActivityActions {
|
|||
for (int i = 0; i <width; i++) {
|
||||
for (int j = 0; j< height; j++) {
|
||||
((OsmandApplication)mapActivity.getApplication()).getResourceManager().
|
||||
clearTileImageForMap(null, mapView.getMap(), i + left, j + top, zoom);
|
||||
clearTileImageForMap(null, mapSource, i + left, j + top, zoom);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ package net.osmand.plus.render;
|
|||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.ResourceManager;
|
||||
import net.osmand.plus.RotatedTileBox;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -12,7 +13,7 @@ import android.graphics.PointF;
|
|||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
|
||||
public class RendererLayer implements OsmandMapLayer {
|
||||
public class MapVectorLayer extends BaseMapLayer {
|
||||
|
||||
private OsmandMapTileView view;
|
||||
private Rect pixRect = new Rect();
|
||||
|
@ -21,6 +22,12 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
private Paint paintImg;
|
||||
|
||||
private RectF destImage = new RectF();
|
||||
private final MapTileLayer tileLayer;
|
||||
private boolean visible = false;
|
||||
|
||||
public MapVectorLayer(MapTileLayer tileLayer){
|
||||
this.tileLayer = tileLayer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -47,11 +54,41 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
rotatedTileBox.set(xL, yT, ((float) pixRect.width()) / ts, ((float) pixRect.height()) / ts, view.getRotate(), view.getZoom());
|
||||
}
|
||||
|
||||
public boolean isVectorDataVisible() {
|
||||
return visible && view.getZoom() >= view.getSettings().LEVEL_TO_SWITCH_VECTOR_RASTER.get();
|
||||
}
|
||||
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
if(!visible){
|
||||
resourceManager.getRenderer().clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumShownMapZoom() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumShownMapZoom() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, boolean nightMode) {
|
||||
if (view.isVectorDataVisible()) {
|
||||
if(!visible){
|
||||
return;
|
||||
}
|
||||
if(!isVectorDataVisible() && tileLayer != null){
|
||||
tileLayer.drawTileMap(canvas, tilesRect);
|
||||
} else {
|
||||
if (!view.isZooming()){
|
||||
pixRect.set(0, 0, view.getWidth(), view.getHeight());
|
||||
updateRotatedTileBox();
|
||||
|
@ -81,20 +118,12 @@ public class RendererLayer implements OsmandMapLayer {
|
|||
float x1 = MapUtils.calcDiffPixelX(sin, cos, dleftX1, dtopY1, view.getTileSize()) + view.getCenterPointX();
|
||||
float y1 = MapUtils.calcDiffPixelY(sin, cos, dleftX1, dtopY1, view.getTileSize()) + view.getCenterPointY();
|
||||
|
||||
/*float drightX1 = (bmpLoc.getRightBottomTileX() * mult - tx) ;
|
||||
float dbottomY1 = (bmpLoc.getRightBottomTileY() * mult - ty);
|
||||
float x2 = MapUtils.calcDiffPixelX(sin, cos, drightX1, dbottomY1, view.getTileSize()) + view.getCenterPointX();
|
||||
float y2 = MapUtils.calcDiffPixelY(sin, cos, drightX1, dbottomY1, view.getTileSize()) + view.getCenterPointY();
|
||||
destImage.set(x1, y1, x2, y2);*/
|
||||
|
||||
canvas.rotate(-rot, view.getCenterPointX(), view.getCenterPointY());
|
||||
destImage.set(x1, y1, x1 + bmpLoc.getTileWidth() * mult * view.getTileSize(), y1 + bmpLoc.getTileHeight() * mult * view.getTileSize());
|
||||
if(!bmp.isRecycled()){
|
||||
canvas.drawBitmap(bmp, null, destImage, paintImg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resourceManager.getRenderer().clearCache();
|
||||
}
|
||||
}
|
||||
|
15
OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java
Normal file
15
OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
public abstract class BaseMapLayer implements OsmandMapLayer {
|
||||
|
||||
|
||||
public int getMaximumShownMapZoom(){
|
||||
return 21;
|
||||
}
|
||||
|
||||
public int getMinimumShownMapZoom(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -96,8 +96,9 @@ public class MapControlsLayer implements OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {
|
||||
boolean zoomInEnabled = view.getZoom() < view.getMaximumShownMapZoom();
|
||||
boolean zoomOutEnabled = view.getZoom() > view.getMinimumShownMapZoom();
|
||||
BaseMapLayer mainLayer = view.getMainLayer();
|
||||
boolean zoomInEnabled = mainLayer != null && view.getZoom() < mainLayer.getMaximumShownMapZoom();
|
||||
boolean zoomOutEnabled = mainLayer != null && view.getZoom() > mainLayer.getMinimumShownMapZoom();
|
||||
if(zoomInButton.isEnabled() != zoomInEnabled){
|
||||
zoomInButton.setEnabled(zoomInEnabled);
|
||||
}
|
||||
|
|
|
@ -6,24 +6,19 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.ResourceManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.util.FloatMath;
|
||||
|
||||
public class MapTileLayer implements OsmandMapLayer {
|
||||
public class MapTileLayer extends BaseMapLayer {
|
||||
|
||||
protected final int emptyTileDivisor = 16;
|
||||
public static final int OVERZOOM_IN = 2;
|
||||
|
||||
private ITileSource map = null;
|
||||
|
||||
Paint paintGrayFill;
|
||||
Paint paintBlackFill;
|
||||
Paint paintWhiteFill;
|
||||
Paint paintBitmap;
|
||||
|
||||
protected RectF tilesRect = new RectF();
|
||||
|
@ -46,24 +41,6 @@ public class MapTileLayer implements OsmandMapLayer {
|
|||
this.view = view;
|
||||
settings = view.getSettings();
|
||||
resourceManager = view.getApplication().getResourceManager();
|
||||
|
||||
paintGrayFill = new Paint();
|
||||
paintGrayFill.setColor(Color.GRAY);
|
||||
paintGrayFill.setStyle(Style.FILL);
|
||||
// when map rotate
|
||||
paintGrayFill.setAntiAlias(true);
|
||||
|
||||
paintBlackFill= new Paint();
|
||||
paintBlackFill.setColor(Color.BLACK);
|
||||
paintBlackFill.setStyle(Style.FILL);
|
||||
// when map rotate
|
||||
paintBlackFill.setAntiAlias(true);
|
||||
|
||||
paintWhiteFill = new Paint();
|
||||
paintWhiteFill.setColor(Color.WHITE);
|
||||
paintWhiteFill.setStyle(Style.FILL);
|
||||
// when map rotate
|
||||
paintWhiteFill.setAntiAlias(true);
|
||||
|
||||
paintBitmap = new Paint();
|
||||
paintBitmap.setFilterBitmap(true);
|
||||
|
@ -75,6 +52,14 @@ public class MapTileLayer implements OsmandMapLayer {
|
|||
if (map == null || !visible) {
|
||||
return;
|
||||
}
|
||||
drawTileMap(canvas, tilesRect);
|
||||
|
||||
}
|
||||
|
||||
public void drawTileMap(Canvas canvas, RectF tilesRect) {
|
||||
if(map == null){
|
||||
return;
|
||||
}
|
||||
ResourceManager mgr = resourceManager;
|
||||
int nzoom = view.getZoom();
|
||||
float tileX = view.getXTile();
|
||||
|
@ -147,7 +132,6 @@ public class MapTileLayer implements OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getSourceTileSize() {
|
||||
|
|
|
@ -11,7 +11,6 @@ import net.osmand.data.MapTileDownloader;
|
|||
import net.osmand.data.MapTileDownloader.DownloadRequest;
|
||||
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
|
||||
import net.osmand.map.IMapLocationListener;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -81,8 +80,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
private boolean showMapPosition = true;
|
||||
|
||||
private boolean vectorData;
|
||||
|
||||
private IMapLocationListener locationListener;
|
||||
|
||||
private OnLongClickListener onLongClickListener;
|
||||
|
@ -93,7 +90,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
|
||||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
||||
|
||||
private MapTileLayer mainLayer = new MapTileLayer();
|
||||
private BaseMapLayer mainLayer;
|
||||
|
||||
private Map<OsmandMapLayer, Float> zOrders = new HashMap<OsmandMapLayer, Float>();
|
||||
|
||||
|
@ -175,7 +172,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
dm = new DisplayMetrics();
|
||||
mgr.getDefaultDisplay().getMetrics(dm);
|
||||
|
||||
mainLayer.initLayer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,7 +234,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
|
||||
public int getSourceTileSize() {
|
||||
return vectorData ? 256 : mainLayer.getSourceTileSize();
|
||||
if(mainLayer instanceof MapTileLayer){
|
||||
return ((MapTileLayer) mainLayer).getSourceTileSize();
|
||||
}
|
||||
return 256;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -255,24 +254,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
return (float) MapUtils.getTileNumberY(getZoom(), latitude);
|
||||
}
|
||||
|
||||
public int getMaximumShownMapZoom(){
|
||||
if(vectorData){
|
||||
return 21;
|
||||
} else {
|
||||
return mainLayer.getMaximumShownMapZoom();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMinimumShownMapZoom(){
|
||||
if(vectorData){
|
||||
return 1;
|
||||
} else {
|
||||
return mainLayer.getMinimumShownMapZoom();
|
||||
}
|
||||
}
|
||||
|
||||
public void setZoom(float zoom) {
|
||||
if (zoom <= getMaximumShownMapZoom() && zoom >= getMinimumShownMapZoom()) {
|
||||
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
|
||||
animatedDraggingThread.stopAnimating();
|
||||
this.zoom = zoom;
|
||||
refreshMap();
|
||||
|
@ -282,8 +265,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
// for internal usage
|
||||
@Override
|
||||
public void zoomTo(float zoom, boolean notify) {
|
||||
if ((vectorData && zoom < 23)
|
||||
|| (!vectorData && getMaximumShownMapZoom() >= zoom && getMinimumShownMapZoom() <= zoom)) {
|
||||
if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) {
|
||||
this.zoom = zoom;
|
||||
refreshMap();
|
||||
if (notify && locationListener != null) {
|
||||
|
@ -311,21 +293,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
return rotate;
|
||||
}
|
||||
|
||||
public ITileSource getMap() {
|
||||
return mainLayer.getMap();
|
||||
}
|
||||
|
||||
public void setMap(ITileSource map) {
|
||||
mainLayer.setMap(map);
|
||||
if (mainLayer.getMaximumShownMapZoom() < this.zoom) {
|
||||
zoom = mainLayer.getMaximumShownMapZoom();
|
||||
}
|
||||
if (mainLayer.getMinimumShownMapZoom() > this.zoom) {
|
||||
zoom = mainLayer.getMinimumShownMapZoom();
|
||||
}
|
||||
refreshMap();
|
||||
}
|
||||
|
||||
public void setLatLon(double latitude, double longitude) {
|
||||
animatedDraggingThread.stopAnimating();
|
||||
this.latitude = latitude;
|
||||
|
@ -377,16 +345,19 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isVectorData() {
|
||||
return vectorData;
|
||||
public BaseMapLayer getMainLayer() {
|
||||
return mainLayer;
|
||||
}
|
||||
|
||||
public boolean isVectorDataVisible() {
|
||||
return vectorData && zoom >= settings.LEVEL_TO_SWITCH_VECTOR_RASTER.get();
|
||||
}
|
||||
|
||||
public void setVectorData(boolean vectorData) {
|
||||
this.vectorData = vectorData;
|
||||
public void setMainLayer(BaseMapLayer mainLayer) {
|
||||
this.mainLayer = mainLayer;
|
||||
if (mainLayer.getMaximumShownMapZoom() < this.zoom) {
|
||||
zoom = mainLayer.getMaximumShownMapZoom();
|
||||
}
|
||||
if (mainLayer.getMinimumShownMapZoom() > this.zoom) {
|
||||
zoom = mainLayer.getMinimumShownMapZoom();
|
||||
}
|
||||
refreshMap();
|
||||
}
|
||||
|
||||
public int getCenterPointX() {
|
||||
|
@ -404,36 +375,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
this.mapPosition = type;
|
||||
}
|
||||
|
||||
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {
|
||||
int w = getCenterPointX();
|
||||
int h = getCenterPointY();
|
||||
canvas.restore();
|
||||
|
||||
for (int i = -1; i < layers.size(); i++) {
|
||||
try {
|
||||
|
||||
OsmandMapLayer layer;
|
||||
if (i == -1) {
|
||||
layer = mainLayer;
|
||||
mainLayer.setVisible(!isVectorDataVisible());
|
||||
} else {
|
||||
layer = layers.get(i);
|
||||
}
|
||||
canvas.save();
|
||||
if (!layer.drawInScreenPixels()) {
|
||||
canvas.rotate(rotate, w, h);
|
||||
}
|
||||
layer.onDraw(canvas, latlonRect, tilesRect, nightMode);
|
||||
canvas.restore();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// skip it
|
||||
}
|
||||
}
|
||||
if (showMapPosition) {
|
||||
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
|
||||
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateTileRectangle(Rect pixRect, float cx, float cy, float ctilex, float ctiley, RectF tileRect) {
|
||||
float x1 = calcDiffTileX(pixRect.left - cx, pixRect.top - cy);
|
||||
|
@ -535,7 +476,30 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {
|
||||
int w = getCenterPointX();
|
||||
int h = getCenterPointY();
|
||||
canvas.restore();
|
||||
|
||||
for (int i = -1; i < layers.size(); i++) {
|
||||
try {
|
||||
OsmandMapLayer layer = layers.get(i);
|
||||
canvas.save();
|
||||
if (!layer.drawInScreenPixels()) {
|
||||
canvas.rotate(rotate, w, h);
|
||||
}
|
||||
layer.onDraw(canvas, latlonRect, tilesRect, nightMode);
|
||||
canvas.restore();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// skip it
|
||||
}
|
||||
}
|
||||
if (showMapPosition) {
|
||||
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
|
||||
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mapIsRefreshing() {
|
||||
|
@ -717,6 +681,16 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
initialMultiTouchLocation = getLatLonFromScreenPoint(centerPoint.x, centerPoint.y);
|
||||
initialMultiTouchZoom = zoom;
|
||||
}
|
||||
|
||||
public LatLon getLatLonFromScreenPoint(float x, float y) {
|
||||
float dx = x - getCenterPointX();
|
||||
float dy = y - getCenterPointY();
|
||||
float fy = calcDiffTileY(dx, dy);
|
||||
float fx = calcDiffTileX(dx, dy);
|
||||
double latitude = MapUtils.getLatitudeFromTile(getZoom(), getYTile() + fy);
|
||||
double longitude = MapUtils.getLongitudeFromTile(getZoom(), getXTile() + fx);
|
||||
return new LatLon(latitude, longitude);
|
||||
}
|
||||
|
||||
private void zoomPositionChanged(float calcZoom) {
|
||||
float dx = initialMultiTouchCenterPoint.x - getCenterPointX();
|
||||
|
@ -740,7 +714,11 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
zoomPositionChanged(calcZoom);
|
||||
}
|
||||
}
|
||||
public AnimateDraggingMapThread getAnimatedDraggingThread() {
|
||||
return animatedDraggingThread;
|
||||
}
|
||||
|
||||
// Start OnGestureListener
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
if (Math.abs(e1.getX() - e2.getX()) + Math.abs(e1.getX() - e2.getX()) > 50 * dm.density) {
|
||||
|
@ -752,10 +730,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
return true;
|
||||
}
|
||||
|
||||
public AnimateDraggingMapThread getAnimatedDraggingThread() {
|
||||
return animatedDraggingThread;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
if (multiTouchSupport.isInZoomMode()) {
|
||||
|
@ -801,17 +776,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
}
|
||||
return false;
|
||||
}
|
||||
// End OnGestureListener
|
||||
|
||||
public LatLon getLatLonFromScreenPoint(float x, float y) {
|
||||
float dx = x - getCenterPointX();
|
||||
float dy = y - getCenterPointY();
|
||||
float fy = calcDiffTileY(dx, dy);
|
||||
float fx = calcDiffTileX(dx, dy);
|
||||
double latitude = MapUtils.getLatitudeFromTile(getZoom(), getYTile() + fy);
|
||||
double longitude = MapUtils.getLongitudeFromTile(getZoom(), getXTile() + fx);
|
||||
return new LatLon(latitude, longitude);
|
||||
}
|
||||
|
||||
// Start OnDoubleTapListener
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
LatLon l = getLatLonFromScreenPoint(e.getX(), e.getY());
|
||||
|
@ -829,5 +797,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// End OnDoubleTapListener
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue