diff --git a/DataExtractionOSM/src/net/osmand/ToDoConstants.java b/DataExtractionOSM/src/net/osmand/ToDoConstants.java index dcdb8f1de7..84fe61bcb0 100644 --- a/DataExtractionOSM/src/net/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/net/osmand/ToDoConstants.java @@ -10,7 +10,7 @@ public class ToDoConstants { // Index // Map QuadTree (skip small areas!!!) - // new Address test Name index!!! + // POI index exclude building hno from categories!!! // slightly changed POI (check it)! // Routing index // Identify coastline areas and pure ocean areas @@ -23,13 +23,6 @@ public class ToDoConstants { // == Osmand application (TODO 127) == // TODO prepare C++ version of routing algorithm - // Map Refactoring -// Remove notification from OsmAndMapTileView (?) - -// === Refactoring issues === -// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. || - - // DONE SWING diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java b/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java index cc0fd19523..b25b5673b9 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryInspector.java @@ -21,9 +21,12 @@ import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion; import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.binary.BinaryMapIndexReader.MapRoot; import net.osmand.binary.BinaryMapIndexReader.SearchFilter; +import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion; import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex; +import net.osmand.data.Amenity; +import net.osmand.data.AmenityType; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; @@ -46,7 +49,7 @@ public class BinaryInspector { // inspector(new String[]{"-v","C:\\Users\\tpd\\osmand\\Housenumbers.obf"}); //inspector(new String[]{"/home/victor/projects/OsmAnd/data/osm-gen/saved/Belarus-newzooms-new-rt.obf"}); // inspector(new String[]{"/home/victor/projects/OsmAnd/download/spain/Spain_europe_1_small.obf"}); - inspector(new String[]{"-vaddress", "/home/victor/projects/OsmAnd/data/osm-gen/Luxembourg.obf"}); + inspector(new String[]{"-vpoi", "/home/victor/projects/OsmAnd/data/osm-gen/Luxembourg.obf"}); // test case extract parts @@ -430,83 +433,12 @@ public class BinaryInspector { i, j++)); } if((verbose != null && verbose.isVmap())){ - final StringBuilder b = new StringBuilder(); - SearchRequest req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(verbose.lonleft), - MapUtils.get31TileNumberX(verbose.lonright), - MapUtils.get31TileNumberY(verbose.lattop), - MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), - new SearchFilter() { - @Override - public boolean accept(TIntArrayList types, MapIndex index) { - return true; - } - }, - new ResultMatcher() { - @Override - public boolean publish(BinaryMapDataObject object) { - boolean way = object.getPointsLength() > 1; - b.setLength(0); - b.append(way ? "Way " : "Point "); - if(object.getName() != null){ - b.append(object.getName()); - } - b.append(" ").append((object.getId() >> 1)).append(" "); - formatTags(object, b); - b.append(" "); - for (int i = 0; i < object.getPointsLength(); i++) { - b.append(" "); - formatPoint(object, i, b); - } - println(b.toString()); - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }); - index.searchMapIndex(req); + printMapDetailInfo(verbose, index); } + } else if(p instanceof PoiRegion && (verbose != null && verbose.isVpoi())){ + printPOIDetailInfo(verbose, index); } else if (p instanceof AddressRegion && (verbose != null && verbose.isVaddress())) { - for(String region : index.getRegionNames()){ - println("\tRegion:" + region); - int[] cityType = new int[] {BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE, - BinaryMapAddressReaderAdapter.POSTCODES_TYPE, - BinaryMapAddressReaderAdapter.VILLAGES_TYPE}; - for (int j = 0; j < cityType.length; j++) { - int type = cityType[j]; - for (City c : index.getCities(region, null, type)) { - println("\t\t" + c + getId(c)); - index.preloadStreets(c, null); - for (Street t : c.getStreets()) { - if (verbose.contains(t)) { - print("\t\t\t" + t.getName() + getId(t)); -// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) { - index.preloadBuildings(t, null); - List buildings = t.getBuildings(); - if (buildings != null && !buildings.isEmpty()) { - print("\t\t ("); - for (Building b : buildings) { - print(b.toString() + ","); - } - print(")"); - } - List streets = t.getIntersectedStreets(); - if (streets != null && !streets.isEmpty()) { - print("\n\t\t\t\t\t\t\t x ("); - for (Street s : streets) { - print(s.getName() +", "); - } - print(")"); - } -// } - println(""); - } - - } - } - } - } + printAddressDetailedInfo(verbose, index); } i++; } @@ -518,6 +450,112 @@ public class BinaryInspector { } } + + private static void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException { + for(String region : index.getRegionNames()){ + println("\tRegion:" + region); + int[] cityType = new int[] {BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE, + BinaryMapAddressReaderAdapter.POSTCODES_TYPE, + BinaryMapAddressReaderAdapter.VILLAGES_TYPE}; + for (int j = 0; j < cityType.length; j++) { + int type = cityType[j]; + for (City c : index.getCities(region, null, type)) { + println("\t\t" + c + getId(c)); + index.preloadStreets(c, null); + for (Street t : c.getStreets()) { + if (verbose.contains(t)) { + print("\t\t\t" + t.getName() + getId(t)); +// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) { + index.preloadBuildings(t, null); + List buildings = t.getBuildings(); + if (buildings != null && !buildings.isEmpty()) { + print("\t\t ("); + for (Building b : buildings) { + print(b.toString() + ","); + } + print(")"); + } + List streets = t.getIntersectedStreets(); + if (streets != null && !streets.isEmpty()) { + print("\n\t\t\t\t\t\t\t x ("); + for (Street s : streets) { + print(s.getName() +", "); + } + print(")"); + } +// } + println(""); + } + + } + } + } + } + } + + private static void printMapDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException { + final StringBuilder b = new StringBuilder(); + SearchRequest req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(verbose.lonleft), + MapUtils.get31TileNumberX(verbose.lonright), + MapUtils.get31TileNumberY(verbose.lattop), + MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), + new SearchFilter() { + @Override + public boolean accept(TIntArrayList types, MapIndex index) { + return true; + } + }, + new ResultMatcher() { + @Override + public boolean publish(BinaryMapDataObject object) { + boolean way = object.getPointsLength() > 1; + b.setLength(0); + b.append(way ? "Way " : "Point "); + if(object.getName() != null){ + b.append(object.getName()); + } + b.append(" ").append((object.getId() >> 1)).append(" "); + formatTags(object, b); + b.append(" "); + for (int i = 0; i < object.getPointsLength(); i++) { + b.append(" "); + formatPoint(object, i, b); + } + println(b.toString()); + return false; + } + @Override + public boolean isCancelled() { + return false; + } + }); + index.searchMapIndex(req); + } + + private static void printPOIDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException { + SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(MapUtils.get31TileNumberX(verbose.lonleft), + MapUtils.get31TileNumberX(verbose.lonright), + MapUtils.get31TileNumberY(verbose.lattop), + MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), + new SearchPoiTypeFilter() { + @Override + public boolean accept(AmenityType type, String subcategory) { + return true; + } + }, + new ResultMatcher() { + @Override + public boolean publish(Amenity object) { + println(object.toString() + " " + object.getLocation()); + return false; + } + @Override + public boolean isCancelled() { + return false; + } + }); + index.searchPoi(req); + } private static String getId(MapObject o ){ if(o.getId() == null) { diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index 0539390e58..2c72d13ab3 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1336,13 +1336,13 @@ public class BinaryMapIndexReader { private static boolean testMapSearch = false; - private static boolean testAddressSearch = true; + private static boolean testAddressSearch = false; private static boolean testPoiSearch = false; private static boolean testTransportSearch = false; - private static int sleft = MapUtils.get31TileNumberX(6); - private static int sright = MapUtils.get31TileNumberX(14); - private static int stop = MapUtils.get31TileNumberY(54); - private static int sbottom = MapUtils.get31TileNumberY(45); + private static int sleft = MapUtils.get31TileNumberX(6.3); + private static int sright = MapUtils.get31TileNumberX(6.5); + private static int stop = MapUtils.get31TileNumberY(49.8); + private static int sbottom = MapUtils.get31TileNumberY(49.3); private static void println(String s){ System.out.println(s); @@ -1360,7 +1360,7 @@ public class BinaryMapIndexReader { } if(testAddressSearch) { testAddressSearchByName(reader); - // testAddressSearch(reader); + testAddressSearch(reader); } if(testTransportSearch) { testTransportSearch(reader); @@ -1378,7 +1378,7 @@ public class BinaryMapIndexReader { private static void testPoiSearchByName(BinaryMapIndexReader reader) throws IOException { println("Searching by name..."); - SearchRequest req = buildSearchPoiRequest(sleft, sright, "kolie", null); + SearchRequest req = buildSearchPoiRequest(sleft, sright, "kol", null); reader.searchPoiByName(req); for (Amenity a : req.getSearchResults()) { println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation()); @@ -1409,18 +1409,13 @@ public class BinaryMapIndexReader { private static void testTransportSearch(BinaryMapIndexReader reader) throws IOException { // test transport for (TransportIndex i : reader.transportIndexes) { - println(i.left + " " + i.right + " " + i.top + " " + i.bottom); - println(i.stringTable.offsets + ""); + println("Transport bounds : " + i.left + " " + i.right + " " + i.top + " " + i.bottom); } { - int sleft = MapUtils.get31TileNumberX(27.573); - int sright = MapUtils.get31TileNumberX(27.581); - int stop = MapUtils.get31TileNumberY(53.912); - int sbottom = MapUtils.get31TileNumberY(53.908); for (TransportStop s : reader.searchTransportIndex(buildSearchTransportRequest(sleft, sright, stop, sbottom, 15, null))) { println(s.getName()); TIntObjectHashMap routes = reader.getTransportRoutes(s.getReferencesToRoutes()); - for (net.osmand.data.TransportRoute route : routes.values()) { + for (net.osmand.data.TransportRoute route : routes.valueCollection()) { println(" " + route.getRef() + " " + route.getName() + " " + route.getDistance() + " " + route.getAvgBothDistance()); } @@ -1430,7 +1425,7 @@ public class BinaryMapIndexReader { for (TransportStop s : reader.searchTransportIndex(buildSearchTransportRequest(sleft, sright, stop, sbottom, 16, null))) { println(s.getName()); TIntObjectHashMap routes = reader.getTransportRoutes(s.getReferencesToRoutes()); - for (net.osmand.data.TransportRoute route : routes.values()) { + for (net.osmand.data.TransportRoute route : routes.valueCollection()) { println(" " + route.getRef() + " " + route.getName() + " " + route.getDistance() + " " + route.getAvgBothDistance()); } diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java index 7d020a69c7..e7e8a58510 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -18,6 +18,7 @@ import net.osmand.CollatorStringMatcher; import net.osmand.LogUtil; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; +import net.osmand.binary.OsmandOdb.OsmAndPoiNameIndex.OsmAndPoiNameIndexData; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; import net.osmand.osm.MapUtils; @@ -242,6 +243,7 @@ public class BinaryMapPoiReaderAdapter { private TIntLongHashMap readPoiNameIndex(Collator instance, String query, SearchRequest req) throws IOException { TIntLongHashMap offsets = new TIntLongHashMap(); TIntArrayList dataOffsets = null; + int offset = 0; while(true){ int t = codedIS.readTag(); int tag = WireFormat.getTagFieldNumber(t); @@ -252,13 +254,13 @@ public class BinaryMapPoiReaderAdapter { int length = readInt(); int oldLimit = codedIS.pushLimit(length); dataOffsets = new TIntArrayList(); + offset = codedIS.getTotalBytesRead(); map.readIndexedStringTable(instance, query, "", dataOffsets, 0); codedIS.popLimit(oldLimit); break; } case OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER : { if(dataOffsets != null){ - dataOffsets.sort(); - int offset = codedIS.getTotalBytesRead(); + dataOffsets.sort(); // 1104125 for (int i = 0; i < dataOffsets.size(); i++) { codedIS.seek(dataOffsets.get(i) + offset); int len = codedIS.readRawVarint32(); @@ -288,7 +290,7 @@ public class BinaryMapPoiReaderAdapter { switch (tag) { case 0: return; - case OsmandOdb.OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER : + case OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER : int len = codedIS.readRawVarint32(); int oldLim = codedIS.pushLimit(len); readPoiNameIndexDataAtom(offsets, req); @@ -366,10 +368,8 @@ public class BinaryMapPoiReaderAdapter { if(skipTiles != null){ skipTiles.clear(); } - LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) + "ms. Found " + offsets.length +" subtress"); - for (int j = 0; j < offsets.length; j++) { codedIS.seek(offsets[j] + indexOffset); int len = readInt(); diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/BinaryMapIndexWriter.java b/DataExtractionOSM/src/net/osmand/data/preparation/BinaryMapIndexWriter.java index f1519d83f9..e7e7684601 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/BinaryMapIndexWriter.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/BinaryMapIndexWriter.java @@ -827,11 +827,12 @@ public class BinaryMapIndexWriter { codedOutStream.writeMessage(OsmAndTransportIndex.STRINGTABLE_FIELD_NUMBER, st.build()); } - public BinaryFileReference startWritePOIIndex(String name, int left31, int right31, int bottom31, int top31) throws IOException { + public long startWritePOIIndex(String name, int left31, int right31, int bottom31, int top31) throws IOException { pushState(POI_INDEX_INIT, OSMAND_STRUCTURE_INIT); codedOutStream.writeTag(OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); stackBounds.push(new Bounds(0, 0, 0, 0)); // for poi index tree - BinaryFileReference startPoiIndex = preserveInt32Size(); + preserveInt32Size(); + long startPointer = getFilePointer(); if (name != null) { codedOutStream.writeString(OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER, name); } @@ -841,7 +842,7 @@ public class BinaryMapIndexWriter { builder.setTop(top31); builder.setBottom(bottom31); codedOutStream.writeMessage(OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER, builder.build()); - return startPoiIndex; + return startPointer; } public void endWritePOIIndex() throws IOException { @@ -889,7 +890,7 @@ public class BinaryMapIndexWriter { codedOutStream.writeMessage(OsmandOdb.OsmAndPoiBox.CATEGORIES_FIELD_NUMBER, builder.build()); } - public Map> writePoiNameIndex(Map> namesIndex, BinaryFileReference startPoiIndex) throws IOException { + public Map> writePoiNameIndex(Map> namesIndex, long startPoiIndex) throws IOException { checkPeekState(POI_INDEX_INIT); codedOutStream.writeTag(OsmandOdb.OsmAndPoiIndex.NAMEINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); preserveInt32Size(); @@ -897,7 +898,7 @@ public class BinaryMapIndexWriter { Map> fpToWriteSeeks = new LinkedHashMap>(); Map indexedTable = writeIndexedTable(OsmandOdb.OsmAndPoiNameIndex.TABLE_FIELD_NUMBER, namesIndex.keySet()); for(Map.Entry> e : namesIndex.entrySet()) { - codedOutStream.writeTag(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); + codedOutStream.writeTag(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, FieldType.MESSAGE.getWireType()); BinaryFileReference nameTableRef = indexedTable.get(e.getKey()); codedOutStream.flush(); nameTableRef.writeReference(raf, getFilePointer()); @@ -915,7 +916,7 @@ public class BinaryMapIndexWriter { } OsmAndPoiNameIndex.OsmAndPoiNameIndexData msg = builder.build(); - codedOutStream.writeMessage(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, msg); + codedOutStream.writeMessageNoTag(msg); long endPointer = getFilePointer(); // first message @@ -925,7 +926,7 @@ public class BinaryMapIndexWriter { if (!fpToWriteSeeks.containsKey(box)) { fpToWriteSeeks.put(box, new ArrayList()); } - fpToWriteSeeks.get(box).add(net.osmand.data.preparation.BinaryFileReference.createShiftReference(endPointer - accumulateSize, startPoiIndex.getStartPointer())); + fpToWriteSeeks.get(box).add(net.osmand.data.preparation.BinaryFileReference.createShiftReference(endPointer - accumulateSize, startPoiIndex)); accumulateSize += CodedOutputStream.computeMessageSize(OsmAndPoiNameIndex.OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER, msg.getAtoms(i)); @@ -993,11 +994,12 @@ public class BinaryMapIndexWriter { public void startWritePoiData(int zoom, int x, int y, List fpPoiBox) throws IOException { pushState(POI_DATA, POI_INDEX_INIT); codedOutStream.writeTag(OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); - BinaryFileReference startPoiData = preserveInt32Size(); + long pointer = codedOutStream.getWrittenBytes(); + preserveInt32Size(); codedOutStream.flush(); // write shift to that data for (int i = 0; i < fpPoiBox.size(); i++) { - fpPoiBox.get(i).writeReference(raf, startPoiData.getStartPointer()); + fpPoiBox.get(i).writeReference(raf, pointer); } codedOutStream.writeUInt32(OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER, zoom); @@ -1011,7 +1013,7 @@ public class BinaryMapIndexWriter { writeInt32Size(); } - public BinaryFileReference startWritePoiBox(int zoom, int tileX, int tileY, BinaryFileReference startPoiIndex, boolean end) + public BinaryFileReference startWritePoiBox(int zoom, int tileX, int tileY, long startPoiIndex, boolean end) throws IOException { checkPeekState(POI_INDEX_INIT, POI_BOX); if (state.peek() == POI_INDEX_INIT) { @@ -1036,7 +1038,7 @@ public class BinaryMapIndexWriter { if (end) { codedOutStream.writeTag(OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); - BinaryFileReference shift = BinaryFileReference.createShiftReference(getFilePointer(), startPoiIndex.getStartPointer()); + BinaryFileReference shift = BinaryFileReference.createShiftReference(getFilePointer(), startPoiIndex); codedOutStream.writeFixed32NoTag(0); return shift; } diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java index e93f568583..d8146b8ca9 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java @@ -627,8 +627,8 @@ public class IndexCreator { IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$ creator.setIndexMap(false); creator.setIndexAddress(true); - creator.setIndexPOI(false); - creator.setIndexTransport(false); + creator.setIndexPOI(true); + creator.setIndexTransport(true); creator.recreateOnlyBinaryFile = false; creator.deleteDatabaseIndexes = false; diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java index 4736715a5a..f428bfeff7 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java @@ -292,7 +292,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { int left31 = minX; int bottom31 = maxY; int top31 = minY; - BinaryFileReference startFpPoiIndex = writer.startWritePOIIndex(regionName, left31, right31, bottom31, top31); + long startFpPoiIndex = writer.startWritePOIIndex(regionName, left31, right31, bottom31, top31); // 2. write categories table Map> categories = rootZoomsTree.node.categories; @@ -420,7 +420,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { } private void writePoiBoxes(BinaryMapIndexWriter writer, Tree tree, - BinaryFileReference startFpPoiIndex, Map> fpToWriteSeeks, + long startFpPoiIndex, Map> fpToWriteSeeks, Map> categories, Map catIndexes) throws IOException, SQLException { int x = tree.getNode().x; int y = tree.getNode().y; diff --git a/OsmAnd/src/net/osmand/plus/RegionAddressRepository.java b/OsmAnd/src/net/osmand/plus/RegionAddressRepository.java index 6ce865b7e9..3f2da52644 100644 --- a/OsmAnd/src/net/osmand/plus/RegionAddressRepository.java +++ b/OsmAnd/src/net/osmand/plus/RegionAddressRepository.java @@ -8,7 +8,6 @@ import net.osmand.ResultMatcher; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; -import net.osmand.data.PostCode; import net.osmand.data.Street; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; @@ -32,20 +31,20 @@ public interface RegionAddressRepository { - public void preloadCities(ResultMatcher resultMatcher); + public void preloadCities(ResultMatcher resultMatcher); public void preloadBuildings(Street street, ResultMatcher resultMatcher); - public void preloadStreets(MapObject o, ResultMatcher resultMatcher); + public void preloadStreets(City o, ResultMatcher resultMatcher); public List getLoadedCities(); - public PostCode getPostcode(String name); + public City getPostcode(String name); public City getCityById(Long id); - public Street getStreetByName(MapObject cityOrPostcode, String name); + public Street getStreetByName(City cityOrPostcode, String name); public Building getBuildingByName(Street street, String name); @@ -56,9 +55,9 @@ public interface RegionAddressRepository { public LatLon findStreetIntersection(Street street, Street street2); // TODO remove that method - public List fillWithSuggestedStreets(MapObject o, ResultMatcher resultMatcher, String... names); + public List fillWithSuggestedStreets(City o, ResultMatcher resultMatcher, String... names); - public List fillWithSuggestedCities(String name, ResultMatcher resultMatcher, LatLon currentLocation); + public List fillWithSuggestedCities(String name, ResultMatcher resultMatcher, LatLon currentLocation); diff --git a/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java index a5fe30576e..981cf603bb 100644 --- a/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/RegionAddressRepositoryBinary.java @@ -15,11 +15,11 @@ import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.LogUtil; import net.osmand.ResultMatcher; +import net.osmand.binary.BinaryMapAddressReaderAdapter; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; -import net.osmand.data.PostCode; import net.osmand.data.Street; import net.osmand.osm.LatLon; @@ -33,7 +33,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { private final LinkedHashMap cities = new LinkedHashMap(); - private final Map postCodes; + private final Map postCodes; private boolean useEnglishNames = false; private final Collator collator; @@ -42,7 +42,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { this.region = name; this.collator = Collator.getInstance(); this.collator.setStrength(Collator.PRIMARY); //ignores also case - this.postCodes = new TreeMap(collator); + this.postCodes = new TreeMap(collator); } @Override @@ -52,10 +52,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { @Override - public synchronized void preloadCities(ResultMatcher resultMatcher) { + public synchronized void preloadCities(ResultMatcher resultMatcher) { if (cities.isEmpty()) { try { - List cs = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); + List cs = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), + BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE); for (City c : cs) { cities.put(c.getId(), c); } @@ -88,18 +89,13 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { } @Override - public synchronized void preloadStreets(MapObject o, ResultMatcher resultMatcher) { - assert o instanceof PostCode || o instanceof City; - Collection streets = o instanceof PostCode ? ((PostCode) o).getStreets() : ((City) o).getStreets(); + public synchronized void preloadStreets(City o, ResultMatcher resultMatcher) { + Collection streets = o.getStreets(); if(!streets.isEmpty()){ return; } try { - if(o instanceof PostCode){ - file.preloadStreets((PostCode) o, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); - } else { - file.preloadStreets((City) o, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); - } + file.preloadStreets(o, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); } catch (IOException e) { log.error("Disk operation failed" , e); //$NON-NLS-1$ } @@ -113,19 +109,16 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { @Override - public List fillWithSuggestedStreets(MapObject o, ResultMatcher resultMatcher, String... names) { - assert o instanceof PostCode || o instanceof City; - City city = (City) (o instanceof City ? o : null); - PostCode post = (PostCode) (o instanceof PostCode ? o : null); + public List fillWithSuggestedStreets(City o, ResultMatcher resultMatcher, String... names) { List streetsToFill = new ArrayList(); if(names.length == 0){ preloadStreets(o, resultMatcher); - streetsToFill.addAll(post == null ? city.getStreets() : post.getStreets()); + streetsToFill.addAll(o.getStreets()); return streetsToFill; } preloadStreets(o, null); - Collection streets = post == null ? city.getStreets() : post.getStreets(); + Collection streets =o.getStreets(); // 1st step loading by starts with for (StringMatcherMode mode : streetsCheckMode) { @@ -148,8 +141,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { @Override - public List fillWithSuggestedCities(String name, ResultMatcher resultMatcher, LatLon currentLocation) { - List citiesToFill = new ArrayList(); + public List fillWithSuggestedCities(String name, ResultMatcher resultMatcher, LatLon currentLocation) { + List citiesToFill = new ArrayList(); if (cities.isEmpty()) { preloadCities(resultMatcher); citiesToFill.addAll(cities.values()); @@ -166,8 +159,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { if (name.length() >= 2 && Algoritms.containsDigit(name)) { // also try to identify postcodes String uName = name.toUpperCase(); - for (PostCode code : file.getPostcodes(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), - new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS))) { + for (City code : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), + new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS), + BinaryMapAddressReaderAdapter.POSTCODES_TYPE)) { citiesToFill.add(code); if (resultMatcher.isCancelled()) { return citiesToFill;