add poi filter implementation

git-svn-id: https://osmand.googlecode.com/svn/trunk@151 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-11 13:44:37 +00:00
parent a33f1275cd
commit efa35f6a16
5 changed files with 258 additions and 13 deletions

View file

@ -29,7 +29,6 @@ public class ToDoConstants {
// ( 1) predefined filters, 2) choose subtype's, 3) filter by name, 4) opening hours (filter)) // ( 1) predefined filters, 2) choose subtype's, 3) filter by name, 4) opening hours (filter))
// 41. POI layer over map (shows poi by selected filter) // 41. POI layer over map (shows poi by selected filter)
// 32b. Include to amenity index : historic, sport, ....
// 8. Enable change POI directly on map (requires OSM login) // 8. Enable change POI directly on map (requires OSM login)
// 33. Build transport locations. Create transport index (transport-stops) (investigate) // 33. Build transport locations. Create transport index (transport-stops) (investigate)
// 39. Support old-versionned resources (1) odb indexes, 2) favourites table, 3) atomic settings (?)) // 39. Support old-versionned resources (1) odb indexes, 2) favourites table, 3) atomic settings (?))
@ -54,7 +53,8 @@ public class ToDoConstants {
// TODO swing // TODO swing
// 4. Fix issues with big files (such as netherlands) - save memory // 4. Fix issues with big files (such as netherlands) - save memory (!)
// Current result : for big file (1 - task 60-80% time, 90% memory)
// 1. Download tiles without using dir tiles (?) // 1. Download tiles without using dir tiles (?)

View file

@ -234,7 +234,7 @@ public class DataExtraction {
} }
// Information about progress for belarus.osm [165 seconds] // Information about progress for belarus.osm [165 seconds] - 580mb
// FINE: Loading file E:\Information\OSM maps\belarus_2010_06_02.osm started - 61% // FINE: Loading file E:\Information\OSM maps\belarus_2010_06_02.osm started - 61%
// FINE: Correlating data... started after 101921 ms - 10% // FINE: Correlating data... started after 101921 ms - 10%
// FINE: Indexing poi... started after 17062 ms - 0 % // FINE: Indexing poi... started after 17062 ms - 0 %
@ -243,14 +243,45 @@ public class DataExtraction {
// FINE: Indexing buildings... started after 16531 ms - 20 % // FINE: Indexing buildings... started after 16531 ms - 20 %
// FINE: Normalizing name streets... started after 30890 ms - 0% // FINE: Normalizing name streets... started after 30890 ms - 0%
// minsk.bz2 [36] // belarus.osm.bz2 [273 ms] - 40mb
// FINE: Loading file E:\Information\OSM maps\minsk_extr.bz2 started - 63% // FINE: Memory before task exec: 16 252 928 free : 11 676 888
// FINE: Loading file E:\Information\OSM maps\belarus osm\belarus_2010_06_02.osm.bz2 started - 73 %
// FINE: Memory before task exec: 95 760 384 free : 17 704 984
// FINE: Correlating data... started after 203 657 ms - 7 %
// FINE: Indexing poi... started after 20 204 ms
// FINE: Indexing cities... started after 62 ms
// FINE: Memory before task exec: 95 760 384 free : 45 752 80
// FINE: Indexing streets... started after 94 ms - 7 %
// FINE: Memory before task exec: 167 510 016 free : 91 616 528
// FINE: Indexing buildings... started after 18 672 ms - 13 %
// FINE: Memory before task exec: 167 510 016 free : 76 993 976
// FINE: Normalizing name streets... started after 32 719 ms
// minsk.bz2 [36] - 4mb
// FINE: Total mem: 16252928 free : 8370296
// FINE: Loading file E:\Information\OSM maps\minsk_extr.bz2 started - 63% - 90 % (memory)
// FINE: Total mem: 64139264 free : 25069688
// FINE: Correlating data... started after 23829 ms - 27% // FINE: Correlating data... started after 23829 ms - 27%
// FINE: Indexing poi... started after 10547 ms - 0% // FINE: Indexing poi... started after 10547 ms - 0%
// FINE: Indexing cities... started after 31 ms - 0% // FINE: Indexing cities... started after 31 ms - 0%
// FINE: Indexing streets... started after 94 ms - 0% // FINE: Indexing streets... started after 94 ms - 1%
// FINE: Indexing buildings... started after 672 ms - 1% // FINE: Indexing buildings... started after 672 ms - 7%
// FINE: Normalizing name streets... started after 2421 ms - 7% // FINE: Normalizing name streets... started after 2421 ms - 0%
// FINE: Total mem: 64139264 free : 22226792
// chech.bz2 [1090 ms] - 185mb
// FINE: Total mem: 16 252 928 free : 9 132 960
// FINE: Loading file E:\Information\OSM maps\czech_republic.osm.bz2 started - 78 % - 90 % (memory)
// FINE: Total mem: 226 877 440 free : 42 500 592
// FINE: Correlating data... started after 857 788 ms - 5 %
// FINE: Indexing poi... started after 58 173 ms
// FINE: Total mem: 259 522 560 free : 77 918 344
// FINE: Indexing cities... started after 171 ms
// FINE: Indexing streets... started after 188 ms - 12 %
// FINE: Indexing buildings... started after 135 250 ms - 3 %
// FINE: Normalizing name streets... started after 36 657 ms
// FINE: Total mem: 259 522 560 free : 8 697 952
public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{ public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{
// data to load & index // data to load & index

View file

@ -176,12 +176,13 @@ public class ProgressDialog extends JDialog implements IProgress {
@Override @Override
public void startTask(String taskName, int work) { public void startTask(String taskName, int work) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Memory before task exec: " + Runtime.getRuntime().totalMemory() + " free : " + Runtime.getRuntime().freeMemory());
if (previousTaskStarted == 0) { if (previousTaskStarted == 0) {
log.debug(taskName + " started"); log.debug(taskName + " started");
} else { } else {
log.debug(taskName + " started after " + (System.currentTimeMillis() - previousTaskStarted) + " ms"); log.debug(taskName + " started after " + (System.currentTimeMillis() - previousTaskStarted) + " ms");
} }
log.debug("Total mem: " + Runtime.getRuntime().totalMemory() + " free : " + Runtime.getRuntime().freeMemory());
} }
previousTaskStarted = System.currentTimeMillis(); previousTaskStarted = System.currentTimeMillis();
if(taskName == null){ if(taskName == null){

View file

@ -1,11 +1,49 @@
package com.osmand; package com.osmand;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import com.osmand.data.Amenity; import com.osmand.data.Amenity;
import com.osmand.data.AmenityType;
public class PoiFilter { public class PoiFilter {
public static String STD_PREFIX = "std_";
public static String USER_PREFIX = "user_";
private Map<AmenityType, List<String>> acceptedTypes = new LinkedHashMap<AmenityType, List<String>>();
private String filterId;
private String name;
private final boolean isStandardFilter;
// constructor for standard filters
public PoiFilter(AmenityType type){
isStandardFilter = true;
filterId = STD_PREFIX + type;
name = type == null ? "Closest poi" : Algoritms.capitalizeFirstLetterAndLowercase(type.name()).replace('_', ' ');
if(type == null){
for(AmenityType t : AmenityType.values()){
acceptedTypes.put(t, null);
}
} else {
acceptedTypes.put(type, null);
}
}
// constructor for standard filters
public PoiFilter(String name, String filterId, Map<AmenityType, List<String>> acceptedTypes){
isStandardFilter = false;
if(filterId == null){
filterId = USER_PREFIX + name.replace(' ', '_').toLowerCase();
}
this.filterId = filterId;
this.name = name;
this.acceptedTypes.putAll(acceptedTypes);
}
public boolean isSearchFurtherAvailable(){ public boolean isSearchFurtherAvailable(){
return false; return false;
} }
@ -14,6 +52,10 @@ public class PoiFilter {
return null; return null;
} }
public String getSearchArea(){
return null;
}
public List<Amenity> getLastSearchedResults(){ public List<Amenity> getLastSearchedResults(){
return null; return null;
} }
@ -23,15 +65,47 @@ public class PoiFilter {
} }
public String getName(){ public String getName(){
return null; return name;
}
/**
* @param type
* @return null if all subtypes are accepted/ empty list if type is not accepted at all
*/
public List<String> getAcceptedSubtypes(AmenityType type){
if(acceptedTypes.containsKey(type)){
return Collections.emptyList();
}
return acceptedTypes.get(type);
}
public boolean isTypeAccepted(AmenityType t){
return acceptedTypes.containsKey(t);
}
public boolean isWholeTypeAccepted(AmenityType type){
return acceptedTypes.get(type) == null;
}
public void setTypeToAccept(AmenityType type, boolean accept){
if(accept){
acceptedTypes.put(type, null);
} else {
acceptedTypes.remove(type);
}
}
public void selectSubTypesToAccept(AmenityType t, List<String> accept){
acceptedTypes.put(t, accept);
} }
public String getFilterId(){ public String getFilterId(){
return null; return filterId;
} }
public boolean isStandardFilter(){ public boolean isStandardFilter(){
return true; return isStandardFilter;
} }
} }

View file

@ -0,0 +1,139 @@
package com.osmand;
import java.util.ArrayList;
import java.util.List;
import com.osmand.data.AmenityType;
import android.content.Context;
public class PoiFiltersHelper {
public static PoiFilter getFilterById(Context ctx, String filterId){
if(filterId.startsWith(PoiFilter.USER_PREFIX)){
List<PoiFilter> filters = getUserDefinedPoiFilters(ctx);
for(PoiFilter f : filters){
if(f.getFilterId().equals(filterId)){
return f;
}
}
} else if(filterId.startsWith(PoiFilter.STD_PREFIX)){
List<PoiFilter> filters = getOsmDefinedPoiFilters(ctx);
for(PoiFilter f : filters){
if(f.getFilterId().equals(filterId)){
return f;
}
}
}
return null;
}
private static List<PoiFilter> cacheUserDefinedFilters = new ArrayList<PoiFilter>();
public static List<PoiFilter> getUserDefinedPoiFilters(Context ctx){
if(cacheUserDefinedFilters == null){
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
// TODO
}
return cacheUserDefinedFilters;
}
private static List<PoiFilter> cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
public static List<PoiFilter> getOsmDefinedPoiFilters(Context ctx){
if(cacheOsmDefinedFilters == null){
cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
cacheOsmDefinedFilters.add(new PoiFilter(null));
for(AmenityType t : AmenityType.values()){
cacheOsmDefinedFilters.add(new PoiFilter(t));
}
}
return cacheOsmDefinedFilters;
}
public static boolean removePoiFilter(Context ctx, PoiFilter filter){
return false;
}
public static boolean createPoiFilter(Context ctx, PoiFilter filter){
return false;
}
public static boolean commitPoiFilter(Context ctx, PoiFilter filter){
return false;
}
// protected static class PoiFilterDbHelper extends SQLiteOpenHelper {
//
// private static final int DATABASE_VERSION = 1;
// private static final String POI_FILTERS_NAME = "poi_filters";
// private static final String FAVOURITE_COL_NAME = "name";
// private static final String FAVOURITE_COL_LAT = "latitude";
// private static final String FAVOURITE_COL_LON = "longitude";
// private static final String FAVOURITE_TABLE_CREATE = "CREATE TABLE " + FAVOURITE_TABLE_NAME + " (" +
// FAVOURITE_COL_NAME + " TEXT, " + FAVOURITE_COL_LAT + " double, " +
// FAVOURITE_COL_LON + " double);";
//
// PoiFilterDbHelper(Context context) {
// super(context, POI_FILTERS_NAME, null, DATABASE_VERSION);
// }
//
// public boolean addFavourite(FavouritePoint p){
// SQLiteDatabase db = getWritableDatabase();
// if(db != null){
// db.execSQL("INSERT INTO " + FAVOURITE_TABLE_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getLatitude(), p.getLongitude()});
// return true;
// }
// return false;
// }
//
// public List<FavouritePoint> getFavouritePoints(){
// SQLiteDatabase db = getReadableDatabase();
// ArrayList<FavouritePoint> list = new ArrayList<FavouritePoint>();
// if(db != null){
// Cursor query = db.rawQuery("SELECT " + FAVOURITE_COL_NAME +", " + FAVOURITE_COL_LAT +"," + FAVOURITE_COL_LON +" FROM " +
// FAVOURITE_TABLE_NAME, null);
// if(query.moveToFirst()){
// do {
// FavouritePoint p = new FavouritePoint();
// p.setName(query.getString(0));
// p.setLatitude(query.getDouble(1));
// p.setLongitude(query.getDouble(2));
// list.add(p);
// } while(query.moveToNext());
// }
// query.close();
// }
// return list;
// }
//
// public boolean editFavouriteName(FavouritePoint p, String newName){
// SQLiteDatabase db = getWritableDatabase();
// if(db != null){
// db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET name = ? WHERE name = ?",new Object[]{newName, p.getName()});
// p.setName(newName);
// return true;
// }
// return false;
// }
//
// public boolean deleteFavourite(FavouritePoint p){
// SQLiteDatabase db = getWritableDatabase();
// if(db != null){
// db.execSQL("DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE name = ?",new Object[]{p.getName()});
// return true;
// }
// return false;
// }
//
//
// @Override
// public void onCreate(SQLiteDatabase db) {
// db.execSQL(FAVOURITE_TABLE_CREATE);
// }
//
// @Override
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// }
// }
}