Improve cahcing for osmand regions
This commit is contained in:
parent
bc297d0988
commit
f2c6e08fb3
2 changed files with 24 additions and 46 deletions
|
@ -268,18 +268,19 @@ public class OsmandRegions {
|
||||||
return Math.abs(area);
|
return Math.abs(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BinaryMapDataObject> getCountries(int tile31x, int tile31y) {
|
private List<BinaryMapDataObject> getCountries(int lx, int rx, int ty, int by) throws IOException {
|
||||||
HashSet<String> set = new HashSet<String>(quadTree.queryInBox(new QuadRect(tile31x, tile31y, tile31x, tile31y),
|
HashSet<String> set = new HashSet<String>(quadTree.queryInBox(new QuadRect(lx, ty, rx, by),
|
||||||
new ArrayList<String>()));
|
new ArrayList<String>()));
|
||||||
List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
|
List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
|
||||||
Iterator<String> it = set.iterator();
|
Iterator<String> it = set.iterator();
|
||||||
|
int mx = lx / 2 + rx / 2;
|
||||||
|
int my = ty / 2 + by / 2;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String cname = it.next();
|
String cname = it.next();
|
||||||
BinaryMapDataObject container = null;
|
BinaryMapDataObject container = null;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (BinaryMapDataObject bo : countriesByDownloadName.get(cname)) {
|
for (BinaryMapDataObject bo : countriesByDownloadName.get(cname)) {
|
||||||
if (contain(bo, tile31x, tile31y)) {
|
if (contain(bo, mx, my)) {
|
||||||
count++;
|
count++;
|
||||||
container = bo;
|
container = bo;
|
||||||
break;
|
break;
|
||||||
|
@ -314,51 +315,26 @@ public class OsmandRegions {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<BinaryMapDataObject> query(int lx, int rx, int ty, int by) throws IOException {
|
||||||
|
if (quadTree != null) {
|
||||||
|
return getCountries(lx, rx, ty, by);
|
||||||
|
}
|
||||||
|
return queryBboxNoInit(lx, rx, ty, by);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<BinaryMapDataObject> query(final int tile31x, final int tile31y) throws IOException {
|
public List<BinaryMapDataObject> query(final int tile31x, final int tile31y) throws IOException {
|
||||||
if (quadTree != null) {
|
if (quadTree != null) {
|
||||||
return getCountries(tile31x, tile31y);
|
return getCountries(tile31x, tile31x, tile31y, tile31y);
|
||||||
}
|
}
|
||||||
return queryNoInit(tile31x, tile31y);
|
return queryBboxNoInit(tile31x, tile31x, tile31y, tile31y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized List<BinaryMapDataObject> queryNoInit(final int tile31x, final int tile31y) throws IOException {
|
|
||||||
final List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
|
private synchronized List<BinaryMapDataObject> queryBboxNoInit(int lx, int rx, int ty, int by) throws IOException {
|
||||||
BinaryMapIndexReader.SearchRequest<BinaryMapDataObject> sr = BinaryMapIndexReader.buildSearchRequest(tile31x, tile31x, tile31y, tile31y,
|
|
||||||
5, new BinaryMapIndexReader.SearchFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(TIntArrayList types, BinaryMapIndexReader.MapIndex index) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}, new ResultMatcher<BinaryMapDataObject>() {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean publish(BinaryMapDataObject object) {
|
|
||||||
if (object.getPointsLength() < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
initTypes(object);
|
|
||||||
if (contain(object, tile31x, tile31y)) {
|
|
||||||
result.add(object);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (reader != null) {
|
|
||||||
reader.searchMapIndex(sr);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized List<BinaryMapDataObject> queryBbox(int lx, int rx, int ty, int by) throws IOException {
|
|
||||||
final List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
|
final List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
|
||||||
|
int mx = lx / 2 + rx / 2;
|
||||||
|
int my = ty / 2 + by / 2;
|
||||||
BinaryMapIndexReader.SearchRequest<BinaryMapDataObject> sr = BinaryMapIndexReader.buildSearchRequest(lx, rx, ty, by,
|
BinaryMapIndexReader.SearchRequest<BinaryMapDataObject> sr = BinaryMapIndexReader.buildSearchRequest(lx, rx, ty, by,
|
||||||
5, new BinaryMapIndexReader.SearchFilter() {
|
5, new BinaryMapIndexReader.SearchFilter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -373,7 +349,9 @@ public class OsmandRegions {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
initTypes(object);
|
initTypes(object);
|
||||||
result.add(object);
|
if (contain(object, mx, my)) {
|
||||||
|
result.add(object);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,7 +725,7 @@ public class OsmandRegions {
|
||||||
|
|
||||||
List<BinaryMapDataObject> mapDataObjects;
|
List<BinaryMapDataObject> mapDataObjects;
|
||||||
try {
|
try {
|
||||||
mapDataObjects = queryBbox(point31x, point31x, point31y, point31y);
|
mapDataObjects = queryBboxNoInit(point31x, point31x, point31y, point31y);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOException("Error while calling queryBbox");
|
throw new IOException("Error while calling queryBbox");
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,7 +281,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
||||||
int bottom = MapUtils.get31TileNumberY(rb.getLatitude());
|
int bottom = MapUtils.get31TileNumberY(rb.getLatitude());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = osmandRegions.queryBbox(left, right, top, bottom);
|
result = osmandRegions.query(left, right, top, bottom);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue