Merge pull request #8886 from osmandapp/osf_fixes

OSF plugin fixes
This commit is contained in:
vshcherb 2020-05-04 14:11:48 +02:00 committed by GitHub
commit 69bdb9926a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 18 deletions

View file

@ -67,6 +67,7 @@ public class TileSourceManager {
private String randoms; private String randoms;
private String[] randomsArray; private String[] randomsArray;
private String rule; private String rule;
private String referer;
private boolean hidden; // if hidden in configure map settings, for example mapillary sources private boolean hidden; // if hidden in configure map settings, for example mapillary sources
private boolean isRuleAcceptable = true; private boolean isRuleAcceptable = true;
@ -253,7 +254,11 @@ public class TileSourceManager {
} }
public String getReferer() { public String getReferer() {
return null; return referer;
}
public void setReferer(String referer) {
this.referer = referer;
} }
@Override @Override
@ -469,12 +474,16 @@ public class TileSourceManager {
public static void createMetaInfoFile(File dir, TileSourceTemplate tm, boolean override) throws IOException { public static void createMetaInfoFile(File dir, TileSourceTemplate tm, boolean override) throws IOException {
File metainfo = new File(dir, ".metainfo"); //$NON-NLS-1$ File metainfo = new File(dir, ".metainfo"); //$NON-NLS-1$
Map<String, String> properties = new LinkedHashMap<String, String>(); Map<String, String> properties = new LinkedHashMap<String, String>();
if (tm.getRule() != null && tm.getRule().length() > 0) {
if (!Algorithms.isEmpty(tm.getRule())) {
properties.put("rule", tm.getRule()); properties.put("rule", tm.getRule());
} }
if(tm.getUrlTemplate() != null) { if(tm.getUrlTemplate() != null) {
properties.put("url_template", tm.getUrlTemplate()); properties.put("url_template", tm.getUrlTemplate());
} }
if (!Algorithms.isEmpty(tm.getReferer())) {
properties.put("referer", tm.getReferer());
}
properties.put("ext", tm.getTileFormat()); properties.put("ext", tm.getTileFormat());
properties.put("min_zoom", tm.getMinimumZoomSupported() + ""); properties.put("min_zoom", tm.getMinimumZoomSupported() + "");

View file

@ -14,7 +14,6 @@ import net.osmand.JsonUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.plus.SettingsHelper.AvoidRoadsSettingsItem; import net.osmand.plus.SettingsHelper.AvoidRoadsSettingsItem;
import net.osmand.plus.SettingsHelper.MapSourcesSettingsItem; import net.osmand.plus.SettingsHelper.MapSourcesSettingsItem;
@ -266,17 +265,20 @@ public class CustomOsmandPlugin extends OsmandPlugin {
List<ITileSource> mapSources = mapSourcesSettingsItem.getItems(); List<ITileSource> mapSources = mapSourcesSettingsItem.getItems();
for (ITileSource tileSource : mapSources) { for (ITileSource tileSource : mapSources) {
if (tileSource instanceof TileSourceManager.TileSourceTemplate) { String tileSourceName = tileSource.getName();
TileSourceManager.TileSourceTemplate sourceTemplate = (TileSourceManager.TileSourceTemplate) tileSource; if (tileSource instanceof SQLiteTileSource) {
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); tileSourceName += SQLITE_EXT;
File dir = new File(tPath, sourceTemplate.getName()); }
Algorithms.removeAllFiles(dir);
} else if (tileSource instanceof SQLiteTileSource) { ITileSource savedTileSource = app.getSettings().getTileSourceByName(tileSourceName, false);
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) tileSource); if (savedTileSource != null) {
if (savedTileSource instanceof SQLiteTileSource) {
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) savedTileSource);
sqLiteTileSource.closeDB(); sqLiteTileSource.closeDB();
}
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, sqLiteTileSource.getName() + SQLITE_EXT); File dir = new File(tPath, tileSourceName);
Algorithms.removeAllFiles(dir); Algorithms.removeAllFiles(dir);
} }
} }

View file

@ -92,7 +92,7 @@ public class SQLiteTileSource implements ITileSource {
public SQLiteTileSource(OsmandApplication ctx, String name, int minZoom, int maxZoom, String urlTemplate, public SQLiteTileSource(OsmandApplication ctx, String name, int minZoom, int maxZoom, String urlTemplate,
String randoms, boolean isEllipsoid, boolean invertedY, String referer, String randoms, boolean isEllipsoid, boolean invertedY, String referer,
boolean timeSupported, long expirationTimeMillis, boolean inversiveZoom) { boolean timeSupported, long expirationTimeMillis, boolean inversiveZoom, String rule) {
this.ctx = ctx; this.ctx = ctx;
this.name = name; this.name = name;
this.urlTemplate = urlTemplate; this.urlTemplate = urlTemplate;
@ -102,6 +102,7 @@ public class SQLiteTileSource implements ITileSource {
this.expirationTimeMillis = expirationTimeMillis; this.expirationTimeMillis = expirationTimeMillis;
this.randoms = randoms; this.randoms = randoms;
this.referer = referer; this.referer = referer;
this.rule = rule;
this.invertedY = invertedY; this.invertedY = invertedY;
this.timeSupported = timeSupported; this.timeSupported = timeSupported;
this.inversiveZoom = inversiveZoom; this.inversiveZoom = inversiveZoom;

View file

@ -16,6 +16,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
@ -2005,8 +2006,8 @@ public class SettingsHelper {
boolean ellipsoid = object.optBoolean("ellipsoid", false); boolean ellipsoid = object.optBoolean("ellipsoid", false);
boolean invertedY = object.optBoolean("inverted_y", false); boolean invertedY = object.optBoolean("inverted_y", false);
String referer = object.optString("referer"); String referer = object.optString("referer");
boolean timesupported = object.optBoolean("timesupported", false); boolean timeSupported = object.optBoolean("timesupported", false);
long expire = object.optLong("expire"); long expire = object.optLong("expire", -1);
boolean inversiveZoom = object.optBoolean("inversiveZoom", false); boolean inversiveZoom = object.optBoolean("inversiveZoom", false);
String ext = object.optString("ext"); String ext = object.optString("ext");
int tileSize = object.optInt("tileSize"); int tileSize = object.optInt("tileSize");
@ -2014,11 +2015,23 @@ public class SettingsHelper {
int avgSize = object.optInt("avgSize"); int avgSize = object.optInt("avgSize");
String rule = object.optString("rule"); String rule = object.optString("rule");
if (expire > 0 && expire < 3600000) {
expire = expire * 60 * 1000L;
}
ITileSource template; ITileSource template;
if (!sql) { if (!sql) {
template = new TileSourceManager.TileSourceTemplate(name, url, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize); TileSourceTemplate tileSourceTemplate = new TileSourceTemplate(name, url, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize);
tileSourceTemplate.setRule(rule);
tileSourceTemplate.setRandoms(randoms);
tileSourceTemplate.setReferer(referer);
tileSourceTemplate.setEllipticYTile(ellipsoid);
tileSourceTemplate.setInvertedYTile(invertedY);
tileSourceTemplate.setExpirationTimeMillis(timeSupported ? expire : -1);
template = tileSourceTemplate;
} else { } else {
template = new SQLiteTileSource(app, name, minZoom, maxZoom, url, randoms, ellipsoid, invertedY, referer, timesupported, expire, inversiveZoom); template = new SQLiteTileSource(app, name, minZoom, maxZoom, url, randoms, ellipsoid, invertedY, referer, timeSupported, expire, inversiveZoom, rule);
} }
items.add(template); items.add(template);
} }
@ -2046,7 +2059,7 @@ public class SettingsHelper {
jsonObject.put("inverted_y", template.isInvertedYTile()); jsonObject.put("inverted_y", template.isInvertedYTile());
jsonObject.put("referer", template.getReferer()); jsonObject.put("referer", template.getReferer());
jsonObject.put("timesupported", template.isTimeSupported()); jsonObject.put("timesupported", template.isTimeSupported());
jsonObject.put("expire", template.getExpirationTimeMillis()); jsonObject.put("expire", template.getExpirationTimeMinutes());
jsonObject.put("inversiveZoom", template.getInversiveZoom()); jsonObject.put("inversiveZoom", template.getInversiveZoom());
jsonObject.put("ext", template.getTileFormat()); jsonObject.put("ext", template.getTileFormat());
jsonObject.put("tileSize", template.getTileSize()); jsonObject.put("tileSize", template.getTileSize());