Fix analyze on map

This commit is contained in:
Vitaliy 2020-06-16 15:51:30 +03:00
parent d8fddfbac9
commit c1e9a74fc5
3 changed files with 23 additions and 30 deletions

View file

@ -29,6 +29,7 @@ public class PointDescription {
public static final String POINT_TYPE_FAVORITE = "favorite"; public static final String POINT_TYPE_FAVORITE = "favorite";
public static final String POINT_TYPE_WPT = "wpt"; public static final String POINT_TYPE_WPT = "wpt";
public static final String POINT_TYPE_GPX = "gpx";
public static final String POINT_TYPE_RTE = "rte"; public static final String POINT_TYPE_RTE = "rte";
public static final String POINT_TYPE_POI = "poi"; public static final String POINT_TYPE_POI = "poi";
public static final String POINT_TYPE_ADDRESS = "address"; public static final String POINT_TYPE_ADDRESS = "address";

View file

@ -122,14 +122,16 @@ public class SelectedGpxMenuController extends MenuController {
gpxItem.chartTypes = list.toArray(new GpxUiHelper.GPXDataSetType[list.size()]); gpxItem.chartTypes = list.toArray(new GpxUiHelper.GPXDataSetType[list.size()]);
} }
OsmandApplication app = getMapActivity().getMyApplication(); MapActivity mapActivity = getMapActivity();
OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(gpxItem.locationStart.lat, gpxItem.locationStart.lon, settings.setMapLocationToShow(gpxItem.locationStart.lat, gpxItem.locationStart.lon,
settings.getLastKnownMapZoom(), settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name),
false, false,
gpxItem); gpxItem);
MapActivity.launchMapActivityMoveToTop(getMapActivity()); mapActivity.getContextMenu().hide();
MapActivity.launchMapActivityMoveToTop(mapActivity);
} }
} }
} }

View file

@ -28,7 +28,6 @@ import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -48,14 +47,14 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;
import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IMoveObjectProvider;
import net.osmand.plus.views.MapTextLayer.MapTextProvider; import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -66,10 +65,10 @@ import java.util.Map;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider, MapTextProvider<WptPt> {
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; private static final double TOUCH_RADIUS_MULTIPLIER = 1.5;
private static final int START_ZOOM = 7;
private OsmandMapTileView view; private OsmandMapTileView view;
@ -89,9 +88,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private LayerDrawable selectedPoint; private LayerDrawable selectedPoint;
private TrackChartPoints trackChartPoints; private TrackChartPoints trackChartPoints;
private static final int startZoom = 7;
private GpxSelectionHelper selectedGpxHelper; private GpxSelectionHelper selectedGpxHelper;
private MapMarkersHelper mapMarkersHelper; private MapMarkersHelper mapMarkersHelper;
private Paint paintBmp; private Paint paintBmp;
@ -109,8 +105,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private OsmandRenderer osmandRenderer; private OsmandRenderer osmandRenderer;
private GPXFile gpx;
private ContextMenuLayer contextMenuLayer; private ContextMenuLayer contextMenuLayer;
@ColorInt @ColorInt
private int visitedColor; private int visitedColor;
@ -296,7 +290,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles, private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) { DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) { if (tileBox.getZoom() >= START_ZOOM) {
// request to load // request to load
for (SelectedGpxFile g : selectedGPXFiles) { for (SelectedGpxFile g : selectedGPXFiles) {
List<GpxDisplayGroup> groups = g.getDisplayGroups(view.getApplication()); List<GpxDisplayGroup> groups = g.getDisplayGroups(view.getApplication());
@ -377,7 +371,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
} }
private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) { private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (tileBox.getZoom() >= startZoom) { if (tileBox.getZoom() >= START_ZOOM) {
float textScale = view.getSettings().TEXT_SCALE.get(); float textScale = view.getSettings().TEXT_SCALE.get();
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0, float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
true, (WptPt) null).getIntrinsicWidth() * 3 / 2.5f * textScale; true, (WptPt) null).getIntrinsicWidth() * 3 / 2.5f * textScale;
@ -582,7 +576,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return (Math.abs(objx - ex) <= radius && Math.abs(objy - ey) <= radius); return (Math.abs(objx - ex) <= radius && Math.abs(objy - ey) <= radius);
} }
public void getWptFromPoint(RotatedTileBox tb, PointF point, List<? super WptPt> res) { public void getWptFromPoint(RotatedTileBox tb, PointF point, List<? super WptPt> res) {
@ -603,27 +596,24 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
} }
} }
private static final Log log = PlatformUtil.getLog(GPXLayer.class); public void getTracksFromPoint(RotatedTileBox tb, PointF point, List<Object> res) {
public void getWptFromPoint2(RotatedTileBox tb, PointF point, List<Object> res) {
int r = getScaledTouchRadius(view.getApplication(), getDefaultRadiusPoi(tb)); int r = getScaledTouchRadius(view.getApplication(), getDefaultRadiusPoi(tb));
int mx = (int) point.x; int mx = (int) point.x;
int my = (int) point.y; int my = (int) point.y;
List<SelectedGpxFile> selectedGpxFiles = new ArrayList<>(selectedGpxHelper.getSelectedGPXFiles()); List<SelectedGpxFile> selectedGpxFiles = new ArrayList<>(selectedGpxHelper.getSelectedGPXFiles());
for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) {
boolean track = false;
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay(); List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
for (TrkSegment segment : segments) { for (TrkSegment segment : segments) {
track |= track(tb, segment.points, (int) r, mx, my); boolean nearSegment = isPointNearSegment(tb, segment.points, r, mx, my);
} if (nearSegment) {
if (track) {
res.add(selectedGpxFile); res.add(selectedGpxFile);
break;
}
} }
log.debug("found " + track);
} }
} }
private boolean track(RotatedTileBox tb, List<WptPt> points, int r, int mx, int my) { private boolean isPointNearSegment(RotatedTileBox tb, List<WptPt> points, int r, int mx, int my) {
WptPt firstPoint = points.get(0); WptPt firstPoint = points.get(0);
int ppx = (int) tb.getPixXFromLatLon(firstPoint.lat, firstPoint.lon); int ppx = (int) tb.getPixXFromLatLon(firstPoint.lat, firstPoint.lon);
int ppy = (int) tb.getPixYFromLatLon(firstPoint.lat, firstPoint.lon); int ppy = (int) tb.getPixYFromLatLon(firstPoint.lat, firstPoint.lon);
@ -681,11 +671,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@Override @Override
public PointDescription getObjectName(Object o) { public PointDescription getObjectName(Object o) {
if (o instanceof WptPt) { if (o instanceof WptPt) {
return new PointDescription(PointDescription.POINT_TYPE_WPT, ((WptPt) o).name); //$NON-NLS-1$ return new PointDescription(PointDescription.POINT_TYPE_WPT, ((WptPt) o).name);
} else if (o instanceof SelectedGpxFile) { } else if (o instanceof SelectedGpxFile) {
SelectedGpxFile selectedGpxFile = (SelectedGpxFile) o; SelectedGpxFile selectedGpxFile = (SelectedGpxFile) o;
String name = formatName(Algorithms.getFileWithoutDirs(selectedGpxFile.getGpxFile().path)); String name = formatName(Algorithms.getFileWithoutDirs(selectedGpxFile.getGpxFile().path));
return new PointDescription(PointDescription.POINT_TYPE_WPT, name); return new PointDescription(PointDescription.POINT_TYPE_GPX, name);
} }
return null; return null;
} }
@ -720,9 +710,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@Override @Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) { public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) { if (tileBox.getZoom() >= START_ZOOM) {
getWptFromPoint(tileBox, point, res); getWptFromPoint(tileBox, point, res);
getWptFromPoint2(tileBox, point, res); getTracksFromPoint(tileBox, point, res);
} }
} }