Fix gpx context menu navigation and add check for segment bounds
This commit is contained in:
parent
7156452f62
commit
e225ad7b03
5 changed files with 35 additions and 22 deletions
|
@ -957,6 +957,24 @@ public class GPXUtilities {
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static QuadRect calculateBounds(List<WptPt> pts) {
|
||||||
|
QuadRect trackBounds = new QuadRect(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
|
||||||
|
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
|
||||||
|
updateBounds(trackBounds, pts, 0);
|
||||||
|
|
||||||
|
return trackBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateBounds(QuadRect trackBounds, List<WptPt> pts, int startIndex) {
|
||||||
|
for (int i = startIndex; i < pts.size(); i++) {
|
||||||
|
WptPt pt = pts.get(i);
|
||||||
|
trackBounds.right = Math.max(trackBounds.right, pt.lon);
|
||||||
|
trackBounds.left = Math.min(trackBounds.left, pt.lon);
|
||||||
|
trackBounds.top = Math.max(trackBounds.top, pt.lat);
|
||||||
|
trackBounds.bottom = Math.min(trackBounds.bottom, pt.lat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class GPXFile extends GPXExtensions {
|
public static class GPXFile extends GPXExtensions {
|
||||||
public String author;
|
public String author;
|
||||||
public Metadata metadata;
|
public Metadata metadata;
|
||||||
|
|
|
@ -289,6 +289,10 @@ public class PointDescription {
|
||||||
return POINT_TYPE_CUSTOM_POI_FILTER.equals(type);
|
return POINT_TYPE_CUSTOM_POI_FILTER.equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGpxPoint() {
|
||||||
|
return POINT_TYPE_GPX.equals(type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|
|
@ -673,6 +673,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
if (trackDetailsMenu.isVisible()) {
|
if (trackDetailsMenu.isVisible()) {
|
||||||
trackDetailsMenu.hide(true);
|
trackDetailsMenu.hide(true);
|
||||||
|
if (mapContextMenu.isActive() && mapContextMenu.getPointDescription() != null
|
||||||
|
&& mapContextMenu.getPointDescription().isGpxPoint()) {
|
||||||
|
mapContextMenu.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (prevActivityIntent == null) {
|
if (prevActivityIntent == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -604,8 +604,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
|
||||||
for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) {
|
for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) {
|
||||||
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
|
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
|
||||||
for (TrkSegment segment : segments) {
|
for (TrkSegment segment : segments) {
|
||||||
boolean nearSegment = isPointNearSegment(tb, segment.points, r, mx, my);
|
QuadRect trackBounds = GPXUtilities.calculateBounds(segment.points);
|
||||||
if (nearSegment) {
|
if (QuadRect.trivialOverlap(tb.getLatLonBounds(), trackBounds) && isPointNearSegment(tb, segment.points, r, mx, my)) {
|
||||||
res.add(selectedGpxFile);
|
res.add(selectedGpxFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.Paint;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
|
@ -61,10 +62,10 @@ public class Renderable {
|
||||||
protected AsynchronousResampler culler = null; // The currently active resampler
|
protected AsynchronousResampler culler = null; // The currently active resampler
|
||||||
protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use
|
protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use
|
||||||
|
|
||||||
public RenderableSegment(List <WptPt> points, double segmentSize) {
|
public RenderableSegment(List<WptPt> points, double segmentSize) {
|
||||||
this.points = points;
|
this.points = points;
|
||||||
calculateBounds(points);
|
|
||||||
this.segmentSize = segmentSize;
|
this.segmentSize = segmentSize;
|
||||||
|
trackBounds = GPXUtilities.calculateBounds(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateLocalPaint(Paint p) {
|
protected void updateLocalPaint(Paint p) {
|
||||||
|
@ -90,23 +91,6 @@ public class Renderable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateBounds(List<WptPt> pts) {
|
|
||||||
trackBounds = new QuadRect(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
|
|
||||||
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
|
|
||||||
updateBounds(pts, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateBounds(List<WptPt> pts, int startIndex) {
|
|
||||||
pointSize = pts.size();
|
|
||||||
for (int i = startIndex; i < pointSize; i++) {
|
|
||||||
WptPt pt = pts.get(i);
|
|
||||||
trackBounds.right = Math.max(trackBounds.right, pt.lon);
|
|
||||||
trackBounds.left = Math.min(trackBounds.left, pt.lon);
|
|
||||||
trackBounds.top = Math.max(trackBounds.top, pt.lat);
|
|
||||||
trackBounds.bottom = Math.min(trackBounds.bottom, pt.lat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRDP(List<WptPt> cull) {
|
public void setRDP(List<WptPt> cull) {
|
||||||
culled = cull;
|
culled = cull;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +182,9 @@ public class Renderable {
|
||||||
|
|
||||||
@Override public void drawSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) {
|
@Override public void drawSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) {
|
||||||
if (points.size() != pointSize) {
|
if (points.size() != pointSize) {
|
||||||
updateBounds(points, pointSize);
|
int prevSize = pointSize;
|
||||||
|
pointSize = points.size();
|
||||||
|
GPXUtilities.updateBounds(trackBounds, points, prevSize);
|
||||||
}
|
}
|
||||||
drawSingleSegment(zoom, p, canvas, tileBox);
|
drawSingleSegment(zoom, p, canvas, tileBox);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue