Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
88c882d47d
2 changed files with 43 additions and 10 deletions
|
@ -5,9 +5,11 @@ import android.graphics.BitmapFactory;
|
|||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PathMeasure;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -19,6 +21,7 @@ import net.osmand.data.QuadPoint;
|
|||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
|
@ -27,6 +30,7 @@ import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
|
|||
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
|
||||
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
|
||||
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -37,6 +41,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
|
||||
|
||||
protected static final int DIST_TO_SHOW = 80;
|
||||
private static final int TEXT_SIZE = 14;
|
||||
private static final int VERTICAL_OFFSET = 10;
|
||||
|
||||
private final MapActivity map;
|
||||
private OsmandMapTileView view;
|
||||
|
@ -63,6 +69,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
private float[] calculations = new float[2];
|
||||
|
||||
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
|
||||
private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerCircle");
|
||||
private Paint paint;
|
||||
private Path path;
|
||||
private List<LatLon> route = new ArrayList<>();
|
||||
|
@ -113,6 +120,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
paint.setColor(ContextCompat.getColor(map, R.color.marker_red));
|
||||
paint.setAlpha(200);
|
||||
|
||||
float textSize = TEXT_SIZE * map.getResources().getDisplayMetrics().density;
|
||||
textAttrs.paint2.setTextSize(textSize);
|
||||
textAttrs.paint3.setTextSize(textSize);
|
||||
|
||||
widgetsFactory = new MapMarkersWidgetsFactory(map);
|
||||
|
||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
|
@ -199,8 +210,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
return;
|
||||
}
|
||||
|
||||
lineAttrs.updatePaints(view, nightMode, tileBox);
|
||||
|
||||
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
|
||||
if (route.size() > 0) {
|
||||
path.reset();
|
||||
|
@ -228,6 +237,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
|
||||
|
||||
if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) {
|
||||
lineAttrs.updatePaints(view, nightMode, tileBox);
|
||||
textAttrs.updatePaints(view, nightMode, tileBox);
|
||||
textAttrs.paint2.setStyle(Paint.Style.FILL);
|
||||
|
||||
int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude());
|
||||
int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude());
|
||||
int[] colors = MapMarker.getColors(map);
|
||||
|
@ -235,6 +248,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
MapMarker marker = activeMapMarkers.get(i);
|
||||
int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude());
|
||||
int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude());
|
||||
|
||||
linePath.reset();
|
||||
tx.clear();
|
||||
ty.clear();
|
||||
|
@ -244,9 +258,29 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
ty.add(locY);
|
||||
tx.add(markerX);
|
||||
ty.add(markerY);
|
||||
|
||||
calculatePath(tileBox, tx, ty, linePath);
|
||||
PathMeasure pm = new PathMeasure(linePath, false);
|
||||
|
||||
float dist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude());
|
||||
String text = OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
|
||||
Rect bounds = new Rect();
|
||||
textAttrs.paint2.getTextBounds(text, 0, text.length(), bounds);
|
||||
float hOffset = pm.getLength() / 2 - bounds.width() / 2;
|
||||
|
||||
lineAttrs.paint.setColor(colors[marker.colorIndex]);
|
||||
canvas.drawPath(linePath, lineAttrs.paint);
|
||||
if (locX - markerX >= 0) {
|
||||
float[] pos = new float[2];
|
||||
pm.getPosTan(pm.getLength() / 2, pos, null);
|
||||
canvas.rotate(180, pos[0], pos[1]);
|
||||
canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3);
|
||||
canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2);
|
||||
canvas.rotate(-180, pos[0], pos[1]);
|
||||
} else {
|
||||
canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3);
|
||||
canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,8 +139,8 @@ public abstract class OsmandMapLayer {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
|
||||
path.reset();
|
||||
boolean start = false;
|
||||
int px = xs.get(0);
|
||||
int py = ys.get(0);
|
||||
|
@ -156,8 +156,7 @@ public abstract class OsmandMapLayer {
|
|||
if (pin && in) {
|
||||
draw = true;
|
||||
} else {
|
||||
long intersection = MapAlgorithms.calculateIntersection(x, y,
|
||||
px, py, 0, w, h, 0);
|
||||
long intersection = MapAlgorithms.calculateIntersection(x, y, px, py, 0, w, h, 0);
|
||||
if (intersection != -1) {
|
||||
if (pin && (i == 1)) {
|
||||
cnt++;
|
||||
|
|
Loading…
Reference in a new issue