From 2ce29533fc78110b012aaa898427e05a91113abf Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 9 Jun 2015 00:19:02 +0200 Subject: [PATCH] Improve GPX display (when the points having 2-5 km far away, the line breaks up). To be properly tested before release --- .../src/net/osmand/plus/views/GPXLayer.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 439b84b767..a073b314cc 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -303,19 +303,30 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex for (List l : points) { path.rewind(); int startIndex = -1; + int endIndex = -1; + int prevCross = 0; + boolean intersect = false; for (int i = 0; i < l.size(); i++) { WptPt ls = l.get(i); - if (startIndex == -1) { - if (ls.lat >= latLonBounds.bottom - 0.1 && ls.lat <= latLonBounds.top + 0.1 && ls.lon >= latLonBounds.left - 0.1 - && ls.lon <= latLonBounds.right + 0.1) { - startIndex = i > 0 ? i - 1 : i; + int cross = 0; + cross |= (ls.lon < latLonBounds.left - 0.1 ? 1 : 0); + cross |= (ls.lon > latLonBounds.right + 0.1 ? 2 : 0); + cross |= (ls.lat > latLonBounds.top + 0.1 ? 4 : 0); + cross |= (ls.lat < latLonBounds.bottom - 0.1 ? 8 : 0); + if (i > 0) { + if ((prevCross & cross) == 0) { + if (prevCross != 0 || !intersect) { + if (startIndex > 0) { + drawSegment(canvas, tileBox, l, startIndex, endIndex); + } + startIndex = i - 1; + } + endIndex = i; + intersect = true; } - } else if (!(latLonBounds.left <= ls.lon + 0.1 && ls.lon - 0.1 <= latLonBounds.right - && latLonBounds.bottom <= ls.lat + 0.1 && ls.lat - 0.1 <= latLonBounds.top)) { - drawSegment(canvas, tileBox, l, startIndex, i); - startIndex = -1; } + prevCross = cross; } if (startIndex != -1) { drawSegment(canvas, tileBox, l, startIndex, l.size() - 1);