Fix dancing split interval

This commit is contained in:
Vitaliy 2020-07-31 12:00:46 +03:00
parent dd40c4dce6
commit 0f89e927e0

View file

@ -374,15 +374,14 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
int r = (int) (12 * tileBox.getDensity()); int r = (int) (12 * tileBox.getDensity());
paintTextIcon.setTextSize(r); paintTextIcon.setTextSize(r);
int dr = r * 3 / 2; int dr = r * 3 / 2;
int px = -1; float px = -1;
int py = -1; float py = -1;
for (int k = 0; k < items.size(); k++) { for (int k = 0; k < items.size(); k++) {
GpxDisplayItem i = items.get(k); GpxDisplayItem i = items.get(k);
WptPt o = i.locationEnd; WptPt point = i.locationEnd;
if (o != null && o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left if (point != null) {
&& o.lon <= latLonBounds.right) { float x = tileBox.getPixXFromLatLon(point.lat, point.lon);
int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon); float y = tileBox.getPixYFromLatLon(point.lat, point.lon);
int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
if (px != -1 || py != -1) { if (px != -1 || py != -1) {
if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) { if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) {
continue; continue;
@ -390,25 +389,29 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
px = x; px = x;
py = y; py = y;
String nm = i.splitName; if (point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top
if (nm != null) { && point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) {
int ind = nm.indexOf(' '); String name = i.splitName;
if (ind > 0) { if (name != null) {
nm = nm.substring(0, ind); int ind = name.indexOf(' ');
if (ind > 0) {
name = name.substring(0, ind);
}
Rect bounds = new Rect();
paintTextIcon.getTextBounds(name, 0, name.length(), bounds);
float nameHalfWidth = bounds.width() / 2f;
float nameHalfHeight = bounds.height() / 2f;
float density = (float) Math.ceil(tileBox.getDensity());
RectF rect = new RectF(x - nameHalfWidth - 2 * density,
y + nameHalfHeight + 3 * density,
x + nameHalfWidth + 3 * density,
y - nameHalfHeight - 2 * density);
canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
canvas.drawText(name, x, y + nameHalfHeight, paintTextIcon);
} }
Rect bounds = new Rect();
paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds);
int nmWidth = bounds.width();
int nmHeight = bounds.height();
RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
// canvas.drawRect(rect, paintInnerRect);
// canvas.drawRect(rect, paintOuterRect);
canvas.drawText(nm, x, y + nmHeight / 2, paintTextIcon);
} }
} }
} }
@ -1110,8 +1113,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
@Override @Override
public void applyNewObjectPosition(@NonNull Object o, public void applyNewObjectPosition(@NonNull Object o,
@NonNull LatLon position, @NonNull LatLon position,
@Nullable final ContextMenuLayer.ApplyMovedObjectCallback callback) { @Nullable final ContextMenuLayer.ApplyMovedObjectCallback callback) {
if (o instanceof WptPt) { if (o instanceof WptPt) {
final WptPt objectInMotion = (WptPt) o; final WptPt objectInMotion = (WptPt) o;
SelectedGpxFile selectedGpxFile = pointFileMap.get(objectInMotion); SelectedGpxFile selectedGpxFile = pointFileMap.get(objectInMotion);