Support multiple segments
This commit is contained in:
parent
bf55e86a7e
commit
14209dbd01
4 changed files with 95 additions and 80 deletions
|
@ -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);
|
||||
List<TrkSegment> allSegments = new ArrayList<>();
|
||||
allSegments.addAll(editingCtx.getBeforeSegments());
|
||||
allSegments.addAll(editingCtx.getAfterSegments());
|
||||
multiProfileGeometry.updateRoute(tb, editingCtx.getRoadSegmentData(), allSegments);
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
multiProfileGeometry.clearWay();
|
||||
List<TrkSegment> before = editingCtx.getBeforeTrkSegmentLine();
|
||||
|
|
|
@ -36,8 +36,7 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
private static final String DEFAULT_PROFILE_KEY = ApplicationMode.DEFAULT.getStringKey();
|
||||
|
||||
private Map<Pair<WptPt, WptPt>, RoadSegmentData> segmentData;
|
||||
private List<TrkSegment> beforeSegments;
|
||||
private List<TrkSegment> afterSegments;
|
||||
private List<TrkSegment> segments;
|
||||
|
||||
public MultiProfileGeometryWay(MultiProfileGeometryWayContext context) {
|
||||
super(context, new MultiProfileGeometryWayDrawer(context));
|
||||
|
@ -60,29 +59,29 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
|
||||
for (int i = 0; i < pathStyles.size(); i++) {
|
||||
Pair<Path, GeometryWayStyle<?>> currPathStyle = pathStyles.get(i);
|
||||
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 {
|
||||
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRoute(RotatedTileBox tileBox, Map<Pair<WptPt, WptPt>, RoadSegmentData> segmentData,
|
||||
boolean before, List<TrkSegment> segments, int segmentIdx) {
|
||||
public void updateRoute(RotatedTileBox tileBox, Map<Pair<WptPt, WptPt>, RoadSegmentData> segmentData, List<TrkSegment> 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<WptPt> userPoints = segments.get(segmentIdx).points;
|
||||
this.segments = segments;
|
||||
List<Location> locations;
|
||||
Map<Integer, GeometryWayStyle<?>> styleMap;
|
||||
|
||||
List<Way> ways = new ArrayList<>();
|
||||
List<GeometryWayStyle<?>> styles = new ArrayList<>();
|
||||
setStyles(tileBox, userPoints, ways, styles);
|
||||
setStyles(tileBox, segments, ways, styles);
|
||||
locations = new ArrayList<>();
|
||||
|
||||
styleMap = new TreeMap<>();
|
||||
|
@ -105,26 +104,48 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
}
|
||||
}
|
||||
|
||||
private void setStyles(RotatedTileBox tileBox, List<WptPt> userPoints, List<Way> ways, List<GeometryWayStyle<?>> styles) {
|
||||
MultiProfileGeometryWayContext context = getContext();
|
||||
@Override
|
||||
public void clearWay() {
|
||||
super.clearWay();
|
||||
if (segmentData != null) {
|
||||
segmentData.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void setStyles(RotatedTileBox tileBox, List<TrkSegment> segments, List<Way> ways, List<GeometryWayStyle<?>> styles) {
|
||||
Path path = new Path();
|
||||
PathMeasure pathMeasure = new PathMeasure();
|
||||
|
||||
for (int i = 0; i < userPoints.size() - 1; i++) {
|
||||
WptPt leftPt = userPoints.get(i);
|
||||
Pair<WptPt, WptPt> userLine = new Pair<>(leftPt, userPoints.get(i + 1));
|
||||
for (TrkSegment segment : segments) {
|
||||
List<WptPt> 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);
|
||||
WptPt last = points.get(points.size() - 1);
|
||||
way.addNode(new Node(last.lat, last.lon, -1));
|
||||
ways.add(way);
|
||||
}
|
||||
}
|
||||
|
||||
private void setStylesInternal(RotatedTileBox tileBox, List<WptPt> points, int idx, List<Way> ways,
|
||||
List<GeometryWayStyle<?>> styles, Path path, PathMeasure pathMeasure) {
|
||||
MultiProfileGeometryWayContext context = getContext();
|
||||
WptPt leftPt = points.get(idx);
|
||||
Pair<WptPt, WptPt> userLine = new Pair<>(leftPt, points.get(idx + 1));
|
||||
RoadSegmentData routeBetweenPoints = segmentData.get(userLine);
|
||||
boolean isSecondToLast = idx + 2 == points.size();
|
||||
|
||||
Way way = new Way(-1);
|
||||
String currProfileKey = getProfileKey(leftPt);
|
||||
Pair<Integer, Integer> profileData = getProfileData(currProfileKey);
|
||||
GeometryMultiProfileWayStyle style = new GeometryMultiProfileWayStyle(
|
||||
getContext(), currProfileKey, profileData.first, profileData.second);
|
||||
getContext(), profileData.first, profileData.second);
|
||||
styles.add(style);
|
||||
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) {
|
||||
|
@ -151,7 +172,6 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
style.setIconLon(tileBox.getLonFromPixel(xy[0], xy[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldAddLocation(RotatedTileBox tileBox, double leftLon, double rightLon,
|
||||
|
@ -181,18 +201,6 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
return false;
|
||||
}
|
||||
|
||||
private void setSegments(boolean before, List<TrkSegment> segments) {
|
||||
if (before) {
|
||||
this.beforeSegments = segments;
|
||||
} else {
|
||||
this.afterSegments = segments;
|
||||
}
|
||||
}
|
||||
|
||||
private List<TrkSegment> 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));
|
||||
}
|
||||
|
@ -223,7 +231,6 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
|
||||
public static class GeometryMultiProfileWayStyle extends GeometryWayStyle<MultiProfileGeometryWayContext> {
|
||||
|
||||
private final String profileKey;
|
||||
@ColorInt
|
||||
private final int lineColor;
|
||||
@ColorInt
|
||||
|
@ -231,16 +238,25 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
@DrawableRes
|
||||
private final int profileIconRes;
|
||||
|
||||
private double iconLat;
|
||||
private double iconLon;
|
||||
private final boolean isGap;
|
||||
|
||||
public GeometryMultiProfileWayStyle(MultiProfileGeometryWayContext context, String profileKey,
|
||||
@ColorInt int profileColor, @DrawableRes int profileIconRes) {
|
||||
private double iconLat = Double.NaN;
|
||||
private double iconLon = Double.NaN;
|
||||
|
||||
public GeometryMultiProfileWayStyle(MultiProfileGeometryWayContext context,
|
||||
@ColorInt int profileColor, @DrawableRes int profileIconRes,
|
||||
boolean isGap) {
|
||||
super(context);
|
||||
this.profileKey = profileKey;
|
||||
this.lineColor = profileColor;
|
||||
this.borderColor = ColorUtils.blendARGB(profileColor, Color.BLACK, 0.2f);
|
||||
this.profileIconRes = profileIconRes;
|
||||
this.isGap = isGap;
|
||||
}
|
||||
|
||||
|
||||
public GeometryMultiProfileWayStyle(MultiProfileGeometryWayContext context,
|
||||
@ColorInt int profileColor, @DrawableRes int profileIconRes) {
|
||||
this(context, profileColor, profileIconRes, false);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
|
@ -255,7 +271,7 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
|
|||
|
||||
@Override
|
||||
public Bitmap getPointBitmap() {
|
||||
return getContext().getProfileIconBitmap(profileKey, profileIconRes, borderColor);
|
||||
return getContext().getProfileIconBitmap(profileIconRes, borderColor);
|
||||
}
|
||||
|
||||
public void setIconLat(double lat) {
|
||||
|
|
|
@ -73,8 +73,8 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public Bitmap getProfileIconBitmap(String profileKey, @DrawableRes int iconRes, @ColorInt int color) {
|
||||
String key = profileKey + "_" + iconRes + "_" + color;
|
||||
public Bitmap getProfileIconBitmap(@DrawableRes int iconRes, @ColorInt int color) {
|
||||
String key = iconRes + "_" + color;
|
||||
Bitmap bitmap = profileIconsBitmapCache.get(key);
|
||||
if (bitmap == null) {
|
||||
bitmap = Bitmap.createBitmap((int) circleSize, (int) circleSize, Bitmap.Config.ARGB_8888);
|
||||
|
|
|
@ -34,12 +34,14 @@ public class MultiProfileGeometryWayDrawer extends GeometryWayDrawer<MultiProfil
|
|||
style = (GeometryMultiProfileWayStyle) styles.get(i);
|
||||
double lat = style.getIconLat();
|
||||
double lon = style.getIconLon();
|
||||
if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
|
||||
float x = tb.getPixXFromLatLon(lat, lon) - context.circleSize / 2;
|
||||
float y = tb.getPixYFromLatLon(lat, lon) - context.circleSize / 2;
|
||||
canvas.drawBitmap(style.getPointBitmap(), x, y, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawPathBorder(Canvas canvas, Path path, GeometryWayStyle<?> style) {
|
||||
if (style instanceof GeometryMultiProfileWayStyle) {
|
||||
|
|
Loading…
Reference in a new issue