travel obf helper updated

This commit is contained in:
simon 2020-12-15 16:54:14 +02:00
parent 2b439a4c80
commit 89ad77ba02
2 changed files with 30 additions and 59 deletions

View file

@ -19,10 +19,8 @@ import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryIndexPart;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
import net.osmand.binary.BinaryMapPoiReaderAdapter;
import net.osmand.binary.CachedOsmandIndexes; import net.osmand.binary.CachedOsmandIndexes;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
@ -78,6 +76,7 @@ import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT;
import static net.osmand.IndexConstants.VOICE_INDEX_DIR; import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
/** /**
@ -636,6 +635,7 @@ public class ResourceManager {
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files); collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
if (Version.isPaidVersion(context)) { if (Version.isPaidVersion(context)) {
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
} }
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) { if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
@ -728,7 +728,10 @@ public class ResourceManager {
} }
renderer.initializeNewResource(progress, f, mapReader); renderer.initializeNewResource(progress, f, mapReader);
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader); BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
if (collectTravelFiles(resource)){
//travel files are indexed
continue;
}
fileReaders.put(f.getName(), resource); fileReaders.put(f.getName(), resource);
if (!mapReader.getRegionNames().isEmpty()) { if (!mapReader.getRegionNames().isEmpty()) {
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource); RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource);
@ -737,7 +740,6 @@ public class ResourceManager {
if (mapReader.hasTransportData()) { if (mapReader.hasTransportData()) {
transportRepositories.put(f.getName(), resource); transportRepositories.put(f.getName(), resource);
} }
collectTravelFiles(mapReader, resource);
// disable osmc for routing temporarily due to some bugs // disable osmc for routing temporarily due to some bugs
if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) || if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) ||
context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) { context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) {
@ -814,10 +816,30 @@ public class ResourceManager {
return res; return res;
} }
private void collectTravelFiles(BinaryMapReaderResource resource) { private List<BinaryMapIndexReader> getTravelRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
for (BinaryMapIndexReader index : getTravelRepositories()){ List<String> fileNames = new ArrayList<>(transportRepositories.keySet());
travelRepositories.put(index.getFile().getName(), resource); Collections.sort(fileNames, Algorithms.getStringVersionComparator());
List<BinaryMapIndexReader> res = new ArrayList<>();
for (String fileName : fileNames) {
int topx31 = MapUtils.get31TileNumberX(topLat);
int leftx31 = MapUtils.get31TileNumberY(leftLon);
int bottomx31 = MapUtils.get31TileNumberX(bottomLat);
int rightx31 = MapUtils.get31TileNumberY(rightLon);
BinaryMapReaderResource r = transportRepositories.get(fileName);
if (r != null &&
r.getShallowReader().containsPoiData(topx31, leftx31, bottomx31, rightx31)) {
res.add(r.getReader(BinaryMapReaderResourceType.TRANSPORT));
}
} }
return res;
}
private boolean collectTravelFiles(BinaryMapReaderResource resource) {
if (resource.getFileName().contains(BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)){
travelRepositories.put(resource.getFileName(), resource);
return true;
}
return false;
} }
public void initMapBoundariesCacheNative() { public void initMapBoundariesCacheNative() {

View file

@ -29,14 +29,11 @@ public class TravelObfHelper implements TravelHelper {
private static final Log LOG = PlatformUtil.getLog(TravelObfHelper.class); private static final Log LOG = PlatformUtil.getLog(TravelObfHelper.class);
private static final int POPULAR_LIMIT = 25;
private final OsmandApplication application; private final OsmandApplication application;
private TravelLocalDataHelper localDataHelper; private TravelLocalDataHelper localDataHelper;
private List<BinaryMapIndexReader> files;
private List<File> existingTravelBooks = new ArrayList<>();
private List<TravelArticle> popularArticles = new ArrayList<TravelArticle>(); private List<TravelArticle> popularArticles = new ArrayList<TravelArticle>();
@ -68,31 +65,7 @@ public class TravelObfHelper implements TravelHelper {
@NonNull @NonNull
public List<WikivoyageSearchResult> search(final String searchQuery) { public List<WikivoyageSearchResult> search(final String searchQuery) {
// TODO remove
//this.files = application.getResourceManager().getTravelFiles();
List<WikivoyageSearchResult> res = new ArrayList<>(); List<WikivoyageSearchResult> res = new ArrayList<>();
// List<Amenity> searchObjects = new ArrayList<>();
// for (BinaryMapIndexReader reader : files) {
// try {
// BinaryMapIndexReader.SearchRequest<Amenity> searchRequest = BinaryMapIndexReader.
// buildSearchPoiRequest(0, 0, searchQuery,
// 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, null);
//
// searchObjects = reader.searchPoiByName(searchRequest);
// } catch (IOException e) {
// LOG.error(e);
// }
// }
// for (MapObject obj : searchObjects) {
// //TODO map
// WikivoyageSearchResult r = new WikivoyageSearchResult();
// r.articleTitles = Collections.singletonList(obj.getName());
// r.langs = Collections.singletonList(obj.getName());
// r.imageTitle = (obj.getName());
// r.isPartOf = Collections.singletonList(obj.getName());
// r.routeId = "routeid";//obj.getId();
// res.add(r);
// }
return res; return res;
} }
@ -132,14 +105,6 @@ public class TravelObfHelper implements TravelHelper {
return popularArticles; return popularArticles;
} }
public String formatTravelBookName(File tb) {
if (tb == null) {
return application.getString(R.string.shared_string_none);
}
String nm = tb.getName();
return nm.substring(0, nm.indexOf('.')).replace('_', ' ');
}
public String getGPXName(TravelArticle article) { public String getGPXName(TravelArticle article) {
return article.getTitle().replace('/', '_').replace('\'', '_') return article.getTitle().replace('/', '_').replace('\'', '_')
.replace('\"', '_') + IndexConstants.GPX_FILE_EXT; .replace('\"', '_') + IndexConstants.GPX_FILE_EXT;
@ -156,8 +121,7 @@ public class TravelObfHelper implements TravelHelper {
@Override @Override
public String getSelectedTravelBookName() { public String getSelectedTravelBookName() {
//TODO REPLACE return null;
return "OBF TRAVEL BOOK";
} }
public static boolean checkIfObfFileExists(OsmandApplication app) { public static boolean checkIfObfFileExists(OsmandApplication app) {
@ -171,19 +135,4 @@ public class TravelObfHelper implements TravelHelper {
} }
return false; return false;
} }
// might use in future
protected static class PopularArticle {
String tripId;
String title;
String lang;
int popIndex;
int order;
double lat;
double lon;
public boolean isLocationSpecified() {
return !Double.isNaN(lat) && !Double.isNaN(lon);
}
}
} }