Fix plan route lags with big gpx files

This commit is contained in:
max-klaus 2020-08-26 17:37:45 +03:00
parent ffde5da67a
commit c95dbff43e

View file

@ -12,6 +12,7 @@ import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.settings.backend.ApplicationMode;
@ -178,6 +179,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2).
drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb);
drawPoints(canvas, tb);
}
}
@ -185,6 +187,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (inMeasurementMode) {
lineAttrs.updatePaints(view.getApplication(), settings, tb);
drawBeforeAfterPath(canvas, tb);
if (editingCtx.getSelectedPointPosition() == -1) {
drawCenterIcon(canvas, tb, settings.isNightMode());
@ -203,90 +206,115 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
}
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
if (before.points.size() > 0 || after.points.size() > 0) {
path.reset();
tx.clear();
ty.clear();
if (before.points.size() > 0) {
WptPt pt = before.points.get(before.points.size() - 1);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
tx.add(locX);
ty.add(locY);
tx.add((float) tb.getCenterPixelX());
ty.add((float) tb.getCenterPixelY());
}
if (after.points.size() > 0) {
if (before.points.size() == 0) {
tx.add((float) tb.getCenterPixelX());
ty.add((float) tb.getCenterPixelY());
}
WptPt pt = after.points.get(0);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
tx.add(locX);
ty.add(locY);
}
GeometryWay.calculatePath(tb, tx, ty, path);
canvas.drawPath(path, lineAttrs.paint);
List<WptPt> beforePoints = editingCtx.getBeforePoints();
List<WptPt> afterPoints = editingCtx.getAfterPoints();
if (beforePoints.size() > 0) {
drawPointIcon(canvas, tb, beforePoints.get(beforePoints.size() - 1));
}
List<WptPt> points = new ArrayList<>();
points.addAll(editingCtx.getBeforePoints());
points.addAll(editingCtx.getAfterPoints());
overlapped = false;
int drawn = 0;
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
drawn++;
if (drawn > POINTS_TO_DRAW) {
overlapped = true;
break;
}
}
}
if (overlapped) {
WptPt pt = points.get(0);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
pt = points.get(points.size() - 1);
locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
} else {
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
if (afterPoints.size() > 0) {
drawPointIcon(canvas, tb, afterPoints.get(0));
}
if (editingCtx.getSelectedPointPosition() != -1) {
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
int locX = tb.getCenterPixelX();
int locY = tb.getCenterPixelY();
canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
}
}
private boolean isInTileBox(RotatedTileBox tb, WptPt point) {
QuadRect latLonBounds = tb.getLatLonBounds();
return point.getLatitude() >= latLonBounds.bottom && point.getLatitude() <= latLonBounds.top
&& point.getLongitude() >= latLonBounds.left && point.getLongitude() <= latLonBounds.right;
}
private void drawPoints(Canvas canvas, RotatedTileBox tb) {
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
WptPt lastBeforePoint = null;
List<WptPt> points = new ArrayList<>(editingCtx.getBeforePoints());
if (points.size() > 0) {
lastBeforePoint = points.get(points.size() - 1);
}
WptPt firstAfterPoint = null;
List<WptPt> afterPoints = editingCtx.getAfterPoints();
if (afterPoints.size() > 0) {
firstAfterPoint = afterPoints.get(0);
}
points.addAll(afterPoints);
overlapped = false;
int drawn = 0;
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
if (tb.containsLatLon(pt.lat, pt.lon)) {
drawn++;
if (drawn > POINTS_TO_DRAW) {
overlapped = true;
break;
}
}
}
if (overlapped) {
WptPt pt = points.get(0);
if (pt != lastBeforePoint && pt != firstAfterPoint && isInTileBox(tb, pt)) {
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
pt = points.get(points.size() - 1);
if (pt != lastBeforePoint && pt != firstAfterPoint && isInTileBox(tb, pt)) {
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
} else {
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
if (pt != lastBeforePoint && pt != firstAfterPoint && isInTileBox(tb, pt)) {
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
}
}
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
private void drawBeforeAfterPath(Canvas canvas, RotatedTileBox tb) {
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
if (before.points.size() > 0 || after.points.size() > 0) {
path.reset();
tx.clear();
ty.clear();
if (before.points.size() > 0) {
WptPt pt = before.points.get(before.points.size() - 1);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
tx.add(locX);
ty.add(locY);
tx.add((float) tb.getCenterPixelX());
ty.add((float) tb.getCenterPixelY());
}
if (after.points.size() > 0) {
if (before.points.size() == 0) {
tx.add((float) tb.getCenterPixelX());
ty.add((float) tb.getCenterPixelY());
}
WptPt pt = after.points.get(0);
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
tx.add(locX);
ty.add(locY);
}
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
GeometryWay.calculatePath(tb, tx, ty, path);
canvas.drawPath(path, lineAttrs.paint);
}
}
@ -298,6 +326,16 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
private void drawPointIcon(Canvas canvas, RotatedTileBox tb, WptPt pt) {
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
float locX = tb.getPixXFromLatLon(pt.lat, pt.lon);
float locY = tb.getPixYFromLatLon(pt.lat, pt.lon);
if (tb.containsPoint(locX, locY, 0)) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
public WptPt addCenterPoint() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon l = tb.getCenterLatLon();