diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java index 9fc3a2b9dd..ce83e15956 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java @@ -1307,6 +1307,12 @@ public class BinaryMapIndexReader { poiAdapter.initCategories(poiIndex); } + public void initCategories() throws IOException { + for (PoiRegion poiIndex : poiIndexes) { + poiAdapter.initCategories(poiIndex); + } + } + public List searchPoiByName(SearchRequest req) throws IOException { if (req.nameQuery == null || req.nameQuery.length() == 0) { throw new IllegalArgumentException(); diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index 81a4212d4d..a004d013dc 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -26,6 +26,7 @@ import net.osmand.data.Amenity.AmenityRoutePoint; import net.osmand.data.LatLon; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -224,11 +225,21 @@ public class BinaryMapPoiReaderAdapter { case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER: String cat = codedIS.readString().intern(); region.categories.add(cat); - region.categoriesType.add(poiTypes.getPoiCategoryByName(cat.toLowerCase())); + region.categoriesType.add(poiTypes.getPoiCategoryByName(cat.toLowerCase(), true)); region.subcategories.add(new ArrayList()); break; case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER: - region.subcategories.get(region.subcategories.size() - 1).add(codedIS.readString().intern()); + String subCat = codedIS.readString().intern(); + PoiCategory lastCat = poiTypes.getPoiCategoryByName(region.categories.get(region.categories.size() - 1)); + PoiType poiType = new PoiType(MapPoiTypes.getDefault(), lastCat, null, subCat); + List filters = new ArrayList<>(); + for (PoiType poi : lastCat.getPoiTypes()) { + filters.add(poi.getKeyName()); + } + if (!filters.contains(subCat)) { + lastCat.getPoiTypes().add(poiType); + } + region.subcategories.get(region.subcategories.size() - 1).add(subCat); break; default: skipUnknownField(t); diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 0edd44aa6e..6635c77936 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -295,6 +295,9 @@ public class MapPoiTypes { } if (create) { PoiCategory lastCategory = new PoiCategory(this, name, categories.size()); + if (!lastCategory.getKeyName().equals("Other")) { + lastCategory.setTopVisible(true); + } categories.add(lastCategory); return lastCategory; } diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 457052796b..6159afb6f5 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -21,6 +21,7 @@ import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi; +import net.osmand.binary.BinaryMapIndexReader; import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions.RegionTranslation; import net.osmand.map.WorldRegion; @@ -481,6 +482,16 @@ public class AppInitializer implements IProgress { }); } + private void readPoiTypesFromMap() { + final BinaryMapIndexReader[] currentFile = app.resourceManager.getPoiSearchFiles(); + for (BinaryMapIndexReader r : currentFile) { + try { + r.initCategories(); + } catch (IOException e) { + LOG.error("Error while read poi types from map " + e); + } + } + } public void onCreateApplication() { // always update application mode to default @@ -730,6 +741,7 @@ public class AppInitializer implements IProgress { initPoiTypes(); notifyEvent(InitEvents.POI_TYPES_INITIALIZED); app.resourceManager.reloadIndexesOnStart(this, warnings); + readPoiTypesFromMap(); // native depends on renderers initNativeCore(); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 8000ea0fca..1a4be8a631 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -1121,7 +1121,21 @@ public class ResourceManager { } return readers.toArray(new BinaryMapIndexReader[readers.size()]); } - + + public BinaryMapIndexReader[] getPoiSearchFiles() { + Collection fileReaders = getFileReaders(); + List readers = new ArrayList<>(fileReaders.size()); + for (BinaryMapReaderResource r : fileReaders) { + BinaryMapIndexReader shallowReader = r.getShallowReader(); + if (shallowReader != null && shallowReader.containsPoiData()) { + BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.POI); + if (reader != null) { + readers.add(reader); + } + } + } + return readers.toArray(new BinaryMapIndexReader[readers.size()]); + } public Map getIndexFileNames() { return new LinkedHashMap(indexFileNames);