commit
bab6004338
5 changed files with 93 additions and 77 deletions
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.map;
|
||||
|
||||
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -695,11 +694,42 @@ public class OsmandRegions {
|
|||
}
|
||||
}
|
||||
|
||||
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
|
||||
public List<WorldRegion> getWoldRegionsAt(LatLon latLon) throws IOException {
|
||||
List<WorldRegion> result = new ArrayList<>();
|
||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjectsAt(latLon);
|
||||
for (BinaryMapDataObject obj : mapDataObjects) {
|
||||
String fullName = getFullName(obj);
|
||||
if (fullName != null) {
|
||||
WorldRegion reg = getRegionData(fullName);
|
||||
if (reg != null) {
|
||||
result.add(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public BinaryMapDataObject getSmallestBinaryMapDataObjectAt(LatLon latLon) throws IOException {
|
||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjectsAt(latLon);
|
||||
BinaryMapDataObject res = null;
|
||||
double smallestArea = -1;
|
||||
for (BinaryMapDataObject o : mapDataObjects) {
|
||||
double area = OsmandRegions.getArea(o);
|
||||
if (smallestArea == -1) {
|
||||
smallestArea = area;
|
||||
res = o;
|
||||
} else if (area < smallestArea) {
|
||||
smallestArea = area;
|
||||
res = o;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<BinaryMapDataObject> getBinaryMapDataObjectsAt(LatLon latLon) throws IOException {
|
||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||
|
||||
BinaryMapDataObject res = null;
|
||||
List<BinaryMapDataObject> mapDataObjects;
|
||||
try {
|
||||
mapDataObjects = queryBbox(point31x, point31x, point31y, point31y);
|
||||
|
@ -729,19 +759,7 @@ public class OsmandRegions {
|
|||
}
|
||||
}
|
||||
}
|
||||
double smallestArea = -1;
|
||||
for (BinaryMapDataObject o : mapDataObjects) {
|
||||
double area = OsmandRegions.getArea(o);
|
||||
if (smallestArea == -1) {
|
||||
smallestArea = area;
|
||||
res = o;
|
||||
} else if (area < smallestArea) {
|
||||
smallestArea = area;
|
||||
res = o;
|
||||
}
|
||||
return mapDataObjects;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
protected BinaryMapDataObject doInBackground(LatLon... latLons) {
|
||||
try {
|
||||
if (latLons != null && latLons.length > 0) {
|
||||
return app.getRegions().findBinaryMapDataObject(latLons[0]);
|
||||
return app.getRegions().getSmallestBinaryMapDataObjectAt(latLons[0]);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
|
|
|
@ -5,15 +5,12 @@ import android.support.annotation.Nullable;
|
|||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -23,13 +20,14 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DownloadResources extends DownloadResourceGroup {
|
||||
private static final String TAG = DownloadResources.class.getSimpleName();
|
||||
|
||||
public boolean isDownloadedFromInternet = false;
|
||||
public boolean downloadFromInternetFailed = false;
|
||||
public boolean mapVersionIsIncreased = false;
|
||||
|
@ -460,42 +458,15 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
}
|
||||
|
||||
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) throws IOException {
|
||||
|
||||
List<IndexItem> res = new ArrayList<>();
|
||||
OsmandRegions regions = app.getRegions();
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
|
||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||
|
||||
List<BinaryMapDataObject> mapDataObjects;
|
||||
try {
|
||||
mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Error while calling queryBbox");
|
||||
}
|
||||
if (mapDataObjects != null) {
|
||||
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
|
||||
while (it.hasNext()) {
|
||||
BinaryMapDataObject o = it.next();
|
||||
if (o.getTypes() != null) {
|
||||
boolean isRegion = true;
|
||||
for (int i = 0; i < o.getTypes().length; i++) {
|
||||
BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
|
||||
if ("boundary".equals(tp.value)) {
|
||||
isRegion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o));
|
||||
if (downloadRegion != null && isRegion && regions.contain(o, point31x, point31y)) {
|
||||
List<WorldRegion> downloadRegions = regions.getWoldRegionsAt(latLon);
|
||||
for (WorldRegion downloadRegion : downloadRegions) {
|
||||
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
||||
addIndexItem(downloadThread, type, downloadRegion, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -408,7 +408,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
|
|||
Amenity amenity = cityItem.getAmenity();
|
||||
BinaryMapDataObject o = null;
|
||||
try {
|
||||
o = osmandRegions.findBinaryMapDataObject(amenity.getLocation());
|
||||
o = osmandRegions.getSmallestBinaryMapDataObjectAt(amenity.getLocation());
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -23,6 +24,7 @@ import net.osmand.plus.download.DownloadResources;
|
|||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -91,28 +93,35 @@ public class WikiArticleHelper {
|
|||
protected List<Amenity> doInBackground(Void... voids) {
|
||||
MapActivity activity = weakMapActivity.get();
|
||||
OsmandApplication application = activity.getMyApplication();
|
||||
List<Amenity> results = new ArrayList<>();
|
||||
final List<Amenity> results = new ArrayList<>();
|
||||
if (application != null && !isCancelled()) {
|
||||
IndexItem item = null;
|
||||
try {
|
||||
List<WorldRegion> regions = null;
|
||||
if (articleLatLon != null) {
|
||||
item = DownloadResources.findSmallestIndexItemAt(application,
|
||||
articleLatLon, DownloadActivityType.WIKIPEDIA_FILE);
|
||||
}
|
||||
try {
|
||||
regions = application.getRegions().getWoldRegionsAt(articleLatLon);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
String filename = null;
|
||||
if (item != null && item.isDownloaded()) {
|
||||
filename = getFilenameFromIndex(item.getFileName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
AmenityIndexRepositoryBinary repository = application.getResourceManager()
|
||||
.getAmenityRepositoryByFileName(filename == null ? "" : filename);
|
||||
if (regions != null) {
|
||||
AmenityIndexRepositoryBinary repository = getWikiRepositoryByRegions(regions, application);
|
||||
if (repository == null) {
|
||||
if ((regionName == null || regionName.isEmpty()) && item != null) {
|
||||
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
||||
if (regionName == null || regionName.isEmpty()) {
|
||||
IndexItem item = null;
|
||||
try {
|
||||
item = DownloadResources.findSmallestIndexItemAt(application, articleLatLon,
|
||||
DownloadActivityType.WIKIPEDIA_FILE);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
if (item != null) {
|
||||
regionName = getRegionName(item.getFileName(), application.getRegions());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (isCancelled()) {
|
||||
return null;
|
||||
|
@ -121,9 +130,27 @@ public class WikiArticleHelper {
|
|||
Integer.MAX_VALUE, Integer.MAX_VALUE, name, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private AmenityIndexRepositoryBinary getWikiRepositoryByRegions(@NonNull List<WorldRegion> regions, @NonNull OsmandApplication app) {
|
||||
AmenityIndexRepositoryBinary repo = null;
|
||||
for (WorldRegion reg : regions) {
|
||||
if (reg != null) {
|
||||
if (repo != null) {
|
||||
break;
|
||||
}
|
||||
repo = app.getResourceManager()
|
||||
.getAmenityRepositoryByFileName(Algorithms
|
||||
.capitalizeFirstLetterAndLowercase(reg.getRegionDownloadName()) +
|
||||
IndexConstants.BINARY_WIKI_MAP_INDEX_EXT);
|
||||
}
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
MapActivity activity = weakMapActivity.get();
|
||||
|
|
Loading…
Reference in a new issue