Something
This commit is contained in:
parent
862384a24f
commit
f471400e32
6 changed files with 79 additions and 37 deletions
|
@ -12,7 +12,7 @@ public interface ITileSource {
|
|||
|
||||
public String getUrlToLoad(int x, int y, int zoom);
|
||||
|
||||
public byte[] getBytes(int x, int y, int zoom) throws IOException;
|
||||
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException;
|
||||
|
||||
public int getMinimumZoomSupported();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.map;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -18,6 +19,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -215,6 +217,27 @@ public class TileSourceManager {
|
|||
public String getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
public String calculateTileId(int x, int y, int zoom) {
|
||||
StringBuilder builder = new StringBuilder(getName());
|
||||
builder.append('/');
|
||||
builder.append(zoom).append('/').append(x).append('/').append(y).append(getTileFormat()).append(".tile"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException {
|
||||
File f = new File(dirWithTiles, calculateTileId(x, y, zoom));
|
||||
if (!f.exists())
|
||||
return null;
|
||||
|
||||
ByteArrayOutputStream bous = new ByteArrayOutputStream();
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
Algorithms.streamCopy(fis, bous);
|
||||
fis.close();
|
||||
bous.close();
|
||||
return bous.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> readMetaInfoFile(File dir) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.core.android;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.core.jni.AlphaChannelPresence;
|
||||
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
|
||||
import net.osmand.core.jni.SwigUtilities;
|
||||
|
@ -9,12 +10,15 @@ import net.osmand.core.jni.TileId;
|
|||
import net.osmand.core.jni.ZoomLevel;
|
||||
import net.osmand.core.jni.interface_ImageMapLayerProvider;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
||||
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||
|
||||
private final OsmandApplication app;
|
||||
private final ITileSource tileSource;
|
||||
|
||||
public TileSourceProxyProvider(ITileSource tileSource) {
|
||||
public TileSourceProxyProvider(OsmandApplication app, ITileSource tileSource) {
|
||||
this.app = app;
|
||||
this.tileSource = tileSource;
|
||||
}
|
||||
|
||||
|
@ -27,16 +31,17 @@ public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
|||
public ZoomLevel getMaxZoom() {
|
||||
return ZoomLevel.swigToEnum(tileSource.getMaximumZoomSupported());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SWIGTYPE_p_QByteArray obtainImage(TileId tileId, ZoomLevel zoom) {
|
||||
byte[] image;
|
||||
try {
|
||||
image = tileSource.getBytes(tileId.getX(), tileId.getY(), zoom.swigValue());
|
||||
image = tileSource.getBytes(tileId.getX(), tileId.getY(), zoom.swigValue(),
|
||||
app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath());
|
||||
} catch(IOException e) {
|
||||
return SwigUtilities.emptyQByteArray();
|
||||
}
|
||||
|
||||
|
||||
return SwigUtilities.createQByteArrayAsCopyOf(image);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -28,6 +27,7 @@ import net.osmand.plus.api.SettingsAPI.SettingsEditor;
|
|||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
|
@ -990,7 +990,7 @@ public class OsmandSettings {
|
|||
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<String> MAP_UNDERLAY = new StringPreference("map_underlay", null).makeGlobal();
|
||||
public final CommonPreference<String> MAP_UNDERLAY = new StringPreference("map_underlay", null).makeGlobal().cache();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Integer> MAP_OVERLAY_TRANSPARENCY = new IntPreference("overlay_transparency",
|
||||
|
@ -998,7 +998,7 @@ public class OsmandSettings {
|
|||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Integer> MAP_TRANSPARENCY = new IntPreference("map_transparency",
|
||||
255).makeGlobal();
|
||||
255).makeGlobal().cache();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<String> MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
|
||||
|
@ -1158,6 +1158,7 @@ public class OsmandSettings {
|
|||
return writableSecondaryStorage;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public String getMatchingExternalFilesDir(String dir) {
|
||||
// only API 19 !!
|
||||
try {
|
||||
|
@ -1181,6 +1182,7 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public List<String> getWritableSecondaryStorageDirectorys() {
|
||||
// only API 19 !!
|
||||
// primary external storage directory
|
||||
|
|
|
@ -18,7 +18,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
|||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
|
||||
import android.database.sqlite.SQLiteDiskIOException;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -262,7 +261,7 @@ public class SQLiteTileSource implements ITileSource {
|
|||
return db.isDbLockedByOtherThreads();
|
||||
}
|
||||
|
||||
public byte[] getBytes(int x, int y, int zoom, long[] timeHolder) throws IOException {
|
||||
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles, long[] timeHolder) throws IOException {
|
||||
SQLiteConnection db = getDatabase();
|
||||
if(db == null){
|
||||
return null;
|
||||
|
@ -294,8 +293,9 @@ public class SQLiteTileSource implements ITileSource {
|
|||
}
|
||||
}
|
||||
|
||||
public byte[] getBytes(int x, int y, int zoom) throws IOException {
|
||||
return getBytes(x, y, zoom, null);
|
||||
@Override
|
||||
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException {
|
||||
return getBytes(x, y, zoom, dirWithTiles, null);
|
||||
}
|
||||
|
||||
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
|
||||
|
@ -306,7 +306,7 @@ public class SQLiteTileSource implements ITileSource {
|
|||
String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
|
||||
byte[] blob;
|
||||
try {
|
||||
blob = getBytes(x, y, zoom, timeHolder);
|
||||
blob = getBytes(x, y, zoom, null, timeHolder);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package net.osmand.plus.render;
|
||||
|
||||
import net.osmand.core.android.MapRendererView;
|
||||
import net.osmand.core.android.TileSourceProxyProvider;
|
||||
import net.osmand.core.jni.PointI;
|
||||
import net.osmand.data.QuadPointDouble;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
@ -20,17 +24,17 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
private OsmandMapTileView view;
|
||||
private ResourceManager resourceManager;
|
||||
private Paint paintImg;
|
||||
|
||||
|
||||
private RectF destImage = new RectF();
|
||||
private final MapTileLayer tileLayer;
|
||||
private boolean visible = false;
|
||||
private boolean oldRender = false;
|
||||
|
||||
public MapVectorLayer(MapTileLayer tileLayer, boolean oldRender){
|
||||
private String cachedUnderlay;
|
||||
|
||||
public MapVectorLayer(MapTileLayer tileLayer, boolean oldRender) {
|
||||
this.tileLayer = tileLayer;
|
||||
this.oldRender = oldRender;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
@ -49,43 +53,39 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
paintImg.setFilterBitmap(true);
|
||||
paintImg.setAlpha(getAlpha());
|
||||
}
|
||||
|
||||
|
||||
public boolean isVectorDataVisible() {
|
||||
return visible && view.getZoom() >= view.getSettings().LEVEL_TO_SWITCH_VECTOR_RASTER.get();
|
||||
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){
|
||||
if (!visible) {
|
||||
resourceManager.getRenderer().clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaximumShownMapZoom() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMinimumShownMapZoom() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect,
|
||||
DrawSettings drawSettings) {
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
|
@ -96,10 +96,23 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
final MapRendererView mapRenderer = view.getMapRenderer();
|
||||
if (mapRenderer != null && !oldRender) {
|
||||
NativeCoreContext.getMapRendererContext().setNightMode(drawSettings.isNightMode());
|
||||
OsmandSettings st = view.getApplication().getSettings();
|
||||
if (!Algorithms.objectEquals(st.MAP_UNDERLAY.get(), cachedUnderlay)) {
|
||||
cachedUnderlay = st.MAP_UNDERLAY.get();
|
||||
ITileSource tileSource = st.getTileSourceByName(cachedUnderlay, false);
|
||||
if (tileSource != null) {
|
||||
TileSourceProxyProvider prov = new TileSourceProxyProvider(view.getApplication(), tileSource);
|
||||
mapRenderer.setMapLayerProvider(-1, prov.instantiateProxy(true));
|
||||
prov.swigReleaseOwnership();
|
||||
} else {
|
||||
mapRenderer.resetMapLayerProvider(-1);
|
||||
}
|
||||
}
|
||||
// opengl renderer
|
||||
mapRenderer.setTarget(new PointI(tilesRect.getCenter31X(), tilesRect.getCenter31Y()));
|
||||
mapRenderer.setAzimuth(-tilesRect.getRotate());
|
||||
mapRenderer.setZoom((float) (tilesRect.getZoom() /*+ tilesRect.getZoomScale() */+ tilesRect.getZoomAnimation()));
|
||||
mapRenderer.setZoom((float) (tilesRect.getZoom() /* + tilesRect.getZoomScale() */+ tilesRect
|
||||
.getZoomAnimation()));
|
||||
} else {
|
||||
if (!view.isZooming()) {
|
||||
if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings)) {
|
||||
|
@ -122,7 +135,7 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) {
|
||||
boolean shown = false;
|
||||
if (bmp != null && bmpLoc != null) {
|
||||
float rot = - bmpLoc.getRotate();
|
||||
float rot = -bmpLoc.getRotate();
|
||||
int cz = currentViewport.getZoom();
|
||||
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
|
||||
final RotatedTileBox calc = currentViewport.copy();
|
||||
|
@ -134,7 +147,7 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
final float y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
|
||||
final float y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
|
||||
destImage.set(x1, y1, x2, y2);
|
||||
if(!bmp.isRecycled()){
|
||||
if (!bmp.isRecycled()) {
|
||||
canvas.drawBitmap(bmp, null, destImage, paintImg);
|
||||
shown = true;
|
||||
}
|
||||
|
@ -143,15 +156,14 @@ public class MapVectorLayer extends BaseMapLayer {
|
|||
return shown;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
super.setAlpha(alpha);
|
||||
if (paintImg != null) {
|
||||
paintImg.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue