Fix #11023 (draft)
This commit is contained in:
parent
d230a323ce
commit
6affa0c432
2 changed files with 42 additions and 8 deletions
|
@ -436,7 +436,7 @@ public class OsmandRegions {
|
||||||
cx /= object.getPointsLength();
|
cx /= object.getPointsLength();
|
||||||
cy /= object.getPointsLength();
|
cy /= object.getPointsLength();
|
||||||
rd.regionCenter = new LatLon(MapUtils.get31LatitudeY((int) cy), MapUtils.get31LongitudeX((int) cx));
|
rd.regionCenter = new LatLon(MapUtils.get31LatitudeY((int) cy), MapUtils.get31LongitudeX((int) cx));
|
||||||
rd.boundingBox = findBoundingBox(object);
|
findBoundaries(rd, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object);
|
rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object);
|
||||||
|
@ -462,13 +462,15 @@ public class OsmandRegions {
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private QuadRect findBoundingBox(BinaryMapDataObject object) {
|
private void findBoundaries(WorldRegion rd, BinaryMapDataObject object) {
|
||||||
if (object.getPointsLength() == 0) {
|
if (object.getPointsLength() == 0) {
|
||||||
return new QuadRect(0, 0, 0, 0);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<LatLon> polygon = new ArrayList<>();
|
||||||
double currentX = object.getPoint31XTile(0);
|
double currentX = object.getPoint31XTile(0);
|
||||||
double currentY = object.getPoint31YTile(0);
|
double currentY = object.getPoint31YTile(0);
|
||||||
|
polygon.add(new LatLon(currentX, currentY));
|
||||||
double minX = currentX;
|
double minX = currentX;
|
||||||
double maxX = currentX;
|
double maxX = currentX;
|
||||||
double minY = currentY;
|
double minY = currentY;
|
||||||
|
@ -476,8 +478,10 @@ public class OsmandRegions {
|
||||||
|
|
||||||
if (object.getPointsLength() > 1) {
|
if (object.getPointsLength() > 1) {
|
||||||
for (int i = 1; i < object.getPointsLength(); i++) {
|
for (int i = 1; i < object.getPointsLength(); i++) {
|
||||||
currentX = object.getPoint31XTile(i);
|
int tileX = object.getPoint31XTile(i);
|
||||||
currentY = object.getPoint31YTile(i);
|
int tileY = object.getPoint31YTile(i);
|
||||||
|
currentX = tileX;
|
||||||
|
currentY = tileY;
|
||||||
if (currentX > maxX) {
|
if (currentX > maxX) {
|
||||||
maxX = currentX;
|
maxX = currentX;
|
||||||
} else if (currentX < minX) {
|
} else if (currentX < minX) {
|
||||||
|
@ -488,6 +492,7 @@ public class OsmandRegions {
|
||||||
} else if (currentY < minY) {
|
} else if (currentY < minY) {
|
||||||
minY = currentY;
|
minY = currentY;
|
||||||
}
|
}
|
||||||
|
polygon.add(new LatLon(currentX, currentY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +501,8 @@ public class OsmandRegions {
|
||||||
double revertedMinY = MapUtils.get31LatitudeY((int) maxY);
|
double revertedMinY = MapUtils.get31LatitudeY((int) maxY);
|
||||||
double revertedMaxY = MapUtils.get31LatitudeY((int) minY);
|
double revertedMaxY = MapUtils.get31LatitudeY((int) minY);
|
||||||
|
|
||||||
return new QuadRect(minX, revertedMinY, maxX, revertedMaxY);
|
rd.boundingBox = new QuadRect(minX, revertedMinY, maxX, revertedMaxY);
|
||||||
|
rd.polygon = polygon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSearchIndex(BinaryMapDataObject object) {
|
private String getSearchIndex(BinaryMapDataObject object) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class WorldRegion implements Serializable {
|
||||||
protected boolean regionMapDownload;
|
protected boolean regionMapDownload;
|
||||||
protected LatLon regionCenter;
|
protected LatLon regionCenter;
|
||||||
protected QuadRect boundingBox;
|
protected QuadRect boundingBox;
|
||||||
|
protected List<LatLon> polygon;
|
||||||
|
|
||||||
public static class RegionParams {
|
public static class RegionParams {
|
||||||
protected String regionLeftHandDriving;
|
protected String regionLeftHandDriving;
|
||||||
|
@ -186,12 +187,39 @@ public class WorldRegion implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsRegion(WorldRegion region) {
|
public boolean containsRegion(WorldRegion region) {
|
||||||
if (this.boundingBox != null && region.boundingBox != null) {
|
boolean isBoundingAvailable = this.boundingBox != null && region.boundingBox != null;
|
||||||
return this.boundingBox.contains(region.boundingBox);
|
boolean isPolygonsAvailable = this.polygon != null && region.polygon != null;
|
||||||
|
|
||||||
|
boolean containsBox = false;
|
||||||
|
if (isBoundingAvailable) {
|
||||||
|
containsBox = this.boundingBox.contains(region.boundingBox);
|
||||||
|
}
|
||||||
|
if (containsBox && isPolygonsAvailable) {
|
||||||
|
boolean allPointsInsideThePolygon = true;
|
||||||
|
List<LatLon> regionPolygon = region.polygon;
|
||||||
|
for (int i = 0; i < regionPolygon.size(); i++) {
|
||||||
|
allPointsInsideThePolygon = isPointInsideThePolygon(regionPolygon.get(i));
|
||||||
|
if (!allPointsInsideThePolygon) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPointInsideThePolygon(LatLon test) {
|
||||||
|
boolean result = false;
|
||||||
|
for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) {
|
||||||
|
if ((polygon.get(i).getLongitude() > test.getLongitude()) != (polygon.get(j).getLongitude() > test.getLongitude()) &&
|
||||||
|
(test.getLatitude() < (polygon.get(j).getLatitude() - polygon.get(i).getLatitude()) * (test.getLongitude() - polygon.get(i).getLongitude())
|
||||||
|
/ (polygon.get(j).getLongitude()-polygon.get(i).getLongitude()) + polygon.get(i).getLatitude())) {
|
||||||
|
result = !result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isContinent() {
|
public boolean isContinent() {
|
||||||
if (superregion != null) {
|
if (superregion != null) {
|
||||||
String superRegionId = superregion.getRegionId();
|
String superRegionId = superregion.getRegionId();
|
||||||
|
|
Loading…
Reference in a new issue