Make search more discrete
This commit is contained in:
parent
eb7abdd0b8
commit
f7075d82d4
6 changed files with 35 additions and 55 deletions
|
@ -8,7 +8,6 @@ import java.io.IOException;
|
|||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -202,8 +201,9 @@ public class BinaryMapPoiReaderAdapter {
|
|||
return Double.compare(foffsets.get(object1), foffsets.get(object2));
|
||||
}
|
||||
});
|
||||
int p = 0;
|
||||
for (int i = BUCKET_SEARCH_BY_NAME;; i += BUCKET_SEARCH_BY_NAME) {
|
||||
int p = BUCKET_SEARCH_BY_NAME * 3 ;
|
||||
if (p < offKeys.length) {
|
||||
for (int i = p + BUCKET_SEARCH_BY_NAME;; i += BUCKET_SEARCH_BY_NAME) {
|
||||
if (i > offKeys.length) {
|
||||
Arrays.sort(offKeys, p, offKeys.length);
|
||||
break;
|
||||
|
@ -213,6 +213,7 @@ public class BinaryMapPoiReaderAdapter {
|
|||
p = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) +
|
||||
|
|
|
@ -554,8 +554,7 @@ public class IndexCreator {
|
|||
if (indexPOI) {
|
||||
progress.setGeneralProgress("[95 of 100]");
|
||||
progress.startTask("Writing poi index to binary file...", -1);
|
||||
// TODO uncomment
|
||||
// indexPoiCreator.writeBinaryPoiIndex(writer, regionName, progress);
|
||||
indexPoiCreator.writeBinaryPoiIndex(writer, regionName, progress);
|
||||
}
|
||||
|
||||
if (indexTransport) {
|
||||
|
|
|
@ -556,7 +556,6 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
|||
|
||||
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
|
||||
// TODO support cancelling poi search request! Do it in another thread (Check is cancelled()!!!)
|
||||
// TODO make more discrete POI Filter
|
||||
// TODO implement UI to show matching by name subcategories
|
||||
long time = System.currentTimeMillis();
|
||||
IndexPoiCreator poiCreator = new IndexPoiCreator();
|
||||
|
|
|
@ -36,6 +36,7 @@ public class NameFinderPoiFilter extends PoiFilter {
|
|||
public NameFinderPoiFilter(OsmandApplication application) {
|
||||
super(null, application);
|
||||
this.name = application.getString(R.string.poi_filter_nominatim); //$NON-NLS-1$
|
||||
this.distanceToSearchValues = new double[] {1, 2, 5, 10, 20, 30, 100, 250 };
|
||||
this.filterId = FILTER_ID;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,12 @@ public class PoiFilter {
|
|||
protected String name;
|
||||
private final boolean isStandardFilter;
|
||||
|
||||
private final static int finalZoom = 6;
|
||||
private final static int initialZoom = 14;
|
||||
protected int zoom = initialZoom;
|
||||
protected final OsmandApplication application;
|
||||
|
||||
protected int distanceInd = 1;
|
||||
// in kilometers
|
||||
protected double[] distanceToSearchValues = new double[] {1, 2, 3, 5, 10, 30, 100, 250 };
|
||||
|
||||
|
||||
// constructor for standard filters
|
||||
public PoiFilter(AmenityType type, OsmandApplication application){
|
||||
|
@ -68,19 +69,19 @@ public class PoiFilter {
|
|||
for(AmenityType t : AmenityType.values()){
|
||||
acceptedTypes.put(t, null);
|
||||
}
|
||||
distanceToSearchValues = new double[] {0.5, 1, 2, 3, 5, 10, 15, 30, 100};
|
||||
}
|
||||
|
||||
|
||||
public boolean isSearchFurtherAvailable(){
|
||||
return zoom > finalZoom;
|
||||
return distanceInd < distanceToSearchValues.length - 1;
|
||||
}
|
||||
|
||||
protected void searchFurtherIncrement(){
|
||||
zoom --;
|
||||
}
|
||||
|
||||
public List<Amenity> searchFurther(double latitude, double longitude, ResultMatcher<Amenity> matcher){
|
||||
searchFurtherIncrement();
|
||||
if(distanceInd < distanceToSearchValues.length - 1){
|
||||
distanceInd ++;
|
||||
}
|
||||
List<Amenity> amenityList = searchAmenities(this, latitude, longitude, matcher);
|
||||
MapUtils.sortListOfMapObject(amenityList, latitude, longitude);
|
||||
|
||||
|
@ -88,28 +89,20 @@ public class PoiFilter {
|
|||
}
|
||||
|
||||
public String getSearchArea(){
|
||||
if(zoom <= 14){
|
||||
int d = (int) (1 * (1 << (14 - zoom)));
|
||||
return " < " + d + " " + application.getString(R.string.km); //$NON-NLS-1$//$NON-NLS-2$
|
||||
double val = distanceToSearchValues[distanceInd];
|
||||
if(val >= 1){
|
||||
return " < " + ((int) val)+ " " + application.getString(R.string.km); //$NON-NLS-1$//$NON-NLS-2$
|
||||
} else {
|
||||
return " < 500 " + application.getString(R.string.m); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public void clearPreviousZoom(){
|
||||
zoom = getInitialZoom();
|
||||
}
|
||||
|
||||
protected int getInitialZoom(){
|
||||
int zoom = initialZoom;
|
||||
if(areAllTypesAccepted()){
|
||||
zoom += 1;
|
||||
}
|
||||
return zoom;
|
||||
distanceInd = 0;
|
||||
}
|
||||
|
||||
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher){
|
||||
zoom = getInitialZoom();
|
||||
clearPreviousZoom();
|
||||
List<Amenity> amenityList = searchAmenities(this, lat, lon, matcher);
|
||||
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
||||
if (firstTimeLimit > 0) {
|
||||
|
@ -121,12 +114,14 @@ public class PoiFilter {
|
|||
}
|
||||
|
||||
private List<Amenity> searchAmenities(PoiFilter poiFilter, double lat, double lon, ResultMatcher<Amenity> matcher) {
|
||||
double tileNumberX = MapUtils.getTileNumberX(zoom, lon);
|
||||
double tileNumberY = MapUtils.getTileNumberY(zoom, lat);
|
||||
double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY - 0.5);
|
||||
double bottomLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY + 0.5);
|
||||
double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX - 0.5);
|
||||
double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 0.5);
|
||||
double baseDistY = MapUtils.getDistance(lat, lon, lat - 1, lon);
|
||||
double baseDistX = MapUtils.getDistance(lat, lon, lat, lon - 1);
|
||||
double distance = distanceToSearchValues[distanceInd] * 1000;
|
||||
|
||||
double topLatitude = lat + (distance/ baseDistY );
|
||||
double bottomLatitude = lat - (distance/ baseDistY );
|
||||
double leftLongitude = lon - (distance / baseDistX);
|
||||
double rightLongitude = lon + (distance/ baseDistX);
|
||||
|
||||
return searchAmenities(poiFilter, lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, matcher);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public class SearchByNameFilter extends PoiFilter {
|
|||
|
||||
public SearchByNameFilter(OsmandApplication application) {
|
||||
super(application.getString(R.string.poi_filter_by_name), FILTER_ID, new LinkedHashMap<AmenityType, LinkedHashSet<String>>(), application);
|
||||
this.distanceToSearchValues = new double[] {100, 1000, 5000};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,22 +38,6 @@ public class SearchByNameFilter extends PoiFilter {
|
|||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInitialZoom() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchFurtherAvailable() {
|
||||
return zoom >= 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Amenity> searchFurther(double latitude, double longitude, ResultMatcher<Amenity> matcher) {
|
||||
zoom -= 3;
|
||||
return super.searchFurther(latitude, longitude, matcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Amenity> searchAmenities(PoiFilter poiFilter, double lat, double lon, double topLatitude,
|
||||
double bottomLatitude, double leftLongitude, double rightLongitude, ResultMatcher<Amenity> matcher) {
|
||||
|
|
Loading…
Reference in a new issue