Add beanshell use. Use new optional field RULE in table INFO. Value "beanshell" makes to use interpreter for processing of a script which put into the field URL. If there is no field RULE or its value differs from "beanshell", content of the field URL used as before.
This commit is contained in:
parent
e96d0a05a1
commit
cd3dc04880
2 changed files with 24 additions and 4 deletions
|
@ -30,7 +30,7 @@ import bsh.Interpreter;
|
||||||
|
|
||||||
public class TileSourceManager {
|
public class TileSourceManager {
|
||||||
private static final Log log = PlatformUtil.getLog(TileSourceManager.class);
|
private static final Log log = PlatformUtil.getLog(TileSourceManager.class);
|
||||||
private static final String RULE_BEANSHELL = "beanshell";
|
public static final String RULE_BEANSHELL = "beanshell";
|
||||||
public static final String RULE_YANDEX_TRAFFIC = "yandex_traffic";
|
public static final String RULE_YANDEX_TRAFFIC = "yandex_traffic";
|
||||||
private static final String RULE_WMS = "wms_tile";
|
private static final String RULE_WMS = "wms_tile";
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
import net.osmand.map.TileSourceManager;
|
||||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
|
@ -19,6 +20,7 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import bsh.Interpreter;
|
||||||
import android.database.sqlite.SQLiteDiskIOException;
|
import android.database.sqlite.SQLiteDiskIOException;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -33,7 +35,7 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
private ITileSource base;
|
private ITileSource base;
|
||||||
private String urlTemplate = null;
|
private String urlTemplate = null;
|
||||||
private String name;
|
private String name;
|
||||||
private SQLiteConnection db;
|
private SQLiteConnection db = null;
|
||||||
private final File file;
|
private final File file;
|
||||||
private int minZoom = 1;
|
private int minZoom = 1;
|
||||||
private int maxZoom = 17;
|
private int maxZoom = 17;
|
||||||
|
@ -41,6 +43,7 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
private boolean timeSupported = false;
|
private boolean timeSupported = false;
|
||||||
private int expirationTimeMillis = -1; // never
|
private int expirationTimeMillis = -1; // never
|
||||||
private boolean isEllipsoid = false;
|
private boolean isEllipsoid = false;
|
||||||
|
private String rule = null;
|
||||||
|
|
||||||
static final int tileSize = 256;
|
static final int tileSize = 256;
|
||||||
private OsmandApplication ctx;
|
private OsmandApplication ctx;
|
||||||
|
@ -101,6 +104,7 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
return base != null ? base.getTileSize() : tileSize;
|
return base != null ? base.getTileSize() : tileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Interpreter bshInterpreter = null;
|
||||||
@Override
|
@Override
|
||||||
public String getUrlToLoad(int x, int y, int zoom) {
|
public String getUrlToLoad(int x, int y, int zoom) {
|
||||||
if (zoom > maxZoom)
|
if (zoom > maxZoom)
|
||||||
|
@ -109,8 +113,23 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
if(db == null || db.isReadOnly() || urlTemplate == null){
|
if(db == null || db.isReadOnly() || urlTemplate == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)){
|
||||||
|
try {
|
||||||
|
if(bshInterpreter == null){
|
||||||
|
bshInterpreter = new Interpreter();
|
||||||
|
bshInterpreter.eval(urlTemplate);
|
||||||
|
}
|
||||||
|
return (String) bshInterpreter.eval("getTileUrl("+zoom+","+x+","+y+");");
|
||||||
|
} catch (bsh.EvalError e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
@ -414,6 +433,7 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeDB(){
|
public void closeDB(){
|
||||||
|
bshInterpreter = null;
|
||||||
if(db != null){
|
if(db != null){
|
||||||
db.close();
|
db.close();
|
||||||
db = null;
|
db = null;
|
||||||
|
|
Loading…
Reference in a new issue