Added avoid route search radius
This commit is contained in:
parent
3bf85b824e
commit
f03bde7222
4 changed files with 17 additions and 12 deletions
|
@ -151,7 +151,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
startLocation.setTime(ms);
|
||||
}
|
||||
RouteSegmentSearchResult searchResult =
|
||||
RoutingHelper.searchRouteSegment(currentLocation.getLatitude(), currentLocation.getLongitude(), roads);
|
||||
RoutingHelper.searchRouteSegment(currentLocation.getLatitude(), currentLocation.getLongitude(), -1, roads);
|
||||
if (searchResult != null) {
|
||||
currentRoad = searchResult.getRoadIndex();
|
||||
currentSegment = searchResult.getSegmentIndex();
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.osmand.binary.RouteDataObject;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -44,6 +45,8 @@ import java.util.Map;
|
|||
|
||||
public class AvoidSpecificRoads {
|
||||
|
||||
private static final float MAX_AVOID_ROUTE_SEARCH_RADIUS_DP = 32f;
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
private Map<LatLon, RouteDataObject> impassableRoads = new LinkedHashMap<>();
|
||||
|
@ -210,7 +213,7 @@ public class AvoidSpecificRoads {
|
|||
});
|
||||
}
|
||||
|
||||
public void addImpassableRoad(@Nullable final MapActivity activity,
|
||||
public void addImpassableRoad(@Nullable final MapActivity mapActivity,
|
||||
@NonNull final LatLon loc,
|
||||
final boolean showDialog,
|
||||
final boolean skipWritingSettings) {
|
||||
|
@ -220,15 +223,17 @@ public class AvoidSpecificRoads {
|
|||
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
|
||||
|
||||
List<RouteSegmentResult> roads = app.getRoutingHelper().getRoute().getOriginalRoute();
|
||||
if (roads != null) {
|
||||
if (mapActivity != null && roads != null) {
|
||||
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
||||
float maxDistPx = MAX_AVOID_ROUTE_SEARCH_RADIUS_DP * tb.getDensity();
|
||||
RouteSegmentSearchResult searchResult =
|
||||
RoutingHelper.searchRouteSegment(loc.getLatitude(), loc.getLongitude(), roads);
|
||||
RoutingHelper.searchRouteSegment(loc.getLatitude(), loc.getLongitude(), maxDistPx / tb.getPixDensity(), roads);
|
||||
if (searchResult != null) {
|
||||
QuadPoint point = searchResult.getPoint();
|
||||
LatLon newLoc = new LatLon(MapUtils.get31LatitudeY((int) point.y), MapUtils.get31LongitudeX((int) point.x));
|
||||
ll.setLatitude(newLoc.getLatitude());
|
||||
ll.setLongitude(newLoc.getLongitude());
|
||||
addImpassableRoadInternal(roads.get(searchResult.getRoadIndex()).getObject(), ll, showDialog, activity, newLoc);
|
||||
addImpassableRoadInternal(roads.get(searchResult.getRoadIndex()).getObject(), ll, showDialog, mapActivity, newLoc);
|
||||
if (!skipWritingSettings) {
|
||||
app.getSettings().addImpassableRoad(newLoc.getLatitude(), newLoc.getLongitude());
|
||||
}
|
||||
|
@ -240,11 +245,11 @@ public class AvoidSpecificRoads {
|
|||
@Override
|
||||
public boolean publish(RouteDataObject object) {
|
||||
if (object == null) {
|
||||
if (activity != null) {
|
||||
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
||||
if (mapActivity != null) {
|
||||
Toast.makeText(mapActivity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
|
||||
addImpassableRoadInternal(object, ll, showDialog, mapActivity, loc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -319,7 +324,7 @@ public class AvoidSpecificRoads {
|
|||
showDialog(activity);
|
||||
}
|
||||
MapContextMenu menu = activity.getContextMenu();
|
||||
if (menu.isActive() && menu.getLatLon().equals(loc)) {
|
||||
if (menu.isActive()) {
|
||||
menu.close();
|
||||
}
|
||||
activity.refreshMap();
|
||||
|
|
|
@ -1251,13 +1251,13 @@ public class RoutingHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static RouteSegmentSearchResult searchRouteSegment(double latitude, double longitude, List<RouteSegmentResult> roads) {
|
||||
public static RouteSegmentSearchResult searchRouteSegment(double latitude, double longitude, double maxDist, List<RouteSegmentResult> roads) {
|
||||
int roadIndex = -1;
|
||||
int segmentIndex = -1;
|
||||
QuadPoint point = null;
|
||||
int px = MapUtils.get31TileNumberX(longitude);
|
||||
int py = MapUtils.get31TileNumberY(latitude);
|
||||
double dist = 1000;
|
||||
double dist = maxDist < 0 ? 1000 : maxDist;
|
||||
for (int i = 0; i < roads.size(); i++) {
|
||||
RouteSegmentResult road = roads.get(i);
|
||||
int startPointIndex = road.getStartPointIndex() < road.getEndPointIndex() ? road.getStartPointIndex() : road.getEndPointIndex();
|
||||
|
|
|
@ -947,9 +947,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
|
||||
if (selectOnMap != null) {
|
||||
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||
menu.init(latlon, null, null);
|
||||
CallbackWithObject<LatLon> cb = selectOnMap;
|
||||
cb.processResult(latlon);
|
||||
menu.init(latlon, null, null);
|
||||
selectOnMap = null;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue