Merge pull request #10444 from osmandapp/Select-on-Map

Select on Map in Route Preparation
This commit is contained in:
Vitaliy 2020-12-20 23:00:44 +02:00 committed by GitHub
commit d41bee29fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,13 +51,8 @@ import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.GeocodingLookupService.OnAddressLookupResult;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.routing.RoutingHelperUtils;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -71,6 +66,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
@ -102,9 +98,16 @@ import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelperUtils;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.search.QuickSearchHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.widgets.TextViewExProgress;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
@ -282,7 +285,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (selectFromMapTouch) {
selectFromMapTouch = false;
LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y);
choosePointTypeAction(mapActivity, latLon, selectFromMapPointType, null, null);
LatLon objectLatLon = getObjectLocation(mapActivity.getMapView(), point, tileBox);
LatLon selectedPoint = objectLatLon != null ? objectLatLon : latLon;
choosePointTypeAction(mapActivity, selectedPoint, selectFromMapPointType, null, null);
if (selectFromMapWaypoints) {
WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager(), true);
} else {
@ -294,6 +299,24 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
return false;
}
private LatLon getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) {
LatLon latLon = null;
List<Object> objects = new ArrayList<>();
for (OsmandMapLayer layer : mapView.getLayers()) {
if (layer instanceof IContextMenuProvider) {
objects.clear();
IContextMenuProvider provider = (IContextMenuProvider) layer;
provider.collectObjectsFromPoint(point, tileBox, objects, true);
for (Object o : objects) {
if (provider.isObjectClickable(o)) {
latLon = provider.getObjectLocation(o);
}
}
}
}
return latLon;
}
private void choosePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) {
OsmandApplication app = getApp();
FavouritesDbHelper favorites = app.getFavorites();