Fix #3186
This commit is contained in:
parent
8903864e97
commit
ed1a8104b7
3 changed files with 58 additions and 14 deletions
|
@ -30,6 +30,7 @@ import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapAlgorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
@ -238,6 +239,20 @@ public class OsmandRegions {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static double getArea(BinaryMapDataObject bo) {
|
||||
double area = 0.0;
|
||||
if (bo.getPointsLength() > 0) {
|
||||
for (int i = 1; i < bo.getPointsLength(); i++) {
|
||||
double ax = bo.getPoint31XTile(i - 1);
|
||||
double bx = bo.getPoint31XTile(i);
|
||||
double ay = bo.getPoint31YTile(i - 1);
|
||||
double by = bo.getPoint31YTile(i);
|
||||
area += (bx + ax) * (by - ay) / 1.631E10;
|
||||
}
|
||||
}
|
||||
return Math.abs(area);
|
||||
}
|
||||
|
||||
private List<BinaryMapDataObject> getCountries(int tile31x, int tile31y) {
|
||||
HashSet<String> set = new HashSet<String>(quadTree.queryInBox(new QuadRect(tile31x, tile31y, tile31x, tile31y),
|
||||
new ArrayList<String>()));
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package net.osmand.plus.mapcontextmenu;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.NativeLibrary;
|
||||
import net.osmand.NativeLibrary.RenderedObject;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
|
@ -60,11 +62,11 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll
|
|||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MenuController extends BaseMenuController {
|
||||
|
||||
|
@ -520,11 +522,22 @@ public abstract class MenuController extends BaseMenuController {
|
|||
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
|
||||
while (it.hasNext()) {
|
||||
BinaryMapDataObject o = it.next();
|
||||
if (!osmandRegions.contain(o, point31x, point31y)) {
|
||||
if (o.getTypes() != null) {
|
||||
boolean isRegion = true;
|
||||
for (int i = 0; i < o.getTypes().length; i++) {
|
||||
TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
|
||||
if ("boundary".equals(tp.value)) {
|
||||
isRegion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
String selectedFullName = "";
|
||||
double smallestArea = -1;
|
||||
for (BinaryMapDataObject o : mapDataObjects) {
|
||||
boolean downloaded = checkIfObjectDownloaded(rm, osmandRegions.getDownloadName(o));
|
||||
if (downloaded) {
|
||||
|
@ -532,7 +545,13 @@ public abstract class MenuController extends BaseMenuController {
|
|||
break;
|
||||
} else {
|
||||
String fullName = osmandRegions.getFullName(o);
|
||||
if (fullName.length() > selectedFullName.length()) {
|
||||
double area = OsmandRegions.getArea(o);
|
||||
if (smallestArea == -1) {
|
||||
smallestArea = area;
|
||||
selectedFullName = fullName;
|
||||
downloadMapDataObject = o;
|
||||
} else if (area < smallestArea) {
|
||||
smallestArea = area;
|
||||
selectedFullName = fullName;
|
||||
downloadMapDataObject = o;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import android.util.DisplayMetrics;
|
|||
import android.view.WindowManager;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
|
@ -468,7 +470,15 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
|||
Iterator<BinaryMapDataObject> it = result.iterator();
|
||||
while (it.hasNext()) {
|
||||
BinaryMapDataObject o = it.next();
|
||||
if (!osmandRegions.contain(o, point31x, point31y) ) {
|
||||
boolean isRegion = true;
|
||||
for (int i = 0; i < o.getTypes().length; i++) {
|
||||
TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
|
||||
if ("boundary".equals(tp.value)) {
|
||||
isRegion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isRegion || !osmandRegions.contain(o, point31x, point31y) ) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue