Fix poi display with track

This commit is contained in:
Victor Shcherb 2015-05-02 20:37:56 +02:00
parent af920a70c3
commit 6c80487bfe
2 changed files with 30 additions and 24 deletions

View file

@ -4,6 +4,7 @@ package net.osmand.binary;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.TIntObjectMap; import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap;
import gnu.trove.set.hash.TIntHashSet; import gnu.trove.set.hash.TIntHashSet;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@ -1419,7 +1420,7 @@ public class BinaryMapIndexReader {
SearchPoiTypeFilter poiTypeFilter, ResultMatcher<Amenity> resultMatcher) { SearchPoiTypeFilter poiTypeFilter, ResultMatcher<Amenity> resultMatcher) {
SearchRequest<Amenity> request = new SearchRequest<Amenity>(); SearchRequest<Amenity> request = new SearchRequest<Amenity>();
float coeff = (float) (radius / MapUtils.getTileDistanceWidth(SearchRequest.ZOOM_TO_SEARCH_POI)); float coeff = (float) (radius / MapUtils.getTileDistanceWidth(SearchRequest.ZOOM_TO_SEARCH_POI));
TIntObjectHashMap<List<Location>> zooms = new TIntObjectHashMap<List<Location>>(); TLongObjectHashMap<List<Location>> zooms = new TLongObjectHashMap<List<Location>>();
for(int i = 1; i < route.size(); i++) { for(int i = 1; i < route.size(); i++) {
Location cr = route.get(i); Location cr = route.get(i);
Location pr = route.get(i - 1); Location pr = route.get(i - 1);
@ -1433,7 +1434,7 @@ public class BinaryMapIndexReader {
double bottomRightY = Math.max(ty, py) + coeff; double bottomRightY = Math.max(ty, py) + coeff;
for(int x = (int) topLeftX; x <= bottomRightX; x++) { for(int x = (int) topLeftX; x <= bottomRightX; x++) {
for(int y = (int) topLeftY; y <= bottomRightY; y++) { for(int y = (int) topLeftY; y <= bottomRightY; y++) {
int hash = (x << SearchRequest.ZOOM_TO_SEARCH_POI) + y; long hash = (((long)x) << SearchRequest.ZOOM_TO_SEARCH_POI) + y;
if(!zooms.containsKey(hash)) { if(!zooms.containsKey(hash)) {
zooms.put(hash, new LinkedList<Location>()); zooms.put(hash, new LinkedList<Location>());
} }
@ -1444,14 +1445,14 @@ public class BinaryMapIndexReader {
} }
} }
int sleft = 0, sright = Integer.MAX_VALUE, stop = 0, sbottom = Integer.MAX_VALUE; int sleft = Integer.MAX_VALUE , sright = 0, stop = Integer.MAX_VALUE, sbottom = 0;
for(int vl : zooms.keys()) { for(long vl : zooms.keys()) {
int x = (vl >> SearchRequest.ZOOM_TO_SEARCH_POI) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI); long x = (vl >> SearchRequest.ZOOM_TO_SEARCH_POI) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
int y = (vl & ((1 << SearchRequest.ZOOM_TO_SEARCH_POI) -1)) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI); long y = (vl & ((1 << SearchRequest.ZOOM_TO_SEARCH_POI) -1)) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
sleft = Math.min(x, sleft); sleft = (int) Math.min(x, sleft);
stop = Math.min(y, stop); stop = (int) Math.min(y, stop);
sbottom = Math.max(y, sbottom); sbottom = (int) Math.max(y, sbottom);
sright = Math.max(x, sright); sright = (int) Math.max(x, sright);
} }
request.radius = radius; request.radius = radius;
request.left = sleft; request.left = sleft;
@ -1601,7 +1602,7 @@ public class BinaryMapIndexReader {
// search on the path // search on the path
// stores tile of 16 index and pairs (even length always) of points intersecting tile // stores tile of 16 index and pairs (even length always) of points intersecting tile
TIntObjectHashMap<List<Location>> tiles = null; TLongObjectHashMap<List<Location>> tiles = null;
double radius = -1; double radius = -1;
@ -1631,9 +1632,9 @@ public class BinaryMapIndexReader {
protected SearchRequest(){ protected SearchRequest(){
} }
public int getTileHashOnPath(double lat, double lon) { public long getTileHashOnPath(double lat, double lon) {
int x = (int) MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, lon); long x = (int) MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, lon);
int y = (int) MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, lat); long y = (int) MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, lat);
return (x << SearchRequest.ZOOM_TO_SEARCH_POI) | y; return (x << SearchRequest.ZOOM_TO_SEARCH_POI) | y;
} }
@ -1940,6 +1941,7 @@ public class BinaryMapIndexReader {
private static boolean testMapSearch = false; private static boolean testMapSearch = false;
private static boolean testAddressSearch = false; private static boolean testAddressSearch = false;
private static boolean testPoiSearch = false; private static boolean testPoiSearch = false;
private static boolean testPoiSearchOnPath = true;
private static boolean testTransportSearch = false; private static boolean testTransportSearch = false;
private static int sleft = MapUtils.get31TileNumberX(6.3); private static int sleft = MapUtils.get31TileNumberX(6.3);
private static int sright = MapUtils.get31TileNumberX(6.5); private static int sright = MapUtils.get31TileNumberX(6.5);
@ -1952,7 +1954,7 @@ public class BinaryMapIndexReader {
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile("", "r"); RandomAccessFile raf = new RandomAccessFile("/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf", "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf); BinaryMapIndexReader reader = new BinaryMapIndexReader(raf);
println("VERSION " + reader.getVersion()); //$NON-NLS-1$ println("VERSION " + reader.getVersion()); //$NON-NLS-1$
@ -1969,11 +1971,15 @@ public class BinaryMapIndexReader {
testTransportSearch(reader); testTransportSearch(reader);
} }
if (testPoiSearch) { if (testPoiSearch || testPoiSearchOnPath) {
PoiRegion poiRegion = reader.getPoiIndexes().get(0); PoiRegion poiRegion = reader.getPoiIndexes().get(0);
testPoiSearch(reader, poiRegion); if(testPoiSearch) {
testPoiSearchByName(reader); testPoiSearch(reader, poiRegion);
testSearchOnthePath(reader); testPoiSearchByName(reader);
}
if(testPoiSearchOnPath) {
testSearchOnthePath(reader);
}
} }
println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); //$NON-NLS-1$ println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); //$NON-NLS-1$
@ -1986,7 +1992,7 @@ public class BinaryMapIndexReader {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
println("Searching poi on the path..."); println("Searching poi on the path...");
final List<Location> locations = readGPX(new File( final List<Location> locations = readGPX(new File(
"")); "/Users/victorshcherb/osmand/maps/2015-03-07_19-07_Sat.gpx"));
SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() { SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() {
@Override @Override
public boolean accept(PoiCategory type, String subcategory) { public boolean accept(PoiCategory type, String subcategory) {

View file

@ -324,7 +324,7 @@ public class BinaryMapPoiReaderAdapter {
LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) + LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) +
"ms. Found " + offKeys.length +" subtress"); "ms. Found " + offKeys.length +" subtrees");
for (int j = 0; j < offKeys.length; j++) { for (int j = 0; j < offKeys.length; j++) {
codedIS.seek(offKeys[j] + indexOffset); codedIS.seek(offKeys[j] + indexOffset);
int len = readInt(); int len = readInt();
@ -482,7 +482,7 @@ public class BinaryMapPoiReaderAdapter {
skipTiles.clear(); skipTiles.clear();
} }
LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) + LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) +
"ms. Found " + offsets.length +" subtress"); "ms. Found " + offsets.length +" subtrees");
for (int j = 0; j < offsets.length; j++) { for (int j = 0; j < offsets.length; j++) {
codedIS.seek(offsets[j] + indexOffset); codedIS.seek(offsets[j] + indexOffset);
int len = readInt(); int len = readInt();
@ -866,8 +866,8 @@ public class BinaryMapPoiReaderAdapter {
long l = ((((x << zoom) | y) << 5) | zoom); long l = ((((x << zoom) | y) << 5) | zoom);
boolean read = true; boolean read = true;
if(req.tiles != null) { if(req.tiles != null) {
int zx = x << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom); long zx = x << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom);
int zy = y << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom); long zy = y << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom);
read = req.tiles.contains((zx << SearchRequest.ZOOM_TO_SEARCH_POI) + zy); read = req.tiles.contains((zx << SearchRequest.ZOOM_TO_SEARCH_POI) + zy);
} }
int offset = readInt(); int offset = readInt();