Align old poi db index usage with new index usage
This commit is contained in:
parent
b082e6ff00
commit
dd95a862ee
9 changed files with 264 additions and 164 deletions
|
@ -221,7 +221,8 @@ public class BinaryMapPoiReaderAdapter {
|
|||
case OsmandOdb.OsmAndPoiNameIndex.TABLE_FIELD_NUMBER : {
|
||||
int length = readInt();
|
||||
int oldLimit = codedIS.pushLimit(length);
|
||||
dataOffsets = readIndexedStringTable(instance, query);
|
||||
dataOffsets = new TIntArrayList();
|
||||
readIndexedStringTable(instance, query, "", dataOffsets, 0);
|
||||
codedIS.popLimit(oldLimit);
|
||||
break; }
|
||||
case OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER : {
|
||||
|
@ -297,40 +298,59 @@ public class BinaryMapPoiReaderAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
private TIntArrayList readIndexedStringTable(Collator instance, String query) throws IOException {
|
||||
// TODO support fully functional indexed string table
|
||||
TIntArrayList list = new TIntArrayList();
|
||||
int charMatches = 0;
|
||||
boolean keyMatches = false;
|
||||
private int readIndexedStringTable(Collator instance, String query, String prefix, TIntArrayList list, int charMatches) throws IOException {
|
||||
String key = null;
|
||||
while(true){
|
||||
int t = codedIS.readTag();
|
||||
int tag = WireFormat.getTagFieldNumber(t);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return list;
|
||||
return charMatches;
|
||||
case OsmandOdb.IndexedStringTable.KEY_FIELD_NUMBER :
|
||||
String key = codedIS.readString();
|
||||
keyMatches = false;
|
||||
int i=0;
|
||||
for(; i<query.length(); i++){
|
||||
if (i >= key.length() || instance.compare(key.substring(i, i + 1), query.substring(i, i + 1)) != 0) {
|
||||
break;
|
||||
}
|
||||
key = codedIS.readString();
|
||||
if(prefix.length() > 0){
|
||||
key = prefix + key;
|
||||
}
|
||||
if(i >= charMatches && i > 0){
|
||||
if(i > charMatches){
|
||||
list.clear();
|
||||
charMatches = i;
|
||||
// check query is part of key (the best matching)
|
||||
if(CollatorStringMatcher.cmatches(instance, key, query, StringMatcherMode.CHECK_ONLY_STARTS_WITH)){
|
||||
if(query.length() >= charMatches){
|
||||
if(query.length() > charMatches){
|
||||
charMatches = key.length();
|
||||
list.clear();
|
||||
}
|
||||
} else {
|
||||
key = null;
|
||||
}
|
||||
keyMatches = true;
|
||||
// check key is part of query
|
||||
} else if (CollatorStringMatcher.cmatches(instance, query, key, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
|
||||
if (key.length() >= charMatches) {
|
||||
if (key.length() > charMatches) {
|
||||
charMatches = key.length();
|
||||
list.clear();
|
||||
}
|
||||
} else {
|
||||
key = null;
|
||||
}
|
||||
} else {
|
||||
key = null;
|
||||
}
|
||||
break;
|
||||
case OsmandOdb.IndexedStringTable.VAL_FIELD_NUMBER :
|
||||
int val = codedIS.readUInt32();
|
||||
if (keyMatches) {
|
||||
if (key != null) {
|
||||
list.add(val);
|
||||
}
|
||||
break;
|
||||
case OsmandOdb.IndexedStringTable.SUBTABLES_FIELD_NUMBER :
|
||||
int len = codedIS.readRawVarint32();
|
||||
int oldLim = codedIS.pushLimit(len);
|
||||
if (key != null) {
|
||||
charMatches = readIndexedStringTable(instance, query, key, list, charMatches);
|
||||
} else {
|
||||
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
|
||||
}
|
||||
codedIS.popLimit(oldLim);
|
||||
break;
|
||||
default:
|
||||
skipUnknownField(t);
|
||||
break;
|
||||
|
|
|
@ -557,9 +557,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
|||
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
|
||||
// TODO support multiple reading amenity types! +/-
|
||||
// TODO support proper POI editing
|
||||
// TODO support string trigramms
|
||||
// TODO support cancelling poi search request! Do it in another thread (Check is cancelled()!!!)
|
||||
// TODO support fully functional indexed string table and pass name matcher
|
||||
long time = System.currentTimeMillis();
|
||||
IndexPoiCreator poiCreator = new IndexPoiCreator();
|
||||
// String fileSqlte = "/home/victor/projects/OsmAnd/data/osm-gen/POI/Ru-mow.poi.odb";
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
<resources>
|
||||
<string name="button_upgrade_osmandplus">Upgrade Osmand+</string>
|
||||
<string name="map_version_changed_info">On server are map files incompatible with your current version of application. To download and use them, please upgrade the application to newer version.</string>
|
||||
<string name="old_poi_file_should_be_deleted">The poi data file \'%1$s\' is deprecated and can be deleted.</string>
|
||||
<string name="update_poi_file_not_found">Local file to maintain poi changes not found and could not be created.</string>
|
||||
<string name="update_poi_does_not_change_indexes">Changing poi inside application doesn\'t affect map files you downloaded but collects all changes in local file.</string>
|
||||
|
||||
<string name="local_index_mi_rename">Rename</string>
|
||||
<string name="show_gpx_route">Show on map</string>
|
||||
<string name="poi_filter_nominatim">Online Nominatim</string>
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
|
||||
public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Amenity> implements AmenityIndexRepository {
|
||||
|
@ -91,37 +92,6 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
|||
return amenities;
|
||||
}
|
||||
|
||||
public boolean addAmenity(Amenity a){
|
||||
insertAmenities(Collections.singleton(a));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateAmenity(Amenity a){
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("UPDATE " + IndexConstants.POI_TABLE + " SET "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
b.append(" x = ?, "). //$NON-NLS-1$
|
||||
append(" y = ?, "). //$NON-NLS-1$
|
||||
append(" opening_hours = ?, "). //$NON-NLS-1$
|
||||
append(" name = ?, "). //$NON-NLS-1$
|
||||
append(" name_en = ?, ").//$NON-NLS-1$
|
||||
append(" type = ?, "). //$NON-NLS-1$
|
||||
append(" subtype = ? "). //$NON-NLS-1$
|
||||
append(" site = ? "). //$NON-NLS-1$
|
||||
append(" phone = ? "). //$NON-NLS-1$
|
||||
append(" WHERE append( id = ?"); //$NON-NLS-1$
|
||||
|
||||
db.execSQL(b.toString(),
|
||||
new Object[] { MapUtils.get31TileNumberX(a.getLocation().getLongitude()), MapUtils.get31TileNumberY(a.getLocation().getLatitude()),
|
||||
a.getOpeningHours(), a.getName(), a.getEnName(), AmenityType.valueToString(a.getType()), a.getSubType(),
|
||||
a.getSite(), a.getPhone(), a.getId()});
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean deleteAmenities(long id){
|
||||
db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void clearCache(){
|
||||
super.clearCache();
|
||||
|
@ -176,6 +146,37 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
|||
return super.initialize(progress, file, IndexConstants.POI_TABLE_VERSION, IndexConstants.POI_TABLE, true);
|
||||
}
|
||||
|
||||
// Update functionality
|
||||
public boolean addAmenity(Amenity a){
|
||||
insertAmenities(Collections.singleton(a));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateAmenity(Amenity a){
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("UPDATE " + IndexConstants.POI_TABLE + " SET "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
b.append(" x = ?, "). //$NON-NLS-1$
|
||||
append(" y = ?, "). //$NON-NLS-1$
|
||||
append(" opening_hours = ?, "). //$NON-NLS-1$
|
||||
append(" name = ?, "). //$NON-NLS-1$
|
||||
append(" name_en = ?, ").//$NON-NLS-1$
|
||||
append(" type = ?, "). //$NON-NLS-1$
|
||||
append(" subtype = ? "). //$NON-NLS-1$
|
||||
append(" site = ? "). //$NON-NLS-1$
|
||||
append(" phone = ? "). //$NON-NLS-1$
|
||||
append(" WHERE append( id = ?"); //$NON-NLS-1$
|
||||
|
||||
db.execSQL(b.toString(),
|
||||
new Object[] { MapUtils.get31TileNumberX(a.getLocation().getLongitude()), MapUtils.get31TileNumberY(a.getLocation().getLatitude()),
|
||||
a.getOpeningHours(), a.getName(), a.getEnName(), AmenityType.valueToString(a.getType()), a.getSubType(),
|
||||
a.getSite(), a.getPhone(), a.getId()});
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean deleteAmenities(long id){
|
||||
db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateAmenities(List<Amenity> amenities, double leftLon, double topLat, double rightLon, double bottomLat){
|
||||
|
@ -204,6 +205,10 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
|||
stat.bindLong(1, a.getId());
|
||||
stat.bindDouble(2, MapUtils.get31TileNumberX(a.getLocation().getLongitude()));
|
||||
stat.bindDouble(3, MapUtils.get31TileNumberY(a.getLocation().getLatitude()));
|
||||
dataBottomLatitude = Math.min(a.getLocation().getLatitude(), dataBottomLatitude);
|
||||
dataTopLatitude = Math.max(a.getLocation().getLatitude(), dataTopLatitude);
|
||||
dataLeftLongitude = Math.min(a.getLocation().getLongitude(), dataLeftLongitude);
|
||||
dataRightLongitude = Math.max(a.getLocation().getLongitude(), dataRightLongitude);
|
||||
bindString(stat, 4, a.getEnName());
|
||||
bindString(stat, 5, a.getName());
|
||||
bindString(stat, 6, AmenityType.valueToString(a.getType()));
|
||||
|
@ -214,10 +219,24 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
|
|||
stat.execute();
|
||||
}
|
||||
stat.close();
|
||||
updateMaxMinBoundaries(IndexConstants.POI_TABLE);
|
||||
|
||||
}
|
||||
|
||||
private final static String SITE_API = "http://api.openstreetmap.org/"; //$NON-NLS-1$
|
||||
|
||||
public static void createAmenityIndexRepository(File file) {
|
||||
SQLiteDatabase db = SQLiteDatabase.openDatabase(file.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY);
|
||||
db.execSQL("create table " + IndexConstants.POI_TABLE + //$NON-NLS-1$
|
||||
"(id bigint, x int, y int, name_en varchar(1024), name varchar(1024), "
|
||||
+ "type varchar(1024), subtype varchar(1024), opening_hours varchar(1024), phone varchar(1024), site varchar(1024),"
|
||||
+ "primary key(id, type, subtype))");
|
||||
db.execSQL("create index poi_loc on poi (x, y, type, subtype)");
|
||||
db.execSQL("create index poi_id on poi (id, type, subtype)");
|
||||
db.setVersion(IndexConstants.POI_TABLE_VERSION);
|
||||
db.close();
|
||||
}
|
||||
|
||||
public static boolean loadingPOIs(List<Amenity> amenities, double leftLon, double topLat, double righLon, double bottomLat) {
|
||||
try {
|
||||
// bbox=left,bottom,right,top
|
||||
|
|
|
@ -44,6 +44,10 @@ public class BaseLocationIndexRepository<T extends MapObject> {
|
|||
cZoom = 0;
|
||||
}
|
||||
|
||||
protected String getMetaLocation(String tableLocation) {
|
||||
return "loc_meta_" + tableLocation;
|
||||
}
|
||||
|
||||
public boolean initialize(final IProgress progress, File file, int version, String tableLocation, boolean searchX31) {
|
||||
long start = System.currentTimeMillis();
|
||||
if(db != null){
|
||||
|
@ -57,7 +61,7 @@ public class BaseLocationIndexRepository<T extends MapObject> {
|
|||
db = null;
|
||||
return false;
|
||||
}
|
||||
String metaTable = "loc_meta_"+tableLocation; //$NON-NLS-1$
|
||||
String metaTable = getMetaLocation(tableLocation);
|
||||
Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='"+metaTable+"'", null); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
boolean dbExist = cursor.moveToFirst();
|
||||
cursor.close();
|
||||
|
@ -109,7 +113,7 @@ public class BaseLocationIndexRepository<T extends MapObject> {
|
|||
query.close();
|
||||
}
|
||||
if (write) {
|
||||
db.execSQL("INSERT INTO " + metaTable + " VALUES (?, ?, ? ,?)", new Double[]{dataTopLatitude, dataRightLongitude, dataBottomLatitude, dataLeftLongitude}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
updateMaxMinBoundaries(tableLocation);
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
|
@ -118,6 +122,12 @@ public class BaseLocationIndexRepository<T extends MapObject> {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void updateMaxMinBoundaries(String tableLocation){
|
||||
String metatable = getMetaLocation(tableLocation);
|
||||
db.execSQL("DELETE FROM " + metatable + " WHERE 1= 1" ) ;
|
||||
db.execSQL("INSERT INTO " + metatable + " VALUES (?, ?, ? ,?)", new Double[]{dataTopLatitude, dataRightLongitude, dataBottomLatitude, dataLeftLongitude}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public synchronized void close() {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
|
@ -164,7 +174,7 @@ public class BaseLocationIndexRepository<T extends MapObject> {
|
|||
}
|
||||
|
||||
public boolean checkContains(double latitude, double longitude){
|
||||
if(latitude < dataTopLatitude && latitude > dataBottomLatitude && longitude > dataLeftLongitude && longitude < dataRightLongitude){
|
||||
if(latitude <= dataTopLatitude && latitude >= dataBottomLatitude && longitude >= dataLeftLongitude && longitude <= dataRightLongitude){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,68 +1,68 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.data.IndexConstants;
|
||||
import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
|
||||
|
||||
/**
|
||||
* @author Pavol Zibrita <pavol.zibrita@gmail.com>
|
||||
*/
|
||||
public class IndexFileList implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
TreeMap<String, IndexItem> indexFiles = new TreeMap<String, IndexItem>(new Comparator<String>(){
|
||||
@SuppressWarnings("unused")
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int compare(String object1, String object2) {
|
||||
if(object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
return object1.compareTo(object2);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
return 1;
|
||||
}
|
||||
return object1.compareTo(object2);
|
||||
}
|
||||
});
|
||||
|
||||
private String mapversion;
|
||||
|
||||
public IndexFileList() {
|
||||
}
|
||||
|
||||
public void setMapVersion(String mapversion) {
|
||||
this.mapversion = mapversion;
|
||||
}
|
||||
|
||||
public void add(String name, IndexItem indexItem) {
|
||||
if (indexItem.isAccepted()) {
|
||||
indexFiles.put(name, indexItem);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAcceptable() {
|
||||
return (indexFiles != null && !indexFiles.isEmpty()) || (mapversion != null);
|
||||
}
|
||||
|
||||
public Map<String, IndexItem> getIndexFiles() {
|
||||
return indexFiles;
|
||||
}
|
||||
|
||||
public boolean isIncreasedMapVersion() {
|
||||
try {
|
||||
int mapVersionInList = Integer.parseInt(mapversion);
|
||||
return IndexConstants.BINARY_MAP_VERSION < mapVersionInList;
|
||||
} catch (NumberFormatException e) {
|
||||
//ignore this...
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package net.osmand.plus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.data.IndexConstants;
|
||||
import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
|
||||
|
||||
/**
|
||||
* @author Pavol Zibrita <pavol.zibrita@gmail.com>
|
||||
*/
|
||||
public class IndexFileList implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
TreeMap<String, IndexItem> indexFiles = new TreeMap<String, IndexItem>(new Comparator<String>(){
|
||||
@SuppressWarnings("unused")
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int compare(String object1, String object2) {
|
||||
if(object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
return object1.compareTo(object2);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
|
||||
return 1;
|
||||
}
|
||||
return object1.compareTo(object2);
|
||||
}
|
||||
});
|
||||
|
||||
private String mapversion;
|
||||
|
||||
public IndexFileList() {
|
||||
}
|
||||
|
||||
public void setMapVersion(String mapversion) {
|
||||
this.mapversion = mapversion;
|
||||
}
|
||||
|
||||
public void add(String name, IndexItem indexItem) {
|
||||
if (indexItem.isAccepted()) {
|
||||
indexFiles.put(name, indexItem);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAcceptable() {
|
||||
return (indexFiles != null && !indexFiles.isEmpty()) || (mapversion != null);
|
||||
}
|
||||
|
||||
public Map<String, IndexItem> getIndexFiles() {
|
||||
return indexFiles;
|
||||
}
|
||||
|
||||
public boolean isIncreasedMapVersion() {
|
||||
try {
|
||||
int mapVersionInList = Integer.parseInt(mapversion);
|
||||
return IndexConstants.BINARY_MAP_VERSION < mapVersionInList;
|
||||
} catch (NumberFormatException e) {
|
||||
//ignore this...
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ import android.view.WindowManager;
|
|||
* Such as indexes, tiles.
|
||||
* Also it is responsible to create cache for that resources if they
|
||||
* can't be loaded fully into memory & clear them on request.
|
||||
*SQLITE
|
||||
*/
|
||||
public class ResourceManager {
|
||||
|
||||
|
@ -72,6 +71,7 @@ public class ResourceManager {
|
|||
public static final int LIMIT_TRANSPORT = 200;
|
||||
|
||||
private static final Log log = LogUtil.getLog(ResourceManager.class);
|
||||
private static final String MINE_POI_DB = APP_DIR + "mine"+ IndexConstants.POI_INDEX_EXT;
|
||||
|
||||
|
||||
protected static ResourceManager manager = null;
|
||||
|
@ -98,6 +98,7 @@ public class ResourceManager {
|
|||
|
||||
protected final List<TransportIndexRepository> transportRepositories = new ArrayList<TransportIndexRepository>();
|
||||
|
||||
|
||||
protected final Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
|
||||
|
||||
protected final Map<String, BinaryMapIndexReader> routingMapFiles = new LinkedHashMap<String, BinaryMapIndexReader>();
|
||||
|
@ -108,6 +109,8 @@ public class ResourceManager {
|
|||
|
||||
protected boolean internetIsNotAccessible = false;
|
||||
|
||||
protected AmenityIndexRepositoryOdb updatablePoiDb = null;
|
||||
|
||||
|
||||
public ResourceManager(OsmandApplication context) {
|
||||
this.context = context;
|
||||
|
@ -355,8 +358,8 @@ public class ResourceManager {
|
|||
initRenderers(progress);
|
||||
// do it lazy
|
||||
// indexingImageTiles(progress);
|
||||
warnings.addAll(indexingPoi(progress));
|
||||
warnings.addAll(indexingMaps(progress));
|
||||
warnings.addAll(indexingPoi(progress));
|
||||
return warnings;
|
||||
}
|
||||
|
||||
|
@ -499,29 +502,82 @@ public class ResourceManager {
|
|||
}
|
||||
|
||||
// POI INDEX //
|
||||
public List<String> indexingPoi(final IProgress progress) {
|
||||
private List<String> indexingPoi(final IProgress progress) {
|
||||
File file = context.getSettings().extendOsmandPath(POI_PATH);
|
||||
file.mkdirs();
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
closeAmenities();
|
||||
if (file.exists() && file.canRead()) {
|
||||
for (File f : file.listFiles()) {
|
||||
indexingPoi(progress, warnings, f);
|
||||
}
|
||||
}
|
||||
File updatablePoiDbFile = context.getSettings().extendOsmandPath(MINE_POI_DB);
|
||||
if(updatablePoiDbFile.exists() && file.canRead()){
|
||||
try {
|
||||
AmenityIndexRepositoryOdb odb = new AmenityIndexRepositoryOdb();
|
||||
boolean initialize = odb.initialize(progress, updatablePoiDbFile);
|
||||
if(initialize){
|
||||
this.updatablePoiDb = odb;
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
}
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public AmenityIndexRepositoryOdb getUpdatablePoiDb() {
|
||||
if (updatablePoiDb == null) {
|
||||
File updatablePoiDbFile = context.getSettings().extendOsmandPath(MINE_POI_DB);
|
||||
if (!tryToOpenUpdatablePoiDb(updatablePoiDbFile)) {
|
||||
if (updatablePoiDbFile.exists()) {
|
||||
updatablePoiDbFile.delete();
|
||||
}
|
||||
AmenityIndexRepositoryOdb.createAmenityIndexRepository(updatablePoiDbFile);
|
||||
tryToOpenUpdatablePoiDb(updatablePoiDbFile);
|
||||
}
|
||||
}
|
||||
return updatablePoiDb;
|
||||
}
|
||||
|
||||
private boolean tryToOpenUpdatablePoiDb(File updatablePoiDbFile) {
|
||||
try {
|
||||
AmenityIndexRepositoryOdb odb = new AmenityIndexRepositoryOdb();
|
||||
boolean initialize = odb.initialize(IProgress.EMPTY_PROGRESS, updatablePoiDbFile);
|
||||
if (initialize) {
|
||||
amenityRepositories.add(odb);
|
||||
this.updatablePoiDb = odb;
|
||||
return true;
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void indexingPoi(final IProgress progress, List<String> warnings, File f) {
|
||||
if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
|
||||
AmenityIndexRepositoryOdb repository = new AmenityIndexRepositoryOdb();
|
||||
|
||||
progress.startTask(context.getString(R.string.indexing_poi) + " " + f.getName(), -1); //$NON-NLS-1$
|
||||
try {
|
||||
boolean initialized = repository.initialize(progress, f);
|
||||
if (initialized) {
|
||||
amenityRepositories.add(repository);
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(f.lastModified()))); //$NON-NLS-1$
|
||||
boolean covered = false;
|
||||
for(AmenityIndexRepository r : amenityRepositories){
|
||||
if(r instanceof AmenityIndexRepositoryBinary){
|
||||
double latC = (repository.dataBottomLatitude + repository.dataTopLatitude )/ 2;
|
||||
double lonC = (repository.dataLeftLongitude + repository.dataRightLongitude) / 2;
|
||||
if(r.checkContains(latC, lonC)){
|
||||
covered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(covered){
|
||||
repository.close();
|
||||
warnings.add(context.getString(R.string.old_poi_file_should_be_deleted, f.getName())); //$NON-NLS-1$
|
||||
} else {
|
||||
amenityRepositories.add(repository);
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(f.lastModified()))); //$NON-NLS-1$
|
||||
}
|
||||
} else {
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -540,16 +596,6 @@ public class ResourceManager {
|
|||
|
||||
|
||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||
public List<AmenityIndexRepository> searchAmenityRepositories(double latitude, double longitude) {
|
||||
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
|
||||
for (AmenityIndexRepository index : amenityRepositories) {
|
||||
if (index.checkContains(latitude,longitude)) {
|
||||
repos.add(index);
|
||||
}
|
||||
}
|
||||
return repos;
|
||||
}
|
||||
|
||||
public List<Amenity> searchAmenities(PoiFilter filter,
|
||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||
double lat, double lon) {
|
||||
|
@ -647,6 +693,7 @@ public class ResourceManager {
|
|||
r.close();
|
||||
}
|
||||
amenityRepositories.clear();
|
||||
updatablePoiDb = null;
|
||||
}
|
||||
|
||||
public void closeAddresses(){
|
||||
|
|
|
@ -37,7 +37,6 @@ import net.osmand.osm.OSMSettings.OSMTagKey;
|
|||
import net.osmand.osm.OpeningHoursParser.BasicDayOpeningHourRule;
|
||||
import net.osmand.osm.OpeningHoursParser.OpeningHoursRule;
|
||||
import net.osmand.osm.io.OsmBaseStorage;
|
||||
import net.osmand.plus.AmenityIndexRepository;
|
||||
import net.osmand.plus.AmenityIndexRepositoryOdb;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -110,6 +109,7 @@ public class EditingPOIActivity {
|
|||
|
||||
private final static Log log = LogUtil.getLog(EditingPOIActivity.class);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -608,26 +608,31 @@ public class EditingPOIActivity {
|
|||
}
|
||||
|
||||
private void updateNodeInIndexes(String action, Node n) {
|
||||
List<AmenityIndexRepository> repos = app.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude());
|
||||
// delete all amenities with same id
|
||||
if (DELETE_ACTION.equals(action) || MODIFY_ACTION.equals(action)) {
|
||||
for (AmenityIndexRepository r : repos) {
|
||||
if (r instanceof AmenityIndexRepositoryOdb) {
|
||||
((AmenityIndexRepositoryOdb) r).deleteAmenities(n.getId() << 1);
|
||||
((AmenityIndexRepositoryOdb) r).clearCache();
|
||||
final AmenityIndexRepositoryOdb repo = app.getResourceManager().getUpdatablePoiDb();
|
||||
view.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (repo == null) {
|
||||
Toast.makeText(app, app.getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
} else {
|
||||
Toast.makeText(app, app.getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// delete all amenities with same id
|
||||
if (DELETE_ACTION.equals(action) || MODIFY_ACTION.equals(action)) {
|
||||
repo.deleteAmenities(n.getId() << 1);
|
||||
repo.clearCache();
|
||||
}
|
||||
// add amenities
|
||||
if (!DELETE_ACTION.equals(action)) {
|
||||
List<Amenity> ams = Amenity.parseAmenities(n, new ArrayList<Amenity>());
|
||||
for (Amenity a : ams) {
|
||||
for (AmenityIndexRepository r : repos) {
|
||||
if (r instanceof AmenityIndexRepositoryOdb) {
|
||||
((AmenityIndexRepositoryOdb) r).addAmenity(a);
|
||||
((AmenityIndexRepositoryOdb) r).clearCache();
|
||||
}
|
||||
}
|
||||
repo.addAmenity(a);
|
||||
repo.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.osmand.data.Amenity;
|
|||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.AmenityIndexRepository;
|
||||
import net.osmand.plus.AmenityIndexRepositoryOdb;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -208,11 +207,13 @@ public class MapActivityActions {
|
|||
Toast.makeText(mapActivity, getString(R.string.update_poi_is_not_available_for_zoom), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
final List<AmenityIndexRepository> repos = ((OsmandApplication) mapActivity.getApplication()).
|
||||
getResourceManager().searchAmenityRepositories(latitude, longitude);
|
||||
if(repos.isEmpty()){
|
||||
final AmenityIndexRepositoryOdb repo = ((OsmandApplication) mapActivity.getApplication()).
|
||||
getResourceManager().getUpdatablePoiDb();
|
||||
if(repo == null){
|
||||
Toast.makeText(mapActivity, getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
} else {
|
||||
Toast.makeText(mapActivity, getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
final OsmandMapTileView mapView = mapActivity.getMapView();
|
||||
Rect pixRect = new Rect(-mapView.getWidth()/2, -mapView.getHeight()/2, 3*mapView.getWidth()/2, 3*mapView.getHeight()/2);
|
||||
|
@ -235,11 +236,7 @@ public class MapActivityActions {
|
|||
if(!loadingPOIs){
|
||||
showToast(getString(R.string.update_poi_error_loading));
|
||||
} else {
|
||||
for(AmenityIndexRepository r : repos){
|
||||
if(r instanceof AmenityIndexRepositoryOdb){
|
||||
((AmenityIndexRepositoryOdb) r).updateAmenities(amenities, leftLon, topLat, rightLon, bottomLat);
|
||||
}
|
||||
}
|
||||
repo.updateAmenities(amenities, leftLon, topLat, rightLon, bottomLat);
|
||||
showToast(MessageFormat.format(getString(R.string.update_poi_success), amenities.size()));
|
||||
mapView.refreshMap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue