Update arrows
This commit is contained in:
parent
26bbb9f937
commit
0f6db423ca
3 changed files with 81 additions and 33 deletions
|
@ -343,7 +343,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
||||||
tx.add(x);
|
tx.add(x);
|
||||||
ty.add(y);
|
ty.add(y);
|
||||||
}
|
}
|
||||||
calculatePath(tb, tx, ty, path, null);
|
calculatePath(tb, tx, ty, path);
|
||||||
if(isPaint_1) {
|
if(isPaint_1) {
|
||||||
canvas.drawPath(path, paint_1);
|
canvas.drawPath(path, paint_1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,44 @@ public abstract class OsmandMapLayer {
|
||||||
return x >= lx && x <= rx && y >= ty && y <= by;
|
return x >= lx && x <= rx && y >= ty && y <= by;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path, List<Path> createNewAdditionalPath) {
|
public int calculateSplitPaths(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys,
|
||||||
|
TIntArrayList results) {
|
||||||
|
int px = xs.get(0);
|
||||||
|
int py = ys.get(0);
|
||||||
|
int h = tb.getPixHeight();
|
||||||
|
int w = tb.getPixWidth();
|
||||||
|
int cnt = 0;
|
||||||
|
boolean pin = isIn(px, py, 0, 0, w, h);
|
||||||
|
Path path = null;
|
||||||
|
for(int i = 1; i < xs.size(); i++) {
|
||||||
|
int x = xs.get(i);
|
||||||
|
int y = ys.get(i);
|
||||||
|
boolean in = isIn(x, y, 0, 0, w, h);
|
||||||
|
boolean draw = false;
|
||||||
|
if(pin && in) {
|
||||||
|
draw = true;
|
||||||
|
} else {
|
||||||
|
long intersection = MapAlgorithms.calculateIntersection(x, y,
|
||||||
|
px, py, 0, w, h, 0);
|
||||||
|
if (intersection != -1) {
|
||||||
|
draw = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (draw) {
|
||||||
|
path = new Path();
|
||||||
|
results.add(px);
|
||||||
|
results.add(py);
|
||||||
|
results.add(x);
|
||||||
|
results.add(y);
|
||||||
|
}
|
||||||
|
pin = in;
|
||||||
|
px = x;
|
||||||
|
py = y;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
|
||||||
boolean start = false;
|
boolean start = false;
|
||||||
int px = xs.get(0);
|
int px = xs.get(0);
|
||||||
int py = ys.get(0);
|
int py = ys.get(0);
|
||||||
|
@ -105,10 +142,6 @@ public abstract class OsmandMapLayer {
|
||||||
}
|
}
|
||||||
if (draw) {
|
if (draw) {
|
||||||
if (!start) {
|
if (!start) {
|
||||||
if (createNewAdditionalPath != null) {
|
|
||||||
path = new Path();
|
|
||||||
createNewAdditionalPath.add(path);
|
|
||||||
}
|
|
||||||
cnt++;
|
cnt++;
|
||||||
path.moveTo(px, py);
|
path.moveTo(px, py);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import android.graphics.PathMeasure;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.graphics.PorterDuff.Mode;
|
import android.graphics.PorterDuff.Mode;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
|
import android.util.FloatMath;
|
||||||
|
|
||||||
public class RouteLayer extends OsmandMapLayer {
|
public class RouteLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ public class RouteLayer extends OsmandMapLayer {
|
||||||
tx.add(x);
|
tx.add(x);
|
||||||
ty.add(y);
|
ty.add(y);
|
||||||
}
|
}
|
||||||
int pth = calculatePath(tb, tx, ty, path, null);
|
calculatePath(tb, tx, ty, path);
|
||||||
|
|
||||||
if(isPaint_1) {
|
if(isPaint_1) {
|
||||||
canvas.drawPath(path, paint_1);
|
canvas.drawPath(path, paint_1);
|
||||||
|
@ -187,40 +188,54 @@ public class RouteLayer extends OsmandMapLayer {
|
||||||
canvas.drawPath(path, paint2);
|
canvas.drawPath(path, paint2);
|
||||||
}
|
}
|
||||||
if (tb.getZoomAnimation() == 0) {
|
if (tb.getZoomAnimation() == 0) {
|
||||||
if(pth <= 1) {
|
TIntArrayList lst = new TIntArrayList(50);
|
||||||
drawArrowsOverPath(canvas, path, coloredArrowUp);
|
calculateSplitPaths(tb, tx, ty, lst);
|
||||||
} else {
|
drawArrowsOverPath(canvas, lst, coloredArrowUp);
|
||||||
ArrayList<Path> lst = new ArrayList<Path>();
|
|
||||||
calculatePath(tb, tx, ty, path, lst);
|
|
||||||
for(Path l : lst) {
|
|
||||||
drawArrowsOverPath(canvas, l, coloredArrowUp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void drawArrowsOverPath(Canvas canvas, Path path, Bitmap arrow) {
|
private void drawArrowsOverPath(Canvas canvas, TIntArrayList lst, Bitmap arrow) {
|
||||||
PathMeasure pm = new PathMeasure();
|
|
||||||
pm.setPath(path, false);
|
|
||||||
float pxStep = arrow.getHeight() * 4f;
|
float pxStep = arrow.getHeight() * 4f;
|
||||||
float dist = pxStep;
|
|
||||||
double length = pm.getLength();
|
|
||||||
Matrix matrix = new Matrix();
|
Matrix matrix = new Matrix();
|
||||||
float[] pos = new float[2];
|
float dist = 0;
|
||||||
float[] tan = new float[2];
|
for (int i = 0; i < lst.size(); i += 4) {
|
||||||
while(dist < length) {
|
int px = lst.get(i);
|
||||||
if(pm.getPosTan(dist, pos, tan)) {
|
int py = lst.get(i + 1);
|
||||||
|
int x = lst.get(i + 2);
|
||||||
|
int y = lst.get(i + 3);
|
||||||
|
float angleRad = (float) Math.atan2(y - py, x - px);
|
||||||
|
float angle = (float) (angleRad * 180 / Math.PI) + 90f;
|
||||||
|
float distSegment = FloatMath.sqrt((y - py) * (y - py) + (x - px) * (x - px));
|
||||||
|
if(distSegment == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int len = (int) (distSegment / pxStep);
|
||||||
|
if (len > 0) {
|
||||||
|
float pdx = ((x - px) / len);
|
||||||
|
float pdy = ((y - py) / len);
|
||||||
|
for (int k = 1; k <= len; k++) {
|
||||||
matrix.reset();
|
matrix.reset();
|
||||||
matrix.postTranslate(0, -arrow.getHeight() / 2);
|
matrix.postTranslate(0, -arrow.getHeight() / 2);
|
||||||
matrix.postRotate((float) (Math.atan2(tan[1], tan[0]) * 180 / Math.PI) + 90f,
|
matrix.postRotate(angle, arrow.getWidth() / 2, 0);
|
||||||
arrow.getWidth() / 2, 0);
|
matrix.postTranslate(px + k * pdx- arrow.getWidth() / 2 , py + pdy * k);
|
||||||
matrix.postTranslate(pos[0] - arrow.getWidth() / 2, pos[1]);
|
|
||||||
canvas.drawBitmap(arrow, matrix, paintIcon);
|
canvas.drawBitmap(arrow, matrix, paintIcon);
|
||||||
|
dist = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(dist > pxStep) {
|
||||||
|
matrix.reset();
|
||||||
|
matrix.postTranslate(0, -arrow.getHeight() / 2);
|
||||||
|
matrix.postRotate(angle, arrow.getWidth() / 2, 0);
|
||||||
|
matrix.postTranslate(px + (x - px) / 2 - arrow.getWidth() / 2, py + (y - py) / 2);
|
||||||
|
canvas.drawBitmap(arrow, matrix, paintIcon);
|
||||||
|
dist = 0;
|
||||||
|
} else {
|
||||||
|
dist += distSegment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dist += pxStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue