From c9491816c3ac841938487fd81bb646befead6e0d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 6 Jun 2015 01:57:56 +0200 Subject: [PATCH] Update regions --- .../src/net/osmand/map/OsmandRegions.java | 44 ++++++++++++---- .../plus/views/DownloadedRegionsLayer.java | 52 +++++++++---------- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 038f265a09..26efd2ceab 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -31,9 +31,16 @@ import net.osmand.util.MapUtils; public class OsmandRegions { + private static final String MAP_TYPE = "region_map"; +// regionSrtm = object.getMapIndex().getRule("region_srtm", null); +// regionWiki = object.getMapIndex().getRule("region_wiki", null); +// regionRoads = object.getMapIndex().getRule("region_roads", null); +// regionHillshade = object.getMapIndex().getRule("region_hillshade", null); + private BinaryMapIndexReader reader; Map> countriesByDownloadName = new HashMap>(); Map fullNamesToLocaleNames = new HashMap(); + Map fullMapNamesToDownloadNames = new HashMap(); Map downloadNamesToFullNames = new HashMap(); Map fullNamesToLowercaseIndex = new HashMap(); QuadTree quadTree = null ; @@ -46,11 +53,6 @@ public class OsmandRegions { Integer nameType = null; Integer nameLocaleType = null; String locale = "en"; - Integer regionSrtm; - Integer regionWiki; - Integer regionMap; - Integer regionRoads; - Integer regionHillshade; public void prepareFile(String fileName) throws IOException { @@ -258,6 +260,10 @@ public class OsmandRegions { this.locale = locale; } + public String getMapDownloadType(String fullname) { + return fullMapNamesToDownloadNames.get(fullname); + } + public void initLocaleNames() throws IOException { // final Collator clt = OsmAndCollator.primaryCollator(); final Map parentRelations = new LinkedHashMap(); @@ -266,6 +272,13 @@ public class OsmandRegions { @Override public boolean publish(BinaryMapDataObject object) { initTypes(object); + int[] types = object.getTypes(); + for(int i = 0; i < types.length; i++ ) { + TagValuePair tp = object.getMapIndex().decodeType(types[i]); + if("boundary".equals(tp.value)) { + return false; + } + } String parentFullName = getParentFullName(object); String fullName = getFullName(object); if(!Algorithms.isEmpty(parentFullName)) { @@ -297,10 +310,14 @@ public class OsmandRegions { String downloadName = getDownloadName(object); if(downloadName != null) { downloadNamesToFullNames.put(downloadName, fullName); + if(isDownloadOfType(object, MAP_TYPE)) { + fullMapNamesToDownloadNames.put(fullName, downloadName); + } } return false; } + @Override public boolean isCancelled() { return false; @@ -330,6 +347,17 @@ public class OsmandRegions { } } + + private boolean isDownloadOfType(BinaryMapDataObject object, String type) { + int[] addtypes = object.getAdditionalTypes(); + for(int i = 0; i < addtypes.length; i++) { + TagValuePair tp = object.getMapIndex().decodeType(addtypes[i]); + if(type.equals(tp.tag) && "yes".equals(tp.value)) { + return true; + } + } + return false; + } public void cacheAllCountries() throws IOException { @@ -402,11 +430,7 @@ public class OsmandRegions { nameLocaleType = object.getMapIndex().getRule("name:" + locale, null); parentFullName = object.getMapIndex().getRule("region_parent_name", null); fullNameType = object.getMapIndex().getRule("region_full_name", null); - regionSrtm = object.getMapIndex().getRule("region_srtm", null); - regionWiki = object.getMapIndex().getRule("region_wiki", null); - regionMap = object.getMapIndex().getRule("region_map", null); - regionRoads = object.getMapIndex().getRule("region_roads", null); - regionHillshade = object.getMapIndex().getRule("region_hillshade", null); + if (downloadNameType == null || nameType == null) { throw new IllegalStateException(); } diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index ecd37d9b31..19725d35bb 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -117,7 +117,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { currentObjects != null) { path.reset(); for (BinaryMapDataObject o : currentObjects) { - boolean downloaded = checkIfObjectDownloaded(o); + String downloadName = osmandRegions.getDownloadName(o); + boolean downloaded = checkIfObjectDownloaded(downloadName); if (!downloaded) { continue; } @@ -136,10 +137,10 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { - private boolean checkIfObjectDownloaded(BinaryMapDataObject o) { - final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) + private boolean checkIfObjectDownloaded(String downloadName) { + final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + IndexConstants.BINARY_MAP_INDEX_EXT; - final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) + "-roads" + final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + "-roads" + IndexConstants.BINARY_MAP_INDEX_EXT; return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName); } @@ -237,35 +238,34 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { btnName.append(view.getResources().getString(R.string.shared_string_download)); filter.setLength(0); Set set = new TreeSet(); - int cx = queriedBox.getCenter31X(); - int cy = queriedBox.getCenter31Y(); + int cx = view.getCurrentRotatedTileBox().getCenter31X(); + int cy = view.getCurrentRotatedTileBox().getCenter31Y(); if ((currentObjects != null && currentObjects.size() > 0)) { for (int i = 0; i < currentObjects.size(); i++) { - // TODO regions=boundary final BinaryMapDataObject o = currentObjects.get(i); if (!osmandRegions.contain(o, cx, cy)) { continue; } - if(checkIfObjectDownloaded(o)) { - return null; + String fullName = osmandRegions.getFullName(o); + String downloadName = osmandRegions.getMapDownloadType(fullName); + if (!Algorithms.isEmpty(downloadName)) { + String name = osmandRegions.getLocaleName(downloadName); // Algorithms.capitalizeFirstLetterAndLowercase(o.getName()); + if (checkIfObjectDownloaded(downloadName)) { + return null; + } + if (!set.add(name)) { + continue; + } + if (set.size() > 1) { + btnName.append(" ").append(view.getResources().getString(R.string.shared_string_or)) + .append(" "); + filter.append(", "); + } else { + btnName.append(" "); + } + filter.append(name); + btnName.append(name); } - String name = osmandRegions.getLocaleName(o); //Algorithms.capitalizeFirstLetterAndLowercase(o.getName()); - if (!set.add(name)) { - continue; - } - if (set.size() > 1) { - btnName.append(" ").append(view.getResources().getString(R.string.shared_string_or)).append(" "); - filter.append(", "); - } else { - btnName.append(" "); - } - filter.append(name); -// String parent = osmandRegions.getParentFullName(o); -// if (osmandRegions.getParentFullName(o) != null) { -// name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " -// + name; -// } - btnName.append(name); } } }