reimplement search postal_code (now it is similar to specify city)

git-svn-id: https://osmand.googlecode.com/svn/trunk@178 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-19 21:39:03 +00:00
parent f23475ad1b
commit 38831b822a
17 changed files with 301 additions and 160 deletions

View file

@ -24,15 +24,19 @@ public class ToDoConstants {
// TODO ANDROID
// 31. Translation.
// DONE : partially olga
// TODO : everywhere put non-nls, check all translated into russian [swing could not be translated]
// TODO : everywhere put non-nls, check all translated into russian [swing could not be translated]
// 34. Suppport navigation for calculated route (example of get route from internet is in swing app).
// DONE : MiniMap done, Routing settings done, RouteLayer done, RoutingHelper done.
// TODO : Test again?
// 37. Get rid of exit button (!). Think about when notification should go & how clear resources if it is necessary
// DONE :
// TODO : add to app settings preference (Refresh indexes).
// 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions.
// Some icons are not fine (as back menu from map - it is blured).
// 37. Get rid of exit button (!). Think about when notification should go & how clear resources if it is necessary
// DONE :
// TODO : add to app settings preference (Refresh indexes).
// 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others)
// DONE : back end (POI filter object, save, delete, read)
// TODO : activity to create/edit new index, activity to read both user defined/osm standard, add actions to remove/create
@ -42,9 +46,6 @@ public class ToDoConstants {
// DONE: Load transport routes in swing.
// TODO: Create transport index, create transport activity
// 34. Suppport navigation for calculated route (example of get route from internet is in swing app).
// DONE : MiniMap done, Routing settings done, RouteLayer done, RoutingHelper done.
// TODO : Test again?
// FUTURE RELEASES
@ -56,16 +57,16 @@ public class ToDoConstants {
// (would you like to use internet for that operation - if using internet is not checked).
// Internet using now for : edit POI osm, show osm bugs layer, download tiles.
// 47. Internet connectivity could be checked before trying to use
// 48. Implement console application that prepare indexes to upload on server...
// 0) run in background 1) download from internet 2) generates indices for Europe (take care about memory) 3) upload?
// 46. Implement downloading strategy for tiles (do not load 17 zoom, load only 16 for example) - try to scale 15 zoom for 17 (?)
// 40. Support simple vector road rendering (require new index file) (?)
// 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. (?)
// BUGS Android
// 6. Improvement postal_code search : replace search city <-> postal_code (show streets for postal_code)
// 5. Improvement : Implement caching files existing on FS, implement specific method in RM
// Introducing cache of file names that are on disk (creating new File() consumes a lot of memory)
// 7. Update map is duplicated in target & in update menu (context menu)
// TODO swing

View file

@ -3,9 +3,7 @@ package com.osmand.data;
import java.text.Collator;
import java.util.Collection;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import com.osmand.Algoritms;
import com.osmand.osm.Entity;
@ -48,7 +46,6 @@ public class City extends MapObject {
private CityType type = null;
// Be attentive ! Working with street names ignoring case
private Map<String, Street> streets = new TreeMap<String, Street>(Collator.getInstance());
private SortedSet<String> postcodes = new TreeSet<String>();
public City(Node el){
super(el);
@ -99,15 +96,11 @@ public class City extends MapObject {
return registerStreet(street, false);
}
public Street registerBuilding(Entity e){
public Building registerBuilding(Entity e){
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
String street = e.getTag(OSMTagKey.ADDR_STREET);
if( street != null && number != null){
Building building = registerStreet(street).registerBuilding(e);
if (building.getPostcode() != null) {
postcodes.add(building.getPostcode());
}
return streets.get(street.toLowerCase());
return registerStreet(street).registerBuilding(e);
}
return null;
}

View file

@ -0,0 +1,35 @@
package com.osmand.data;
import java.text.Collator;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
public class PostCode extends MapObject {
private Map<String, Street> streets = new TreeMap<String, Street>(Collator.getInstance());
public PostCode(String name){
setName(name);
setEnName(name);
setId(-1L);
}
public boolean isEmptyWithStreets(){
return streets.isEmpty();
}
public Street getStreet(String name){
return streets.get(name);
}
public Collection<Street> getStreets() {
return streets.values();
}
public Street registerStreet(Street street, boolean useEnglishNames){
String name = street.getName(useEnglishNames);
streets.put(name, street);
return street;
}
}

View file

@ -1,14 +0,0 @@
package com.osmand.data;
public class PostcodeBasedStreet extends Street {
public PostcodeBasedStreet(City city, String postcode) {
super(city, postcode);
}
@Override
public Long getId() {
return -1l;
}
}

View file

@ -63,7 +63,7 @@ public class Street extends MapObject {
}
public boolean isRegisteredInCity(){
return city.getStreet(getName()) == this;
return city != null && city.getStreet(getName()) == this;
}
@Override
@ -71,7 +71,7 @@ public class Street extends MapObject {
if (name.equals(getName())) {
return;
}
if (city.getStreet(getName()) == this) {
if (city != null && city.getStreet(getName()) == this) {
city.unregisterStreet(getName());
super.setName(name);
Street s = city.registerStreet(this);
@ -92,8 +92,8 @@ public class Street extends MapObject {
public City getCity() {
return city;
}
public void doDataPreparation() {
public void sortBuildings(){
Collections.sort(buildings, new Comparator<Building>(){
@Override
public int compare(Building o1, Building o2) {
@ -102,6 +102,10 @@ public class Street extends MapObject {
return i1 - i2;
}
});
}
public void doDataPreparation() {
sortBuildings();
calculateCenter();
if(location == null){
List<LatLon> nodes = new ArrayList<LatLon>();

View file

@ -115,24 +115,39 @@ public class DataExtraction {
protected class DataExtractionOsmFilter implements IOsmStorageFilter {
final ArrayList<Node> places;
final ArrayList<Entity> buildings;
final ArrayList<Entity> amenities;
final ArrayList<Way> ways;
final ArrayList<Relation> transport;
ArrayList<Node> places = new ArrayList<Node>();
ArrayList<Entity> buildings = new ArrayList<Entity>();
ArrayList<Entity> amenities = new ArrayList<Entity>();
ArrayList<Way> ways = new ArrayList<Way>();
ArrayList<Relation> transport = new ArrayList<Relation>();
Map<Long, String> postalCodes = new LinkedHashMap<Long, String>();
int currentCount = 0;
private Connection conn;
private PreparedStatement prep;
public DataExtractionOsmFilter(ArrayList<Entity> amenities, ArrayList<Entity> buildings, ArrayList<Node> places,
ArrayList<Way> ways, ArrayList<Relation> transport) {
this.amenities = amenities;
this.buildings = buildings;
this.places = places;
this.ways = ways;
this.transport = transport;
public DataExtractionOsmFilter() {
}
public ArrayList<Node> getPlaces() {
return places;
}
public ArrayList<Entity> getBuildings() {
return buildings;
}
public ArrayList<Entity> getAmenities() {
return amenities;
}
public ArrayList<Way> getWays() {
return ways;
}
public ArrayList<Relation> getTransport() {
return transport;
}
public Map<Long, String> getPostalCodes() {
return postalCodes;
}
public void initDatabase() throws SQLException {
@ -232,6 +247,15 @@ public class DataExtraction {
ways.add((Way) e);
processed = true;
}
if(e instanceof Relation){
if(e.getTag(OSMTagKey.POSTAL_CODE) != null){
String tag = e.getTag(OSMTagKey.POSTAL_CODE);
for(Long l : ((Relation)e).getMemberIds()){
postalCodes.put(l, tag);
}
}
// do not need to mark processed
}
}
if(indexTransport){
if(e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null){
@ -314,12 +338,7 @@ public class DataExtraction {
public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{
// data to load & index
final ArrayList<Node> places = new ArrayList<Node>();
final ArrayList<Entity> buildings = new ArrayList<Entity>();
final ArrayList<Entity> amenities = new ArrayList<Entity>();
final ArrayList<Way> ways = new ArrayList<Way>();
final ArrayList<Relation> transport = new ArrayList<Relation>();
File f = new File(path);
InputStream stream = new FileInputStream(f);
@ -342,7 +361,14 @@ public class DataExtraction {
storage.getFilters().add(addFilter);
}
DataExtractionOsmFilter filter = new DataExtractionOsmFilter(amenities, buildings, places, ways, transport);
DataExtractionOsmFilter filter = new DataExtractionOsmFilter();
// data to load & index
final ArrayList<Node> places = filter.getPlaces();
final ArrayList<Entity> buildings = filter.getBuildings();
final ArrayList<Entity> amenities = filter.getAmenities();
final ArrayList<Way> ways = filter.getWays();
final ArrayList<Relation> transport = filter.getTransport();
Map<Long, String> postalCodes = filter.getPostalCodes();
storage.getFilters().add(filter);
// 0. Loading osm file
try {
@ -393,7 +419,7 @@ public class DataExtraction {
// 5. reading buildings
progress.setGeneralProgress("[95 of 100]");
readingBuildings(progress, buildings, country);
readingBuildings(progress, buildings, country, postalCodes);
}
progress.setGeneralProgress("[100 of 100]");
@ -451,7 +477,7 @@ public class DataExtraction {
}
private void readingBuildings(IProgress progress, final ArrayList<Entity> buildings, Region country) {
private void readingBuildings(IProgress progress, final ArrayList<Entity> buildings, Region country, Map<Long, String> postalCodes) {
// found buildings (index addresses)
progress.startTask("Indexing buildings...", buildings.size());
for(Entity b : buildings){
@ -470,7 +496,10 @@ public class DataExtraction {
city = country.getClosestCity(center);
}
if (city != null) {
city.registerBuilding(b);
Building building = city.registerBuilding(b);
if(postalCodes.containsKey(building.getId()) ){
building.setPostcode(postalCodes.get(building.getId()));
}
}
}
}
@ -664,12 +693,6 @@ public class DataExtraction {
// Performance testing methods
public static void main(String[] args) throws IOException, SAXException, SQLException, ParserConfigurationException {
ArrayList<Entity> amenities = new ArrayList<Entity>();
ArrayList<Entity> buildings = new ArrayList<Entity>();
ArrayList<Node> places = new ArrayList<Node>();
ArrayList<Relation> transport = new ArrayList<Relation>();
ArrayList<Way> ways = new ArrayList<Way>();
long time = System.currentTimeMillis();
OsmBaseStorage storage = new OsmBaseStorage();
String path = "E:\\Information\\OSM maps\\belarus_2010_06_02.osm";
@ -704,7 +727,7 @@ public class DataExtraction {
});
DataExtraction e = new DataExtraction(true, true, true, true, false, true, new File(wDir));
DataExtractionOsmFilter filter = e.new DataExtractionOsmFilter(amenities, buildings, places, ways, transport);
DataExtractionOsmFilter filter = e.new DataExtractionOsmFilter();
filter.initDatabase();
storage.getFilters().add(filter);
@ -715,7 +738,7 @@ public class DataExtraction {
storage.parseOSM(stream, new ConsoleProgressImplementation(), streamFile, true);
System.out.println("Total mem: " + Runtime.getRuntime().totalMemory() + " free : " + Runtime.getRuntime().freeMemory());
System.out.println("All time " + (System.currentTimeMillis() - time) + " ms"); //
System.out.println(amenities.size() + " " + buildings.size() + " " + places.size() + " " + ways.size());
// System.out.println(amenities.size() + " " + buildings.size() + " " + places.size() + " " + ways.size());
}
}

View file

@ -8,6 +8,7 @@ public class OSMSettings {
// ways
HIGHWAY("highway"), //$NON-NLS-1$
BUILDING("building"), //$NON-NLS-1$
POSTAL_CODE("postal_code"), //$NON-NLS-1$
// transport
ROUTE("route"), //$NON-NLS-1$
OPERATOR("operator"), //$NON-NLS-1$

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="use_online_routing_descr">Использовать интернет для расчета маршрута</string>
<string name="use_online_routing">Online маршрутизация</string>
<string name="user_password_descr">Указать пароль для работы с OSM</string>
<string name="user_password">Пароль</string>
<string name="osm_settings_descr">Упраление слоем open street bugs, установка osm логина </string>
@ -75,7 +77,7 @@
<color name="color_red">#FF0000</color>
<string name="searchpoi_activity">Выберите poi</string>
<string name="search_POI_level_btn">Найти еще</string>
<string name="incremental_search_city">Выберите город. Чтобы найти дереавню введите как минимум 3 первых буквы.</string>
<string name="incremental_search_city">Выберите город. Введите 3 первых буквы, чтобы найти деревню, 2 цифры - индекс.</string>
<string name="incremental_search_street">Выберите улицу</string>
<string name="incremental_search_building">Выберите здание</string>
<string name="choose_available_region">Выберите регион</string>

View file

@ -77,7 +77,7 @@
<color name="color_red">#FF0000</color>
<string name="searchpoi_activity">Choose poi</string>
<string name="search_POI_level_btn">Find more</string>
<string name="incremental_search_city">Search city incrementally. In order to find villages input more than 3 first symbols.</string>
<string name="incremental_search_city">Search city incrementally. In order to find villages/postcodes input more than 3 first symbols.</string>
<string name="incremental_search_street">Search street incrementally</string>
<string name="incremental_search_building">Search building incrementally</string>
<string name="choose_available_region">Choose region</string>

View file

@ -290,6 +290,7 @@ public class OsmandSettings {
public static final String LAST_SEARCHED_REGION = "last_searched_region"; //$NON-NLS-1$
public static final String LAST_SEARCHED_CITY = "last_searched_city"; //$NON-NLS-1$
public static final String lAST_SEARCHED_POSTCODE= "last_searched_postcode"; //$NON-NLS-1$
public static final String LAST_SEARCHED_STREET = "last_searched_street"; //$NON-NLS-1$
public static final String LAST_SEARCHED_BUILDING = "last_searched_building"; //$NON-NLS-1$
public static final String LAST_SEARCHED_INTERSECTED_STREET = "last_searched_intersected_street"; //$NON-NLS-1$
@ -308,6 +309,21 @@ public class OsmandSettings {
}
return edit.commit();
}
public static String getLastSearchedPostcode(Context ctx){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.getString(lAST_SEARCHED_POSTCODE, null);
}
public static boolean setLastSearchedPostcode(Context ctx, String postcode){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit().putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$
LAST_SEARCHED_BUILDING, "").putString(lAST_SEARCHED_POSTCODE, postcode); //$NON-NLS-1$
if(prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)){
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
}
return edit.commit();
}
public static Long getLastSearchedCity(Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
@ -318,6 +334,7 @@ public class OsmandSettings {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit().putLong(LAST_SEARCHED_CITY, cityId).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$
LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$
edit.remove(lAST_SEARCHED_POSTCODE);
if(prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)){
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
}

View file

@ -11,7 +11,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
@ -21,7 +21,8 @@ import android.database.sqlite.SQLiteDatabase;
import com.osmand.data.Building;
import com.osmand.data.City;
import com.osmand.data.PostcodeBasedStreet;
import com.osmand.data.MapObject;
import com.osmand.data.PostCode;
import com.osmand.data.Region;
import com.osmand.data.Street;
import com.osmand.data.City.CityType;
@ -41,7 +42,7 @@ public class RegionAddressRepository {
private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>();
private Map<CityType, List<City>> cityTypes = new HashMap<CityType, List<City>>();
private SortedSet<String> postCodes = new TreeSet<String>(Collator.getInstance());
private Map<String, PostCode> postCodes = new TreeMap<String, PostCode>(Collator.getInstance());
private boolean useEnglishNames = false;
@ -86,6 +87,14 @@ public class RegionAddressRepository {
return !cities.isEmpty();
}
public PostCode getPostcode(String name){
if(name == null){
return null;
}
preloadPostcodes();
return postCodes.get(name.toUpperCase());
}
public City getCityById(Long id){
if(id == -1){
// do not preload cities for that case
@ -95,18 +104,14 @@ public class RegionAddressRepository {
return cities.get(id);
}
public Street getStreetByName(City city, String name){
if(city.isEmptyWithStreets()){
preloadStreets(city);
public Street getStreetByName(MapObject city, String name) {
preloadStreets(city);
if (city instanceof City) {
return ((City) city).getStreet(name);
} else {
return ((PostCode) city).getStreet(name);
}
if (postCodes.isEmpty()) {
preloadPostcodes();
}
Street street = city.getStreet(name);
if (street == null) {
street = postCodes.contains(name.toUpperCase()) ? new PostcodeBasedStreet(city, name) : null;
}
return street;
}
public Building getBuildingByName(Street street, String name){
@ -148,15 +153,22 @@ public class RegionAddressRepository {
}
}
public void fillWithSuggestedBuildings(Street street, String name, List<Building> buildingsToFill){
public void fillWithSuggestedBuildings(PostCode postcode, Street street, String name, List<Building> buildingsToFill){
preloadBuildings(street);
name = name.toLowerCase();
int ind = 0;
if(name.length() == 0){
boolean empty = name.length() == 0;
if(empty && postcode == null){
buildingsToFill.addAll(street.getBuildings());
return;
}
for (Building building : street.getBuildings()) {
if(postcode != null && !postcode.getName().equals(building.getPostcode())){
continue;
} else if(empty){
buildingsToFill.add(building);
continue;
}
String bName = useEnglishNames ? building.getEnName() : building.getName();
String lowerCase = bName.toLowerCase();
if (lowerCase.startsWith(name)) {
@ -193,30 +205,21 @@ public class RegionAddressRepository {
}
public void fillWithSuggestedStreets(City c, String name, List<Street> streetsToFill){
preloadStreets(c);
preloadPostcodes();
public void fillWithSuggestedStreets(MapObject o, String name, List<Street> streetsToFill){
assert o instanceof PostCode || o instanceof City;
City city = (City) (o instanceof City ? o : null);
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
preloadStreets(o);
name = name.toLowerCase();
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets() ;
int ind = 0;
if(name.length() == 0){
streetsToFill.addAll(c.getStreets());
streetsToFill.addAll(streets);
return;
} else if (name.length() >= 2 &&
Character.isDigit(name.charAt(0)) &&
Character.isDigit(name.charAt(1))) {
// also try to identify postcodes
for (String code : postCodes) {
code = code.toLowerCase();
if (code.startsWith(name)) {
streetsToFill.add(ind++,new PostcodeBasedStreet(c, code));
} else {
streetsToFill.add(new PostcodeBasedStreet(c, code));
}
}
}
ind = 0;
for (Street s : c.getStreets()) {
for (Street s : streets) {
String sName = useEnglishNames ? s.getEnName() : s.getName();
String lowerCase = sName.toLowerCase();
if (lowerCase.startsWith(name)) {
@ -228,7 +231,7 @@ public class RegionAddressRepository {
}
}
public void fillWithSuggestedCities(String name, List<City> citiesToFill){
public void fillWithSuggestedCities(String name, List<MapObject> citiesToFill){
preloadCities();
// essentially index is created that cities towns are first in cities map
int ind = 0;
@ -236,18 +239,13 @@ public class RegionAddressRepository {
Character.isDigit(name.charAt(0)) &&
Character.isDigit(name.charAt(1))) {
preloadPostcodes();
name = name.toLowerCase();
// also try to identify postcodes
for (String code : postCodes) {
String lcode = code.toLowerCase();
// TODO postcode
City c = new City(CityType.CITY);
c.setName(code);
c.setEnName(code);
if (lcode.startsWith(name)) {
citiesToFill.add(ind++,c);
} else if(lcode.contains(name)){
citiesToFill.add(c);
String uName = name.toUpperCase();
for (String code : postCodes.keySet()) {
if (code.startsWith(uName)) {
citiesToFill.add(ind++, postCodes.get(code));
} else if(code.contains(uName)){
citiesToFill.add(postCodes.get(code));
}
}
@ -346,7 +344,7 @@ public class RegionAddressRepository {
do {
String postcode = query.getString(0);
if (postcode != null) {
postCodes.add(postcode);
postCodes.put(postcode, new PostCode(postcode));
}
} while (query.moveToNext());
}
@ -357,15 +355,8 @@ public class RegionAddressRepository {
public void preloadBuildings(Street street){
if (street.getBuildings().isEmpty()) {
Cursor query = null;
if (street instanceof PostcodeBasedStreet) {
// this is postcode
query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = postcode", //$NON-NLS-1$
new String[] { street.getName().toUpperCase()}, null, null, null);
} else {
query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = street", //$NON-NLS-1$
Cursor query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = street", //$NON-NLS-1$
new String[] { street.getId() + "" }, null, null, null); //$NON-NLS-1$
}
log.debug("Start loading buildings for " + street.getName()); //$NON-NLS-1$
if (query.moveToFirst()) {
do {
@ -375,16 +366,21 @@ public class RegionAddressRepository {
.ordinal()));
building.setName(query.getString(IndexBuildingTable.NAME.ordinal()));
building.setEnName(query.getString(IndexBuildingTable.NAME_EN.ordinal()));
building.setPostcode(query.getString(IndexBuildingTable.POSTCODE.ordinal()));
street.registerBuilding(building);
} while (query.moveToNext());
street.sortBuildings();
}
query.close();
log.debug("Loaded " + street.getBuildings().size() + " buildings"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
public void preloadStreets(City city){
if (city.isEmptyWithStreets()) {
public void preloadStreets(MapObject o){
assert o instanceof PostCode || o instanceof City;
City city = (City) (o instanceof City ? o : null);
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
if (city != null && city.isEmptyWithStreets()) {
log.debug("Start loading streets for " + city.getName()); //$NON-NLS-1$
Cursor query = db.query(IndexStreetTable.getTable(), IndexConstants.generateColumnNames(IndexStreetTable.values()), "? = city", //$NON-NLS-1$
new String[] { city.getId() + "" }, null, null, null); //$NON-NLS-1$
@ -401,6 +397,33 @@ public class RegionAddressRepository {
}
query.close();
log.debug("Loaded " + city.getStreets().size() + " streets"); //$NON-NLS-1$ //$NON-NLS-2$
} else if(post != null && post.isEmptyWithStreets()){
log.debug("Start loading streets for " + post.getName()); //$NON-NLS-1$
Cursor query = db.rawQuery("SELECT B.CITY, B.ID,B.LATITUDE, B.LONGITUDE, B.NAME, B.NAME_EN FROM building A JOIN street B ON A.street = B.ID WHERE A.postcode = ?", //$NON-NLS-1$
new String[] { post.getName() + "" }); //$NON-NLS-1$
if (query.moveToFirst()) {
do {
city = getCityById(query.getLong(0));
Street street = null;
if(city != null){
preloadStreets(city);
street = city.getStreet(useEnglishNames ? query.getString(5) : query.getString(4));
}
if(street == null){
street = new Street(city);
street.setId(query.getLong(1));
street.setLocation(query.getDouble(2), query.getDouble(3));
street.setName(query.getString(4));
street.setEnName(query.getString(5));
if(city != null){
city.registerStreet(street, useEnglishNames);
}
}
post.registerStreet(street, useEnglishNames);
} while (query.moveToNext());
}
query.close();
log.debug("Loaded " +post.getStreets().size() + " streets"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -194,7 +194,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
float fx = mapView.calcDiffTileX(dx, dy);
double latitude = MapUtils.getLatitudeFromTile(mapView.getZoom(), mapView.getYTile() + fy);
double longitude = MapUtils.getLongitudeFromTile(mapView.getZoom(), mapView.getXTile() + fx);
contextMenuPoint(latitude, longitude);
contextMenuPoint(latitude, longitude, false);
return true;
}
@ -508,7 +508,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
startActivity(settings);
return true;
} else if (item.getItemId() == R.id.map_mark_point) {
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude(), true);
return true;
} else if (item.getItemId() == R.id.map_reload_tile) {
reloadTile(mapView.getZoom(), mapView.getLatitude(), mapView.getLongitude());
@ -542,16 +542,27 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
builder.create().show();
}
protected void contextMenuPoint(final double latitude, final double longitude){
protected void contextMenuPoint(final double latitude, final double longitude, boolean menu){
Builder builder = new AlertDialog.Builder(this);
Resources resources = this.getResources();
builder.setItems(new String[]{
String[] res;
if(menu){
res = new String[]{
resources.getString(R.string.context_menu_item_navigate_point),
resources.getString(R.string.context_menu_item_add_favorite),
resources.getString(R.string.context_menu_item_update_map),
resources.getString(R.string.context_menu_item_open_bug),
resources.getString(R.string.context_menu_item_create_poi)
}, new DialogInterface.OnClickListener(){
resources.getString(R.string.context_menu_item_create_poi),
};
} else {
res = new String[]{
resources.getString(R.string.context_menu_item_navigate_point),
resources.getString(R.string.context_menu_item_add_favorite),
resources.getString(R.string.context_menu_item_open_bug),
resources.getString(R.string.context_menu_item_create_poi),
resources.getString(R.string.context_menu_item_update_map),
};
}
builder.setItems(res, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
@ -560,12 +571,12 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
} else if(which == 1){
addFavouritePoint(latitude, longitude);
} else if(which == 2){
reloadTile(mapView.getZoom(), latitude, longitude);
} else if(which == 3){
osmBugsLayer.openBug(MapActivity.this, getLayoutInflater(), mapView, latitude, longitude);
} else if(which == 4){
} else if(which == 3){
EditingPOIActivity activity = new EditingPOIActivity(MapActivity.this);
activity.showCreateDialog(latitude, longitude);
} else if(which == 4){
reloadTile(mapView.getZoom(), latitude, longitude);
}
}
});

View file

@ -19,6 +19,8 @@ import com.osmand.ResourceManager;
import com.osmand.activities.MapActivity;
import com.osmand.data.Building;
import com.osmand.data.City;
import com.osmand.data.MapObject;
import com.osmand.data.PostCode;
import com.osmand.data.Street;
import com.osmand.osm.LatLon;
import com.osmand.osm.Node;
@ -35,6 +37,7 @@ public class SearchAddressActivity extends Activity {
private RegionAddressRepository region = null;
private City city = null;
private PostCode postcode = null;
private Street street = null;
private Building building = null;
private Street street2 = null;
@ -118,6 +121,7 @@ public class SearchAddressActivity extends Activity {
findViewById(R.id.ResetCity).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
postcode = null;
city = null;
street = null;
street2 = null;
@ -129,6 +133,7 @@ public class SearchAddressActivity extends Activity {
@Override
public void onClick(View v) {
region = null;
postcode = null;
city = null;
street = null;
street2 = null;
@ -222,11 +227,15 @@ public class SearchAddressActivity extends Activity {
} else {
countryButton.setText(region.getName());
}
findViewById(R.id.ResetCity).setEnabled(city != null);
if(city == null){
findViewById(R.id.ResetCity).setEnabled(postcode != null || city != null);
if(city == null && postcode == null){
cityButton.setText(R.string.choose_city);
} else {
cityButton.setText(city.getName(region.useEnglishNames()));
if(postcode != null){
cityButton.setText(postcode.getName());
} else {
cityButton.setText(city.getName(region.useEnglishNames()));
}
}
cityButton.setEnabled(region != null);
@ -236,7 +245,7 @@ public class SearchAddressActivity extends Activity {
} else {
streetButton.setText(street.getName(region.useEnglishNames()));
}
streetButton.setEnabled(city != null);
streetButton.setEnabled(city != null || postcode != null);
if(radioBuilding){
((RadioButton)findViewById(R.id.RadioBuilding)).setChecked(true);
@ -247,7 +256,8 @@ public class SearchAddressActivity extends Activity {
buildingButton.setEnabled(street != null);
showOnMap.setEnabled(building != null || city != null || street != null);
showOnMap.setEnabled(city != null || street != null);
navigateTo.setEnabled(city != null || street != null);
}
public void loadData(){
@ -255,17 +265,23 @@ public class SearchAddressActivity extends Activity {
if(region.useEnglishNames() != OsmandSettings.usingEnglishNames(this)){
region.setUseEnglishNames(OsmandSettings.usingEnglishNames(this));
}
city = region.getCityById(OsmandSettings.getLastSearchedCity(SearchAddressActivity.this));
if (city != null) {
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(SearchAddressActivity.this));
String postcodeStr = OsmandSettings.getLastSearchedPostcode(this);
if(postcodeStr != null){
postcode = region.getPostcode(postcodeStr);
} else {
city = region.getCityById(OsmandSettings.getLastSearchedCity(SearchAddressActivity.this));
}
if (postcode != null || city != null) {
MapObject o = postcode == null ? city : postcode;
street = region.getStreetByName(o, OsmandSettings.getLastSearchedStreet(SearchAddressActivity.this));
if (street != null) {
String str = OsmandSettings.getLastSearchedIntersectedStreet(SearchAddressActivity.this);
radioBuilding = str == null;
if(str != null){
street2 = region.getStreetByName(city, str);
street2 = region.getStreetByName(o, str);
} else {
building = region.getBuildingByName(street, OsmandSettings
.getLastSearchedBuilding(SearchAddressActivity.this));
building = region.getBuildingByName(street, OsmandSettings.getLastSearchedBuilding(SearchAddressActivity.this));
}
}
}
@ -301,6 +317,7 @@ public class SearchAddressActivity extends Activity {
region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion);
String progressMsg = null;
// try to determine whether progress dialog & new thread needed
if (region != null) {
Long cityId = OsmandSettings.getLastSearchedCity(this);
if (!region.areCitiesPreloaded()) {
@ -311,6 +328,7 @@ public class SearchAddressActivity extends Activity {
progressMsg = "Converting native/english names...";
}
}
postcode = null;
city = null;
street = null;
building = null;

View file

@ -12,18 +12,24 @@ import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.Building;
import com.osmand.data.City;
import com.osmand.data.PostCode;
import com.osmand.data.Street;
public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<Building> {
private RegionAddressRepository region;
private City city;
private Street street;
private PostCode postcode;
@Override
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
if(region != null){
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
if(city != null){
if(postcode != null){
street = region.getStreetByName(postcode, OsmandSettings.getLastSearchedStreet(this));
} else if(city != null){
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(this));
}
}
@ -35,7 +41,7 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
public List<Building> getObjects(String filter) {
List<Building> l = new ArrayList<Building>();
if(street != null){
region.fillWithSuggestedBuildings(street, filter, l);
region.fillWithSuggestedBuildings(postcode, street, filter, l);
}
return l;
}

View file

@ -11,10 +11,12 @@ import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
import com.osmand.data.MapObject;
import com.osmand.data.PostCode;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City> {
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> {
private RegionAddressRepository region;
private LatLon location;
@ -27,8 +29,8 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
}
@Override
public List<City> getObjects(String filter) {
List<City> l = new ArrayList<City>();
public List<MapObject> getObjects(String filter) {
List<MapObject> l = new ArrayList<MapObject>();
if(region != null){
region.fillWithSuggestedCities(filter, l);
}
@ -36,7 +38,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
}
@Override
public void updateTextView(City obj, TextView txt) {
public void updateTextView(MapObject obj, TextView txt) {
LatLon l = obj.getLocation();
if (getFilter().length() > 2 && location != null && l != null) {
txt.setText(obj.getName(region.useEnglishNames()) + " - " + //$NON-NLS-1$
@ -47,10 +49,14 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
}
@Override
public void itemSelected(City obj) {
OsmandSettings.setLastSearchedCity(this, obj.getId());
if(region.getCityById(obj.getId()) == null){
region.registerCity(obj);
public void itemSelected(MapObject obj) {
if (obj instanceof City) {
OsmandSettings.setLastSearchedCity(this, obj.getId());
if (region.getCityById(obj.getId()) == null) {
region.registerCity((City) obj);
}
} else if(obj instanceof PostCode){
OsmandSettings.setLastSearchedPostcode(this, obj.getName());
}
finish();

View file

@ -12,11 +12,13 @@ import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
import com.osmand.data.PostCode;
import com.osmand.data.Street;
public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region;
private City city;
private PostCode postcode;
private Street street1;
volatile private List<Street> initialList = new ArrayList<Street>();
private List<Street> filterList = new ArrayList<Street>();
@ -24,9 +26,17 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
if(region != null){
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
if(city != null){
if(postcode != null){
street1 = region.getStreetByName(postcode, (OsmandSettings.getLastSearchedStreet(this)));
if(street1 != null){
city = street1.getCity();
}
} else if(city != null){
street1 = region.getStreetByName(city, (OsmandSettings.getLastSearchedStreet(this)));
}
if(city != null){
startLoadDataInThread("Finding streets...");
}
}

View file

@ -11,16 +11,21 @@ import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
import com.osmand.data.PostCode;
import com.osmand.data.Street;
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region;
private City city;
private PostCode postcode;
@Override
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
if(region != null){
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(this));
if (postcode == null) {
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
}
}
super.onCreate(savedInstanceState);
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
@ -29,8 +34,8 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
@Override
public List<Street> getObjects(String filter) {
List<Street> l = new ArrayList<Street>();
if(city != null){
region.fillWithSuggestedStreets(city, filter, l);
if (city != null || postcode != null) {
region.fillWithSuggestedStreets(postcode == null ? city : postcode, filter, l);
}
return l;
}