From 2bfdea04f3f0c2aa542525efbd63105467ec0195 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 9 Aug 2017 10:26:04 +0300 Subject: [PATCH] Fit rect to map when adding segment --- .../osmand/plus/activities/MapActivity.java | 2 + .../osmand/plus/activities/TrackActivity.java | 65 ++++++++++++++++++- .../plus/myplaces/TrackSegmentFragment.java | 51 +-------------- 3 files changed, 66 insertions(+), 52 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 88704c75d8..bb3d84d043 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -932,6 +932,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint); } else if (toShow instanceof NewGpxLine) { NewGpxLine newGpxLine = (NewGpxLine) toShow; + QuadRect qr = newGpxLine.getRect(); + mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0); openAddingNewGpxLine(newGpxLine); } else { mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index cdb618e7ab..b848b69551 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -15,6 +15,7 @@ import android.view.View; import net.osmand.AndroidUtils; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.data.QuadRect; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; @@ -111,7 +112,8 @@ public class TrackActivity extends TabActivity { public void addLine() { GPXFile gpxFile = getGpx(); - NewGpxLine newGpxLine = new NewGpxLine(gpxFile); + QuadRect rect = getRect(); + NewGpxLine newGpxLine = new NewGpxLine(gpxFile, rect); WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null; if (pointToShow != null) { LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude()); @@ -127,6 +129,59 @@ public class TrackActivity extends TabActivity { } } + public QuadRect getRect() { + double left = 0, right = 0; + double top = 0, bottom = 0; + if (getGpx() != null) { + for (GPXUtilities.Track track : getGpx().tracks) { + for (GPXUtilities.TrkSegment segment : track.segments) { + for (WptPt p : segment.points) { + if (left == 0 && right == 0) { + left = p.getLongitude(); + right = p.getLongitude(); + top = p.getLatitude(); + bottom = p.getLatitude(); + } else { + left = Math.min(left, p.getLongitude()); + right = Math.max(right, p.getLongitude()); + top = Math.max(top, p.getLatitude()); + bottom = Math.min(bottom, p.getLatitude()); + } + } + } + } + for (WptPt p : getGpx().points) { + if (left == 0 && right == 0) { + left = p.getLongitude(); + right = p.getLongitude(); + top = p.getLatitude(); + bottom = p.getLatitude(); + } else { + left = Math.min(left, p.getLongitude()); + right = Math.max(right, p.getLongitude()); + top = Math.max(top, p.getLatitude()); + bottom = Math.min(bottom, p.getLatitude()); + } + } + for (GPXUtilities.Route route : getGpx().routes) { + for (WptPt p : route.points) { + if (left == 0 && right == 0) { + left = p.getLongitude(); + right = p.getLongitude(); + top = p.getLatitude(); + bottom = p.getLatitude(); + } else { + left = Math.min(left, p.getLongitude()); + right = Math.max(right, p.getLongitude()); + top = Math.max(top, p.getLatitude()); + bottom = Math.min(bottom, p.getLatitude()); + } + } + } + } + return new QuadRect(left, top, right, bottom); + } + protected void setGpxDataItem(GpxDataItem gpxDataItem) { this.gpxDataItem = gpxDataItem; } @@ -351,13 +406,19 @@ public class TrackActivity extends TabActivity { public static class NewGpxLine { private GPXFile gpxFile; + private QuadRect rect; - public NewGpxLine(GPXFile gpxFile) { + public NewGpxLine(GPXFile gpxFile, QuadRect rect) { this.gpxFile = gpxFile; + this.rect = rect; } public GPXFile getGpxFile() { return gpxFile; } + + public QuadRect getRect() { + return rect; + } } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 8ec1e1771c..32efad25ca 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -698,56 +698,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { } private QuadRect getRect() { - double left = 0, right = 0; - double top = 0, bottom = 0; - if (getGpx() != null) { - for (Track track : getGpx().tracks) { - for (TrkSegment segment : track.segments) { - for (WptPt p : segment.points) { - if (left == 0 && right == 0) { - left = p.getLongitude(); - right = p.getLongitude(); - top = p.getLatitude(); - bottom = p.getLatitude(); - } else { - left = Math.min(left, p.getLongitude()); - right = Math.max(right, p.getLongitude()); - top = Math.max(top, p.getLatitude()); - bottom = Math.min(bottom, p.getLatitude()); - } - } - } - } - for (WptPt p : getGpx().points) { - if (left == 0 && right == 0) { - left = p.getLongitude(); - right = p.getLongitude(); - top = p.getLatitude(); - bottom = p.getLatitude(); - } else { - left = Math.min(left, p.getLongitude()); - right = Math.max(right, p.getLongitude()); - top = Math.max(top, p.getLatitude()); - bottom = Math.min(bottom, p.getLatitude()); - } - } - for (Route route : getGpx().routes) { - for (WptPt p : route.points) { - if (left == 0 && right == 0) { - left = p.getLongitude(); - right = p.getLongitude(); - top = p.getLatitude(); - bottom = p.getLatitude(); - } else { - left = Math.min(left, p.getLongitude()); - right = Math.max(right, p.getLongitude()); - top = Math.max(top, p.getLatitude()); - bottom = Math.min(bottom, p.getLatitude()); - } - } - } - } - return new QuadRect(left, top, right, bottom); + return getTrackActivity().getRect(); } private List getOriginalGroups() {