From 89ad77ba0248bbe57bd188879f13bd53f5b580c7 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 15 Dec 2020 16:54:14 +0200 Subject: [PATCH] travel obf helper updated --- .../plus/resources/ResourceManager.java | 36 ++++++++++--- .../plus/wikivoyage/data/TravelObfHelper.java | 53 +------------------ 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 85fc4b43df..8f8c93a3d8 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -19,10 +19,8 @@ import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; -import net.osmand.binary.BinaryIndexPart; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; -import net.osmand.binary.BinaryMapPoiReaderAdapter; import net.osmand.binary.CachedOsmandIndexes; import net.osmand.data.Amenity; import net.osmand.data.RotatedTileBox; @@ -78,6 +76,7 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; +import static net.osmand.IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT; import static net.osmand.IndexConstants.VOICE_INDEX_DIR; /** @@ -636,6 +635,7 @@ public class ResourceManager { collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files); if (Version.isPaidVersion(context)) { 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)) { 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); BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader); - + if (collectTravelFiles(resource)){ + //travel files are indexed + continue; + } fileReaders.put(f.getName(), resource); if (!mapReader.getRegionNames().isEmpty()) { RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource); @@ -737,7 +740,6 @@ public class ResourceManager { if (mapReader.hasTransportData()) { transportRepositories.put(f.getName(), resource); } - collectTravelFiles(mapReader, resource); // disable osmc for routing temporarily due to some bugs if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) || context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) { @@ -814,10 +816,30 @@ public class ResourceManager { return res; } - private void collectTravelFiles(BinaryMapReaderResource resource) { - for (BinaryMapIndexReader index : getTravelRepositories()){ - travelRepositories.put(index.getFile().getName(), resource); + private List getTravelRepositories(double topLat, double leftLon, double bottomLat, double rightLon) { + List fileNames = new ArrayList<>(transportRepositories.keySet()); + Collections.sort(fileNames, Algorithms.getStringVersionComparator()); + List 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() { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index b162fa8698..df54776ab8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -29,14 +29,11 @@ public class TravelObfHelper implements TravelHelper { private static final Log LOG = PlatformUtil.getLog(TravelObfHelper.class); - private static final int POPULAR_LIMIT = 25; private final OsmandApplication application; private TravelLocalDataHelper localDataHelper; - private List files; - private List existingTravelBooks = new ArrayList<>(); private List popularArticles = new ArrayList(); @@ -68,31 +65,7 @@ public class TravelObfHelper implements TravelHelper { @NonNull public List search(final String searchQuery) { - // TODO remove - //this.files = application.getResourceManager().getTravelFiles(); List res = new ArrayList<>(); -// List searchObjects = new ArrayList<>(); -// for (BinaryMapIndexReader reader : files) { -// try { -// BinaryMapIndexReader.SearchRequest 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; } @@ -132,14 +105,6 @@ public class TravelObfHelper implements TravelHelper { 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) { return article.getTitle().replace('/', '_').replace('\'', '_') .replace('\"', '_') + IndexConstants.GPX_FILE_EXT; @@ -156,8 +121,7 @@ public class TravelObfHelper implements TravelHelper { @Override public String getSelectedTravelBookName() { - //TODO REPLACE - return "OBF TRAVEL BOOK"; + return null; } public static boolean checkIfObfFileExists(OsmandApplication app) { @@ -171,19 +135,4 @@ public class TravelObfHelper implements TravelHelper { } 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); - } - } }