Proper sort indexes for search
This commit is contained in:
parent
3a22cab194
commit
300a9530ff
3 changed files with 34 additions and 9 deletions
|
@ -12,11 +12,9 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StringMatcher;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion;
|
||||
import net.osmand.binary.OsmandOdb.AddressNameIndexDataAtom;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressIndex.CitiesIndex;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressNameIndexData;
|
||||
|
|
|
@ -160,6 +160,7 @@ public class BinaryMapIndexReader {
|
|||
routingIndexes = new ArrayList<RouteRegion>(referenceToSameFile.routingIndexes);
|
||||
indexes = new ArrayList<BinaryIndexPart>(referenceToSameFile.indexes);
|
||||
basemap = referenceToSameFile.basemap;
|
||||
calculateCenterPointForRegions();
|
||||
}
|
||||
|
||||
|
||||
|
@ -268,14 +269,20 @@ public class BinaryMapIndexReader {
|
|||
for (MapIndex map : mapIndexes) {
|
||||
if (Algorithms.objectEquals(reg.name, map.name)) {
|
||||
if (map.getRoots().size() > 0) {
|
||||
MapRoot mapRoot = map.getRoots().get(map.getRoots().size() - 1);
|
||||
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(cy, cx);
|
||||
reg.calculatedCenter = map.getCenterLatLon();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(reg.calculatedCenter == null) {
|
||||
for (RouteRegion map : routingIndexes) {
|
||||
if (Algorithms.objectEquals(reg.name, map.name)) {
|
||||
reg.calculatedCenter = new LatLon(map.getTopLatitude() / 2 + map.getBottomLatitude() / 2,
|
||||
map.getLeftLongitude() / 2 + map.getRightLongitude() / 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +293,7 @@ public class BinaryMapIndexReader {
|
|||
public List<MapIndex> getMapIndexes() {
|
||||
return mapIndexes;
|
||||
}
|
||||
|
||||
|
||||
public List<RouteRegion> getRoutingIndexes() {
|
||||
return routingIndexes;
|
||||
}
|
||||
|
@ -1796,6 +1803,16 @@ public class BinaryMapIndexReader {
|
|||
return null;
|
||||
}
|
||||
|
||||
public LatLon getCenterLatLon() {
|
||||
if(roots.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
MapRoot mapRoot = roots.get(roots.size() - 1);
|
||||
double cy = (MapUtils.get31LatitudeY(mapRoot.getBottom()) + MapUtils.get31LatitudeY(mapRoot.getTop())) / 2;
|
||||
double cx = (MapUtils.get31LongitudeX(mapRoot.getLeft()) + MapUtils.get31LongitudeX(mapRoot.getRight())) / 2;
|
||||
return new LatLon(cy, cx);
|
||||
}
|
||||
|
||||
public List<MapRoot> getRoots() {
|
||||
return roots;
|
||||
}
|
||||
|
|
|
@ -423,8 +423,18 @@ public class SearchPhrase {
|
|||
|
||||
@Override
|
||||
public int compare(BinaryMapIndexReader o1, BinaryMapIndexReader o2) {
|
||||
LatLon rc1 = o1.getRegionCenter();
|
||||
LatLon rc2 = o2.getRegionCenter();
|
||||
LatLon rc1 = null;
|
||||
if(o1.containsMapData()) {
|
||||
rc1 = o1.getMapIndexes().get(0).getCenterLatLon();
|
||||
} else {
|
||||
rc1 = o2.getRegionCenter();
|
||||
}
|
||||
LatLon rc2 = null;
|
||||
if(o2.containsMapData()) {
|
||||
rc2 = o2.getMapIndexes().get(0).getCenterLatLon();
|
||||
} else {
|
||||
rc2 = o2.getRegionCenter();
|
||||
}
|
||||
double d1 = rc1 == null ? 10000000d : MapUtils.getDistance(rc1, ll);
|
||||
double d2 = rc2 == null ? 10000000d : MapUtils.getDistance(rc2, ll);
|
||||
return Double.compare(d1, d2);
|
||||
|
|
Loading…
Reference in a new issue