commit
bab6004338
5 changed files with 93 additions and 77 deletions
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.map;
|
package net.osmand.map;
|
||||||
|
|
||||||
|
|
||||||
import net.osmand.OsmAndCollator;
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
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 point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||||
|
|
||||||
BinaryMapDataObject res = null;
|
|
||||||
List<BinaryMapDataObject> mapDataObjects;
|
List<BinaryMapDataObject> mapDataObjects;
|
||||||
try {
|
try {
|
||||||
mapDataObjects = queryBbox(point31x, point31x, point31y, point31y);
|
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 res;
|
return mapDataObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
||||||
protected BinaryMapDataObject doInBackground(LatLon... latLons) {
|
protected BinaryMapDataObject doInBackground(LatLon... latLons) {
|
||||||
try {
|
try {
|
||||||
if (latLons != null && latLons.length > 0) {
|
if (latLons != null && latLons.length > 0) {
|
||||||
return app.getRegions().findBinaryMapDataObject(latLons[0]);
|
return app.getRegions().getSmallestBinaryMapDataObjectAt(latLons[0]);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
|
@ -5,15 +5,12 @@ import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.binary.BinaryMapDataObject;
|
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.map.OsmandRegions;
|
import net.osmand.map.OsmandRegions;
|
||||||
import net.osmand.map.WorldRegion;
|
import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
|
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
|
||||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||||
import net.osmand.util.MapUtils;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -23,13 +20,14 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DownloadResources extends DownloadResourceGroup {
|
public class DownloadResources extends DownloadResourceGroup {
|
||||||
|
private static final String TAG = DownloadResources.class.getSimpleName();
|
||||||
|
|
||||||
public boolean isDownloadedFromInternet = false;
|
public boolean isDownloadedFromInternet = false;
|
||||||
public boolean downloadFromInternetFailed = false;
|
public boolean downloadFromInternetFailed = false;
|
||||||
public boolean mapVersionIsIncreased = false;
|
public boolean mapVersionIsIncreased = false;
|
||||||
|
@ -460,40 +458,13 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) throws IOException {
|
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) throws IOException {
|
||||||
|
|
||||||
List<IndexItem> res = new ArrayList<>();
|
List<IndexItem> res = new ArrayList<>();
|
||||||
OsmandRegions regions = app.getRegions();
|
OsmandRegions regions = app.getRegions();
|
||||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||||
|
List<WorldRegion> downloadRegions = regions.getWoldRegionsAt(latLon);
|
||||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
for (WorldRegion downloadRegion : downloadRegions) {
|
||||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
||||||
|
addIndexItem(downloadThread, type, downloadRegion, res);
|
||||||
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)) {
|
|
||||||
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
|
||||||
addIndexItem(downloadThread, type, downloadRegion, res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -408,7 +408,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
|
||||||
Amenity amenity = cityItem.getAmenity();
|
Amenity amenity = cityItem.getAmenity();
|
||||||
BinaryMapDataObject o = null;
|
BinaryMapDataObject o = null;
|
||||||
try {
|
try {
|
||||||
o = osmandRegions.findBinaryMapDataObject(amenity.getLocation());
|
o = osmandRegions.getSmallestBinaryMapDataObjectAt(amenity.getLocation());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.map.OsmandRegions;
|
import net.osmand.map.OsmandRegions;
|
||||||
|
import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
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.download.IndexItem;
|
||||||
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
||||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -91,39 +93,64 @@ public class WikiArticleHelper {
|
||||||
protected List<Amenity> doInBackground(Void... voids) {
|
protected List<Amenity> doInBackground(Void... voids) {
|
||||||
MapActivity activity = weakMapActivity.get();
|
MapActivity activity = weakMapActivity.get();
|
||||||
OsmandApplication application = activity.getMyApplication();
|
OsmandApplication application = activity.getMyApplication();
|
||||||
List<Amenity> results = new ArrayList<>();
|
final List<Amenity> results = new ArrayList<>();
|
||||||
if (application != null && !isCancelled()) {
|
if (application != null && !isCancelled()) {
|
||||||
IndexItem item = null;
|
List<WorldRegion> regions = null;
|
||||||
try {
|
if (articleLatLon != null) {
|
||||||
if (articleLatLon != null) {
|
try {
|
||||||
item = DownloadResources.findSmallestIndexItemAt(application,
|
regions = application.getRegions().getWoldRegionsAt(articleLatLon);
|
||||||
articleLatLon, DownloadActivityType.WIKIPEDIA_FILE);
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, e.getMessage(), e);
|
|
||||||
}
|
|
||||||
String filename = null;
|
|
||||||
if (item != null && item.isDownloaded()) {
|
|
||||||
filename = getFilenameFromIndex(item.getFileName());
|
|
||||||
}
|
|
||||||
AmenityIndexRepositoryBinary repository = application.getResourceManager()
|
|
||||||
.getAmenityRepositoryByFileName(filename == null ? "" : filename);
|
|
||||||
if (repository == null) {
|
|
||||||
if ((regionName == null || regionName.isEmpty()) && item != null) {
|
|
||||||
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} else {
|
} else {
|
||||||
if (isCancelled()) {
|
return null;
|
||||||
return null;
|
}
|
||||||
|
if (regions != null) {
|
||||||
|
AmenityIndexRepositoryBinary repository = getWikiRepositoryByRegions(regions, application);
|
||||||
|
if (repository == null) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
results.addAll(repository.searchAmenitiesByName(0, 0, 0, 0,
|
||||||
|
Integer.MAX_VALUE, Integer.MAX_VALUE, name, null));
|
||||||
}
|
}
|
||||||
results.addAll(repository.searchAmenitiesByName(0, 0, 0, 0,
|
|
||||||
Integer.MAX_VALUE, Integer.MAX_VALUE, name, null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
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
|
@Override
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
MapActivity activity = weakMapActivity.get();
|
MapActivity activity = weakMapActivity.get();
|
||||||
|
|
Loading…
Reference in a new issue