Fix issue during poi map init
This commit is contained in:
parent
c10adff813
commit
5bf8c30d58
7 changed files with 41 additions and 67 deletions
|
@ -1098,8 +1098,11 @@ public class BinaryInspector {
|
|||
|
||||
index.initCategories(p);
|
||||
println("\tRegion: " + p.name);
|
||||
println("\t\tBounds " + formatLatBounds(p.getLeftLongitude(), p.getRightLongitude(),
|
||||
p.getTopLatitude(), p.getBottomLatitude()));
|
||||
|
||||
println("\t\tBounds " + formatLatBounds(MapUtils.get31LongitudeX(p.left31),
|
||||
MapUtils.get31LongitudeX(p.right31),
|
||||
MapUtils.get31LatitudeY(p.top31),
|
||||
MapUtils.get31LatitudeY(p.bottom31)));
|
||||
println("\t\tCategories:");
|
||||
for (int i = 0; i < p.categories.size(); i++) {
|
||||
println("\t\t\t" + p.categories.get(i));
|
||||
|
|
|
@ -321,25 +321,7 @@ public class BinaryMapIndexReader {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean containsPoiData(double latitude, double longitude) {
|
||||
for (PoiRegion index : poiIndexes) {
|
||||
if (index.rightLongitude >= longitude && index.leftLongitude <= longitude &&
|
||||
index.topLatitude >= latitude && index.bottomLatitude <= latitude) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsPoiData(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
|
||||
for (PoiRegion index : poiIndexes) {
|
||||
if (index.rightLongitude >= leftLongitude && index.leftLongitude <= rightLongitude &&
|
||||
index.topLatitude >= bottomLatitude && index.bottomLatitude <= topLatitude) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsPoiData(int left31x, int top31y, int right31x, int bottom31y) {
|
||||
for (PoiRegion index : poiIndexes) {
|
||||
|
@ -2216,8 +2198,10 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
|
||||
private static void testPoiSearch(BinaryMapIndexReader reader, PoiRegion poiRegion) throws IOException {
|
||||
println(poiRegion.leftLongitude + " " + poiRegion.rightLongitude + " " + poiRegion.bottomLatitude + " "
|
||||
+ poiRegion.topLatitude);
|
||||
|
||||
println(MapUtils.get31LongitudeX(poiRegion.left31) + " " + MapUtils.get31LongitudeX(poiRegion.right31) +
|
||||
" " +MapUtils.get31LatitudeY( poiRegion.bottom31 )+ " "
|
||||
+ MapUtils.get31LatitudeY(poiRegion.top31));
|
||||
for (int i = 0; i < poiRegion.categories.size(); i++) {
|
||||
println(poiRegion.categories.get(i));
|
||||
println(" " + poiRegion.subcategories.get(i));
|
||||
|
|
|
@ -55,19 +55,11 @@ public class BinaryMapPoiReaderAdapter {
|
|||
List<List<String>> subcategories = new ArrayList<List<String>>();
|
||||
List<PoiSubType> subTypes = new ArrayList<PoiSubType>();
|
||||
|
||||
double leftLongitude;
|
||||
double rightLongitude;
|
||||
double topLatitude;
|
||||
double bottomLatitude;
|
||||
int left31;
|
||||
int right31;
|
||||
int top31;
|
||||
int bottom31;
|
||||
|
||||
public double getLeftLongitude() {
|
||||
return leftLongitude;
|
||||
}
|
||||
|
||||
public String getPartName() {
|
||||
return "POI";
|
||||
}
|
||||
|
@ -98,17 +90,6 @@ public class BinaryMapPoiReaderAdapter {
|
|||
return null;
|
||||
}
|
||||
|
||||
public double getRightLongitude() {
|
||||
return rightLongitude;
|
||||
}
|
||||
|
||||
public double getTopLatitude() {
|
||||
return topLatitude;
|
||||
}
|
||||
|
||||
public double getBottomLatitude() {
|
||||
return bottomLatitude;
|
||||
}
|
||||
}
|
||||
|
||||
private CodedInputStream codedIS;
|
||||
|
@ -139,19 +120,15 @@ public class BinaryMapPoiReaderAdapter {
|
|||
return;
|
||||
case OsmandOdb.OsmAndTileBox.LEFT_FIELD_NUMBER:
|
||||
region.left31 = codedIS.readUInt32();
|
||||
region.leftLongitude = MapUtils.get31LongitudeX(region.left31);
|
||||
break;
|
||||
case OsmandOdb.OsmAndTileBox.RIGHT_FIELD_NUMBER:
|
||||
region.right31 = codedIS.readUInt32();
|
||||
region.rightLongitude = MapUtils.get31LongitudeX(region.right31);
|
||||
break;
|
||||
case OsmandOdb.OsmAndTileBox.TOP_FIELD_NUMBER:
|
||||
region.top31 = codedIS.readUInt32();
|
||||
region.topLatitude = MapUtils.get31LatitudeY(region.top31);
|
||||
break;
|
||||
case OsmandOdb.OsmAndTileBox.BOTTOM_FIELD_NUMBER:
|
||||
region.bottom31 = codedIS.readUInt32();
|
||||
region.bottomLatitude = MapUtils.get31LatitudeY(region.bottom31);
|
||||
break;
|
||||
default:
|
||||
skipUnknownField(t);
|
||||
|
|
|
@ -111,10 +111,10 @@ public class CachedOsmandIndexes {
|
|||
if(index.getName() != null) {
|
||||
poi.setName(index.getName());
|
||||
}
|
||||
poi.setLeft(MapUtils.get31TileNumberX(index.getLeftLongitude()));
|
||||
poi.setRight(MapUtils.get31TileNumberX(index.getRightLongitude()));
|
||||
poi.setTop(MapUtils.get31TileNumberY(index.getTopLatitude()));
|
||||
poi.setBottom(MapUtils.get31TileNumberY(index.getBottomLatitude()));
|
||||
poi.setLeft(index.left31);
|
||||
poi.setRight(index.right31);
|
||||
poi.setTop(index.top31);
|
||||
poi.setBottom(index.bottom31);
|
||||
fileIndex.addPoiIndex(poi.build());
|
||||
}
|
||||
|
||||
|
@ -250,10 +250,10 @@ public class CachedOsmandIndexes {
|
|||
mi.length = (int) index.getSize();
|
||||
mi.filePointer = (int) index.getOffset();
|
||||
mi.name = index.getName();
|
||||
mi.leftLongitude = MapUtils.get31LongitudeX(index.getLeft());
|
||||
mi.rightLongitude = MapUtils.get31LongitudeX(index.getRight());
|
||||
mi.topLatitude =MapUtils.get31LatitudeY(index.getTop());
|
||||
mi.bottomLatitude = MapUtils.get31LatitudeY(index.getBottom());
|
||||
mi.left31 = index.getLeft();
|
||||
mi.right31 = index.getRight();
|
||||
mi.top31 = index.getTop();
|
||||
mi.bottom31 = index.getBottom();
|
||||
reader.poiIndexes.add(mi);
|
||||
reader.indexes.add(mi);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public interface AmenityIndexRepository {
|
|||
|
||||
public boolean checkContains(double latitude, double longitude);
|
||||
|
||||
public boolean checkContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude);
|
||||
public boolean checkContainsInt(int top31, int left31, int bottom31, int right31);
|
||||
|
||||
/**
|
||||
* Search amenities in the specified box doesn't cache results
|
||||
|
|
|
@ -40,12 +40,14 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
|
|||
|
||||
@Override
|
||||
public boolean checkContains(double latitude, double longitude) {
|
||||
return index.containsPoiData(latitude, longitude);
|
||||
int x31 = MapUtils.get31TileNumberX(longitude);
|
||||
int y31 = MapUtils.get31TileNumberY(latitude);
|
||||
return index.containsPoiData(x31, y31, x31, y31);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
|
||||
return index.containsPoiData(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
|
||||
public boolean checkContainsInt(int top31, int left31, int bottom31, int right31) {
|
||||
return index.containsPoiData(top31, left31, bottom31, right31);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -756,15 +756,18 @@ public class ResourceManager {
|
|||
searchAmenitiesInProgress = true;
|
||||
try {
|
||||
if (!filter.isEmpty()) {
|
||||
int top31 = MapUtils.get31TileNumberY(topLatitude);
|
||||
int left31 = MapUtils.get31TileNumberX(leftLongitude);
|
||||
int bottom31 = MapUtils.get31TileNumberY(bottomLatitude);
|
||||
int right31 = MapUtils.get31TileNumberX(rightLongitude);
|
||||
for (AmenityIndexRepository index : amenityRepositories.values()) {
|
||||
if (matcher != null && matcher.isCancelled()) {
|
||||
searchAmenitiesInProgress = false;
|
||||
break;
|
||||
}
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
List<Amenity> r = index.searchAmenities(MapUtils.get31TileNumberY(topLatitude),
|
||||
MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberY(bottomLatitude),
|
||||
MapUtils.get31TileNumberX(rightLongitude), zoom, filter, matcher);
|
||||
if (index.checkContainsInt(top31, left31, bottom31, right31)) {
|
||||
List<Amenity> r = index.searchAmenities(top31,
|
||||
left31, bottom31, right31, zoom, filter, matcher);
|
||||
if(r != null) {
|
||||
amenities.addAll(r);
|
||||
}
|
||||
|
@ -796,7 +799,11 @@ public class ResourceManager {
|
|||
}
|
||||
if (!filter.isEmpty()) {
|
||||
for (AmenityIndexRepository index : amenityRepositories.values()) {
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
if (index.checkContainsInt(
|
||||
MapUtils.get31TileNumberY(topLatitude),
|
||||
MapUtils.get31TileNumberX(leftLongitude),
|
||||
MapUtils.get31TileNumberY(bottomLatitude),
|
||||
MapUtils.get31TileNumberX(rightLongitude))) {
|
||||
repos.add(index);
|
||||
}
|
||||
}
|
||||
|
@ -835,12 +842,16 @@ public class ResourceManager {
|
|||
double lat, double lon, ResultMatcher<Amenity> matcher) {
|
||||
List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>();
|
||||
int left = MapUtils.get31TileNumberX(leftLongitude);
|
||||
int top = MapUtils.get31TileNumberY(topLatitude);
|
||||
int right = MapUtils.get31TileNumberX(rightLongitude);
|
||||
int bottom = MapUtils.get31TileNumberY(bottomLatitude);
|
||||
for (AmenityIndexRepository index : amenityRepositories.values()) {
|
||||
if (matcher != null && matcher.isCancelled()) {
|
||||
break;
|
||||
}
|
||||
if (index instanceof AmenityIndexRepositoryBinary) {
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
if (index.checkContainsInt(top, left, bottom, right)) {
|
||||
if(index.checkContains(lat, lon)){
|
||||
list.add(0, (AmenityIndexRepositoryBinary) index);
|
||||
} else {
|
||||
|
@ -850,10 +861,7 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
int left = MapUtils.get31TileNumberX(leftLongitude);
|
||||
int top = MapUtils.get31TileNumberY(topLatitude);
|
||||
int right = MapUtils.get31TileNumberX(rightLongitude);
|
||||
int bottom = MapUtils.get31TileNumberY(bottomLatitude);
|
||||
|
||||
// Not using boundares results in very slow initial search if user has many maps installed
|
||||
// int left = 0;
|
||||
// int top = 0;
|
||||
|
|
Loading…
Reference in a new issue