diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 4ed8aa719a..b630233137 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -219,14 +219,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL if (editingCtx.isInMultiProfileMode()) { multiProfileGeometryWayContext.updatePaints(settings.isNightMode(), multiProfileLineAttrs); - for (int i = 0; i < editingCtx.getBeforeSegments().size(); i++) { - multiProfileGeometry.updateRoute(tb, editingCtx.getRoadSegmentData(), true, editingCtx.getBeforeSegments(), i); - multiProfileGeometry.drawSegments(canvas, tb); - } - for (int i = 0; i < editingCtx.getAfterSegments().size(); i++) { - multiProfileGeometry.updateRoute(tb, editingCtx.getRoadSegmentData(), false, editingCtx.getAfterSegments(), i); - multiProfileGeometry.drawSegments(canvas, tb); - } + List allSegments = new ArrayList<>(); + allSegments.addAll(editingCtx.getBeforeSegments()); + allSegments.addAll(editingCtx.getAfterSegments()); + multiProfileGeometry.updateRoute(tb, editingCtx.getRoadSegmentData(), allSegments); + multiProfileGeometry.drawSegments(canvas, tb); } else { multiProfileGeometry.clearWay(); List before = editingCtx.getBeforeTrkSegmentLine(); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java index 865e56e60b..5096cfa59f 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java @@ -36,8 +36,7 @@ public class MultiProfileGeometryWay extends GeometryWay, RoadSegmentData> segmentData; - private List beforeSegments; - private List afterSegments; + private List segments; public MultiProfileGeometryWay(MultiProfileGeometryWayContext context) { super(context, new MultiProfileGeometryWayDrawer(context)); @@ -60,8 +59,10 @@ public class MultiProfileGeometryWay extends GeometryWay> currPathStyle = pathStyles.get(i); - getDrawer().drawPathBorder(canvas, currPathStyle.first, currPathStyle.second); - getDrawer().drawPath(canvas, currPathStyle.first, currPathStyle.second); + if (!((GeometryMultiProfileWayStyle) currPathStyle.second).isGap) { + getDrawer().drawPathBorder(canvas, currPathStyle.first, currPathStyle.second); + getDrawer().drawPath(canvas, currPathStyle.first, currPathStyle.second); + } } getDrawer().drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles); } finally { @@ -69,20 +70,18 @@ public class MultiProfileGeometryWay extends GeometryWay, RoadSegmentData> segmentData, - boolean before, List segments, int segmentIdx) { + public void updateRoute(RotatedTileBox tileBox, Map, RoadSegmentData> segmentData, List segments) { boolean shouldUpdateRoute = tileBox.getMapDensity() != getMapDensity() || segmentDataChanged(segmentData) - || getSegments(before) != segments || getLocationProvider() == null; + || this.segments != segments || getLocationProvider() == null; if (shouldUpdateRoute) { this.segmentData = segmentData; - setSegments(before, segments); - List userPoints = segments.get(segmentIdx).points; + this.segments = segments; List locations; Map> styleMap; List ways = new ArrayList<>(); List> styles = new ArrayList<>(); - setStyles(tileBox, userPoints, ways, styles); + setStyles(tileBox, segments, ways, styles); locations = new ArrayList<>(); styleMap = new TreeMap<>(); @@ -105,51 +104,72 @@ public class MultiProfileGeometryWay extends GeometryWay userPoints, List ways, List> styles) { - MultiProfileGeometryWayContext context = getContext(); + @Override + public void clearWay() { + super.clearWay(); + if (segmentData != null) { + segmentData.clear(); + } + } + + private void setStyles(RotatedTileBox tileBox, List segments, List ways, List> styles) { Path path = new Path(); PathMeasure pathMeasure = new PathMeasure(); - for (int i = 0; i < userPoints.size() - 1; i++) { - WptPt leftPt = userPoints.get(i); - Pair userLine = new Pair<>(leftPt, userPoints.get(i + 1)); - RoadSegmentData routeBetweenPoints = segmentData.get(userLine); - + for (TrkSegment segment : segments) { + List points = segment.points; + for (int i = 0; i < points.size() - 1; i++) { + setStylesInternal(tileBox, points, i, ways, styles, path, pathMeasure); + } + styles.add(new GeometryMultiProfileWayStyle(getContext(), 0, 0, true)); Way way = new Way(-1); - String currProfileKey = getProfileKey(leftPt); - Pair profileData = getProfileData(currProfileKey); - GeometryMultiProfileWayStyle style = new GeometryMultiProfileWayStyle( - getContext(), currProfileKey, profileData.first, profileData.second); - styles.add(style); + WptPt last = points.get(points.size() - 1); + way.addNode(new Node(last.lat, last.lon, -1)); ways.add(way); + } + } - path.reset(); - boolean isSecondToLast = i + 2 == userPoints.size(); - if (routeBetweenPoints == null || Algorithms.isEmpty(routeBetweenPoints.getPoints())) { - way.addNode(new Node(userLine.first.lat, userLine.first.lon, -1)); - if (isSecondToLast) { - way.addNode(new Node(userLine.second.lat, userLine.second.lon, -1)); - } - movePathToWpt(path, tileBox, userLine.first); - pathLineToWpt(path, tileBox, userLine.second); - } else { - movePathToWpt(path, tileBox, routeBetweenPoints.getPoints().get(0)); - for (WptPt pt : routeBetweenPoints.getPoints()) { - if (pt.lat != userLine.second.lat && pt.lon != userLine.second.lon || isSecondToLast) { - way.addNode(new Node(pt.lat, pt.lon, -1)); - } - pathLineToWpt(path, tileBox, pt); - } - } + private void setStylesInternal(RotatedTileBox tileBox, List points, int idx, List ways, + List> styles, Path path, PathMeasure pathMeasure) { + MultiProfileGeometryWayContext context = getContext(); + WptPt leftPt = points.get(idx); + Pair userLine = new Pair<>(leftPt, points.get(idx + 1)); + RoadSegmentData routeBetweenPoints = segmentData.get(userLine); + boolean isSecondToLast = idx + 2 == points.size(); - float[] xy = new float[2]; - pathMeasure.setPath(path, false); - float routeLength = pathMeasure.getLength(); - if ((routeLength - context.circleSize) / 2 >= context.minIconMargin) { - pathMeasure.getPosTan(pathMeasure.getLength() * 0.5f, xy, null); - style.setIconLat(tileBox.getLatFromPixel(xy[0], xy[1])); - style.setIconLon(tileBox.getLonFromPixel(xy[0], xy[1])); + Way way = new Way(-1); + String currProfileKey = getProfileKey(leftPt); + Pair profileData = getProfileData(currProfileKey); + GeometryMultiProfileWayStyle style = new GeometryMultiProfileWayStyle( + getContext(), profileData.first, profileData.second); + styles.add(style); + ways.add(way); + + path.reset(); + if (routeBetweenPoints == null || Algorithms.isEmpty(routeBetweenPoints.getPoints())) { + way.addNode(new Node(userLine.first.lat, userLine.first.lon, -1)); + if (isSecondToLast) { + way.addNode(new Node(userLine.second.lat, userLine.second.lon, -1)); } + movePathToWpt(path, tileBox, userLine.first); + pathLineToWpt(path, tileBox, userLine.second); + } else { + movePathToWpt(path, tileBox, routeBetweenPoints.getPoints().get(0)); + for (WptPt pt : routeBetweenPoints.getPoints()) { + if (pt.lat != userLine.second.lat && pt.lon != userLine.second.lon || isSecondToLast) { + way.addNode(new Node(pt.lat, pt.lon, -1)); + } + pathLineToWpt(path, tileBox, pt); + } + } + + float[] xy = new float[2]; + pathMeasure.setPath(path, false); + float routeLength = pathMeasure.getLength(); + if ((routeLength - context.circleSize) / 2 >= context.minIconMargin) { + pathMeasure.getPosTan(pathMeasure.getLength() * 0.5f, xy, null); + style.setIconLat(tileBox.getLatFromPixel(xy[0], xy[1])); + style.setIconLon(tileBox.getLonFromPixel(xy[0], xy[1])); } } @@ -181,18 +201,6 @@ public class MultiProfileGeometryWay extends GeometryWay segments) { - if (before) { - this.beforeSegments = segments; - } else { - this.afterSegments = segments; - } - } - - private List getSegments(boolean before) { - return before ? this.beforeSegments : this.afterSegments; - } - private void movePathToWpt(Path path, RotatedTileBox tileBox, WptPt pt) { path.moveTo(tileBox.getPixXFromLatLon(pt.lat, pt.lon), tileBox.getPixYFromLatLon(pt.lat, pt.lon)); } @@ -221,9 +229,8 @@ public class MultiProfileGeometryWay extends GeometryWay { + public static class GeometryMultiProfileWayStyle extends GeometryWayStyle { - private final String profileKey; @ColorInt private final int lineColor; @ColorInt @@ -231,16 +238,25 @@ public class MultiProfileGeometryWay extends GeometryWay