read poi categories/types from obf

This commit is contained in:
veliymolfar 2020-04-27 13:43:10 +03:00
parent 821700b59b
commit 5204a2a15a
5 changed files with 49 additions and 3 deletions

View file

@ -1307,6 +1307,12 @@ public class BinaryMapIndexReader {
poiAdapter.initCategories(poiIndex);
}
public void initCategories() throws IOException {
for (PoiRegion poiIndex : poiIndexes) {
poiAdapter.initCategories(poiIndex);
}
}
public List<Amenity> searchPoiByName(SearchRequest<Amenity> req) throws IOException {
if (req.nameQuery == null || req.nameQuery.length() == 0) {
throw new IllegalArgumentException();

View file

@ -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<String>());
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<String> 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);

View file

@ -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;
}

View file

@ -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();

View file

@ -1121,7 +1121,21 @@ public class ResourceManager {
}
return readers.toArray(new BinaryMapIndexReader[readers.size()]);
}
public BinaryMapIndexReader[] getPoiSearchFiles() {
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
List<BinaryMapIndexReader> 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<String, String> getIndexFileNames() {
return new LinkedHashMap<String, String>(indexFileNames);