Fit rect to map when adding segment

This commit is contained in:
PavelRatushny 2017-08-09 10:26:04 +03:00
parent aa641516c9
commit 2bfdea04f3
3 changed files with 66 additions and 52 deletions

View file

@ -932,6 +932,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint); getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
} else if (toShow instanceof NewGpxLine) { } else if (toShow instanceof NewGpxLine) {
NewGpxLine newGpxLine = (NewGpxLine) toShow; 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); openAddingNewGpxLine(newGpxLine);
} else { } else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);

View file

@ -15,6 +15,7 @@ import android.view.View;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
@ -111,7 +112,8 @@ public class TrackActivity extends TabActivity {
public void addLine() { public void addLine() {
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
NewGpxLine newGpxLine = new NewGpxLine(gpxFile); QuadRect rect = getRect();
NewGpxLine newGpxLine = new NewGpxLine(gpxFile, rect);
WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null; WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null;
if (pointToShow != null) { if (pointToShow != null) {
LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude()); 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) { protected void setGpxDataItem(GpxDataItem gpxDataItem) {
this.gpxDataItem = gpxDataItem; this.gpxDataItem = gpxDataItem;
} }
@ -351,13 +406,19 @@ public class TrackActivity extends TabActivity {
public static class NewGpxLine { public static class NewGpxLine {
private GPXFile gpxFile; private GPXFile gpxFile;
private QuadRect rect;
public NewGpxLine(GPXFile gpxFile) { public NewGpxLine(GPXFile gpxFile, QuadRect rect) {
this.gpxFile = gpxFile; this.gpxFile = gpxFile;
this.rect = rect;
} }
public GPXFile getGpxFile() { public GPXFile getGpxFile() {
return gpxFile; return gpxFile;
} }
public QuadRect getRect() {
return rect;
}
} }
} }

View file

@ -698,56 +698,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
} }
private QuadRect getRect() { private QuadRect getRect() {
double left = 0, right = 0; return getTrackActivity().getRect();
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);
} }
private List<GpxDisplayGroup> getOriginalGroups() { private List<GpxDisplayGroup> getOriginalGroups() {