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 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();
|
public int getMinimumZoomSupported();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.map;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -18,6 +19,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -215,6 +217,27 @@ public class TileSourceManager {
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
return rule;
|
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) {
|
private static Map<String, String> readMetaInfoFile(File dir) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.core.android;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.core.jni.AlphaChannelPresence;
|
import net.osmand.core.jni.AlphaChannelPresence;
|
||||||
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
|
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
|
||||||
import net.osmand.core.jni.SwigUtilities;
|
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.ZoomLevel;
|
||||||
import net.osmand.core.jni.interface_ImageMapLayerProvider;
|
import net.osmand.core.jni.interface_ImageMapLayerProvider;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
|
||||||
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||||
|
|
||||||
|
private final OsmandApplication app;
|
||||||
private final ITileSource tileSource;
|
private final ITileSource tileSource;
|
||||||
|
|
||||||
public TileSourceProxyProvider(ITileSource tileSource) {
|
public TileSourceProxyProvider(OsmandApplication app, ITileSource tileSource) {
|
||||||
|
this.app = app;
|
||||||
this.tileSource = tileSource;
|
this.tileSource = tileSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +36,8 @@ public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
|
||||||
public SWIGTYPE_p_QByteArray obtainImage(TileId tileId, ZoomLevel zoom) {
|
public SWIGTYPE_p_QByteArray obtainImage(TileId tileId, ZoomLevel zoom) {
|
||||||
byte[] image;
|
byte[] image;
|
||||||
try {
|
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) {
|
} catch(IOException e) {
|
||||||
return SwigUtilities.emptyQByteArray();
|
return SwigUtilities.emptyQByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
import net.osmand.data.LatLon;
|
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.render.RendererRegistry;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
|
@ -990,7 +990,7 @@ public class OsmandSettings {
|
||||||
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal();
|
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal();
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// 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
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final CommonPreference<Integer> MAP_OVERLAY_TRANSPARENCY = new IntPreference("overlay_transparency",
|
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
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final CommonPreference<Integer> MAP_TRANSPARENCY = new IntPreference("map_transparency",
|
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
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final CommonPreference<String> MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
|
public final CommonPreference<String> MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
|
||||||
|
@ -1158,6 +1158,7 @@ public class OsmandSettings {
|
||||||
return writableSecondaryStorage;
|
return writableSecondaryStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
public String getMatchingExternalFilesDir(String dir) {
|
public String getMatchingExternalFilesDir(String dir) {
|
||||||
// only API 19 !!
|
// only API 19 !!
|
||||||
try {
|
try {
|
||||||
|
@ -1181,6 +1182,7 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
public List<String> getWritableSecondaryStorageDirectorys() {
|
public List<String> getWritableSecondaryStorageDirectorys() {
|
||||||
// only API 19 !!
|
// only API 19 !!
|
||||||
// primary external storage directory
|
// primary external storage directory
|
||||||
|
|
|
@ -18,7 +18,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.http.client.protocol.ClientContext;
|
|
||||||
|
|
||||||
import android.database.sqlite.SQLiteDiskIOException;
|
import android.database.sqlite.SQLiteDiskIOException;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
@ -262,7 +261,7 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
return db.isDbLockedByOtherThreads();
|
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();
|
SQLiteConnection db = getDatabase();
|
||||||
if(db == null){
|
if(db == null){
|
||||||
return null;
|
return null;
|
||||||
|
@ -294,8 +293,9 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes(int x, int y, int zoom) throws IOException {
|
@Override
|
||||||
return getBytes(x, y, zoom, null);
|
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) {
|
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) + "" };
|
String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
|
||||||
byte[] blob;
|
byte[] blob;
|
||||||
try {
|
try {
|
||||||
blob = getBytes(x, y, zoom, timeHolder);
|
blob = getBytes(x, y, zoom, null, timeHolder);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package net.osmand.plus.render;
|
package net.osmand.plus.render;
|
||||||
|
|
||||||
import net.osmand.core.android.MapRendererView;
|
import net.osmand.core.android.MapRendererView;
|
||||||
|
import net.osmand.core.android.TileSourceProxyProvider;
|
||||||
import net.osmand.core.jni.PointI;
|
import net.osmand.core.jni.PointI;
|
||||||
import net.osmand.data.QuadPointDouble;
|
import net.osmand.data.QuadPointDouble;
|
||||||
import net.osmand.data.RotatedTileBox;
|
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.resources.ResourceManager;
|
||||||
import net.osmand.plus.views.BaseMapLayer;
|
import net.osmand.plus.views.BaseMapLayer;
|
||||||
import net.osmand.plus.views.MapTileLayer;
|
import net.osmand.plus.views.MapTileLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
@ -25,13 +29,13 @@ public class MapVectorLayer extends BaseMapLayer {
|
||||||
private final MapTileLayer tileLayer;
|
private final MapTileLayer tileLayer;
|
||||||
private boolean visible = false;
|
private boolean visible = false;
|
||||||
private boolean oldRender = false;
|
private boolean oldRender = false;
|
||||||
|
private String cachedUnderlay;
|
||||||
|
|
||||||
public MapVectorLayer(MapTileLayer tileLayer, boolean oldRender){
|
public MapVectorLayer(MapTileLayer tileLayer, boolean oldRender) {
|
||||||
this.tileLayer = tileLayer;
|
this.tileLayer = tileLayer;
|
||||||
this.oldRender = oldRender;
|
this.oldRender = oldRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyLayer() {
|
public void destroyLayer() {
|
||||||
}
|
}
|
||||||
|
@ -51,17 +55,16 @@ public class MapVectorLayer extends BaseMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVectorDataVisible() {
|
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() {
|
public boolean isVisible() {
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
if(!visible){
|
if (!visible) {
|
||||||
resourceManager.getRenderer().clearCache();
|
resourceManager.getRenderer().clearCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,16 +79,13 @@ public class MapVectorLayer extends BaseMapLayer {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
|
public void onDraw(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect,
|
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
|
||||||
DrawSettings drawSettings) {
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,23 @@ public class MapVectorLayer extends BaseMapLayer {
|
||||||
final MapRendererView mapRenderer = view.getMapRenderer();
|
final MapRendererView mapRenderer = view.getMapRenderer();
|
||||||
if (mapRenderer != null && !oldRender) {
|
if (mapRenderer != null && !oldRender) {
|
||||||
NativeCoreContext.getMapRendererContext().setNightMode(drawSettings.isNightMode());
|
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
|
// opengl renderer
|
||||||
mapRenderer.setTarget(new PointI(tilesRect.getCenter31X(), tilesRect.getCenter31Y()));
|
mapRenderer.setTarget(new PointI(tilesRect.getCenter31X(), tilesRect.getCenter31Y()));
|
||||||
mapRenderer.setAzimuth(-tilesRect.getRotate());
|
mapRenderer.setAzimuth(-tilesRect.getRotate());
|
||||||
mapRenderer.setZoom((float) (tilesRect.getZoom() /*+ tilesRect.getZoomScale() */+ tilesRect.getZoomAnimation()));
|
mapRenderer.setZoom((float) (tilesRect.getZoom() /* + tilesRect.getZoomScale() */+ tilesRect
|
||||||
|
.getZoomAnimation()));
|
||||||
} else {
|
} else {
|
||||||
if (!view.isZooming()) {
|
if (!view.isZooming()) {
|
||||||
if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings)) {
|
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) {
|
private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) {
|
||||||
boolean shown = false;
|
boolean shown = false;
|
||||||
if (bmp != null && bmpLoc != null) {
|
if (bmp != null && bmpLoc != null) {
|
||||||
float rot = - bmpLoc.getRotate();
|
float rot = -bmpLoc.getRotate();
|
||||||
int cz = currentViewport.getZoom();
|
int cz = currentViewport.getZoom();
|
||||||
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
|
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
|
||||||
final RotatedTileBox calc = currentViewport.copy();
|
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 y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
|
||||||
final float y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
|
final float y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
|
||||||
destImage.set(x1, y1, x2, y2);
|
destImage.set(x1, y1, x2, y2);
|
||||||
if(!bmp.isRecycled()){
|
if (!bmp.isRecycled()) {
|
||||||
canvas.drawBitmap(bmp, null, destImage, paintImg);
|
canvas.drawBitmap(bmp, null, destImage, paintImg);
|
||||||
shown = true;
|
shown = true;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +156,6 @@ public class MapVectorLayer extends BaseMapLayer {
|
||||||
return shown;
|
return shown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAlpha(int alpha) {
|
public void setAlpha(int alpha) {
|
||||||
super.setAlpha(alpha);
|
super.setAlpha(alpha);
|
||||||
|
|
Loading…
Reference in a new issue