From d3f6b65b560258ffb52008be51fa73a8824af762 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Jan 2015 22:23:49 +0100 Subject: [PATCH] Source layer --- .../src/net/osmand/plus/views/GPXLayer.java | 2 +- .../net/osmand/plus/views/OsmandMapLayer.java | 36 +++++++++++-------- .../src/net/osmand/plus/views/RouteLayer.java | 12 +++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 0b0c2c3b0d..e10544382f 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -337,7 +337,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex tx.add(x); ty.add(y); } - calculatePath(tb, tx, ty, path); + calculatePath(tb, tx, ty, path, null); if(isPaint_1) { canvas.drawPath(path, paint_1); } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index d3d815e362..fab95a9597 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -2,6 +2,7 @@ package net.osmand.plus.views; import gnu.trove.list.array.TIntArrayList; +import java.util.List; import java.util.Map; import net.osmand.data.RotatedTileBox; @@ -78,41 +79,48 @@ public abstract class OsmandMapLayer { return x >= lx && x <= rx && y >= ty && y <= by; } - public void calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) { + public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path, List createNewAdditionalPath) { boolean start = false; 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); 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) { - if(!start) { + draw = true; + } else { + long intersection = MapAlgorithms.calculateIntersection(x, y, + px, py, 0, w, h, 0); + if (intersection != -1) { + px = (int) (intersection >> 32); + py = (int) (intersection & 0xffffffff); + } + } + if (draw) { + if (!start) { + if (createNewAdditionalPath != null) { + path = new Path(); + createNewAdditionalPath.add(path); + } + cnt++; path.moveTo(px, py); } path.lineTo(x, y); start = true; } else{ - long intersection = MapAlgorithms.calculateIntersection(x, y, px, py, 0, w, h, 0); - if(intersection != -1) { - int bx = (int) (intersection >> 32); - int by = (int) (intersection & 0xffffffff); - if(!start) { - path.moveTo(bx, by); - } - path.lineTo(x, y); - start = true; - } else { - start = false; - } + start = false; } pin = in; px = x; py = y; } + return cnt; } diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index ad17459bef..5d40ca1597 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -173,7 +173,7 @@ public class RouteLayer extends OsmandMapLayer { tx.add(x); ty.add(y); } - calculatePath(tb, tx, ty, path); + int pth = calculatePath(tb, tx, ty, path, null); if(isPaint_1) { canvas.drawPath(path, paint_1); @@ -186,7 +186,15 @@ public class RouteLayer extends OsmandMapLayer { canvas.drawPath(path, paint2); } if(tb.getZoomAnimation() == 0) { - drawArrowsOverPath(canvas, path, coloredArrowUp); + if(pth <= 1) { + drawArrowsOverPath(canvas, path, coloredArrowUp); + } else { + ArrayList lst = new ArrayList(); + calculatePath(tb, tx, ty, path, lst); + for(Path l : lst) { + drawArrowsOverPath(canvas, l, coloredArrowUp); + } + } } } }