Small changes in search address

This commit is contained in:
Victor Shcherb 2011-09-13 08:34:08 +02:00
parent 1f807756ee
commit b32ea87c04
6 changed files with 63 additions and 6 deletions

View file

@ -24,6 +24,8 @@ public class BinaryMapAddressReaderAdapter {
int postcodesOffset = -1;
int villagesOffset = -1;
int citiesOffset = -1;
LatLon calculatedCenter = null;
}
private CodedInputStreamRAF codedIS;

View file

@ -124,6 +124,7 @@ public class BinaryMapIndexReader {
break;
case OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER :
int cversion = codedIS.readUInt32();
calculateCenterPointForRegions();
initCorrectly = cversion == version;
break;
default:
@ -133,6 +134,22 @@ public class BinaryMapIndexReader {
}
}
private void calculateCenterPointForRegions(){
for(AddressRegion reg : addressIndexes){
for(MapIndex map : mapIndexes){
if(Algoritms.objectEquals(reg.name, map.name)){
if(map.getRoots().size() > 0){
MapRoot mapRoot = map.getRoots().get(0);
double cy = (MapUtils.get31LatitudeY(mapRoot.getBottom()) + MapUtils.get31LatitudeY(mapRoot.getTop())) / 2;
double cx = (MapUtils.get31LongitudeX(mapRoot.getLeft()) + MapUtils.get31LongitudeX(mapRoot.getRight())) / 2;
reg.calculatedCenter = new LatLon(cx, cy);
break;
}
}
}
}
}
public List<BinaryIndexPart> getIndexes() {
return indexes;
}
@ -285,7 +302,6 @@ public class BinaryMapIndexReader {
/**
* Address public methods
*/
public List<String> getRegionNames(){
List<String> names = new ArrayList<String>();
for(AddressRegion r : addressIndexes){
@ -294,6 +310,14 @@ public class BinaryMapIndexReader {
return names;
}
public LatLon getRegionCenter(String name) {
AddressRegion rg = getRegionByName(name);
if (rg != null) {
return rg.calculatedCenter;
}
return null;
}
private AddressRegion getRegionByName(String name){
for(AddressRegion r : addressIndexes){
if(r.name.equals(name)){

View file

@ -834,18 +834,43 @@ public class OsmandSettings {
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$
public static final String LAST_SEARCHED_LAT = "last_searched_lat"; //$NON-NLS-1$
public static final String LAST_SEARCHED_LON = "last_searched_lon"; //$NON-NLS-1$
public LatLon getLastSearchedPoint(){
if(globalPreferences.contains(LAST_SEARCHED_LAT) && globalPreferences.contains(LAST_SEARCHED_LON)){
return new LatLon(globalPreferences.getFloat(LAST_SEARCHED_LAT, 0),
globalPreferences.getFloat(LAST_SEARCHED_LON, 0));
}
return null;
}
public boolean setLastSearchedPoint(LatLon l){
if(l == null){
return globalPreferences.edit().remove(LAST_SEARCHED_LAT).remove(LAST_SEARCHED_LON).commit();
} else {
return setLastSearchedPoint(l.getLatitude(), l.getLongitude());
}
}
public boolean setLastSearchedPoint(double lat, double lon){
return globalPreferences.edit().putFloat(LAST_SEARCHED_LAT, (float) lat).
putFloat(LAST_SEARCHED_LON, (float) lon).commit();
}
public String getLastSearchedRegion() {
return globalPreferences.getString(LAST_SEARCHED_REGION, ""); //$NON-NLS-1$
}
public boolean setLastSearchedRegion(String region) {
public boolean setLastSearchedRegion(String region, LatLon l) {
Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_REGION, region).putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET,
"").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ //$NON-NLS-2$
if (globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) {
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
}
return edit.commit();
boolean res = edit.commit();
setLastSearchedPoint(l);
return res;
}
public String getLastSearchedPostcode(){

View file

@ -77,6 +77,9 @@ public interface RegionAddressRepository {
public void addCityToPreloadedList(City city);
public LatLon getEstimatedRegionCenter();
public boolean isMapRepository();
// is called on low memory

View file

@ -320,7 +320,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
@Override
public boolean arePostcodesPreloaded() {
// postcodes are always preloaded
// postcodes are always preeloaded
// do not load them into memory (just cache last used)
return true;
}
@ -332,6 +332,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
}
@Override
public LatLon getEstimatedRegionCenter() {
return file.getRegionCenter(region);
}
}

View file

@ -35,7 +35,7 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
@Override
public void itemSelected(RegionAddressRepository obj) {
OsmandSettings.getOsmandSettings(this).setLastSearchedRegion(obj.getName());
OsmandSettings.getOsmandSettings(this).setLastSearchedRegion(obj.getName(), obj.getEstimatedRegionCenter());
finish();
}