use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class RouteProvider method createOsmandRouterGPX.
public GPXFile createOsmandRouterGPX(RouteCalculationResult route, OsmandApplication ctx, String name) {
TargetPointsHelper helper = ctx.getTargetPointsHelper();
List<WptPt> points = new ArrayList<>();
List<TargetPoint> ps = helper.getIntermediatePointsWithTarget();
for (int k = 0; k < ps.size(); k++) {
WptPt pt = new WptPt();
pt.lat = ps.get(k).getLatitude();
pt.lon = ps.get(k).getLongitude();
if (k < ps.size()) {
pt.name = ps.get(k).getOnlyName() + "";
if (k == ps.size() - 1) {
String target = ctx.getString(R.string.destination_point, "");
if (pt.name.startsWith(target)) {
pt.name = ctx.getString(R.string.destination_point, pt.name);
}
} else {
String prefix = (k + 1) + ". ";
if (Algorithms.isEmpty(pt.name)) {
pt.name = ctx.getString(R.string.target_point, pt.name);
}
if (pt.name.startsWith(prefix)) {
pt.name = prefix + pt.name;
}
}
pt.desc = pt.name;
}
points.add(pt);
}
List<Location> locations = route.getImmutableAllLocations();
List<RouteSegmentResult> originalRoute = route.getOriginalRoute();
RouteExporter exporter = new RouteExporter(name, originalRoute, locations, points);
return exporter.exportRoute();
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class RoutingOptionsHelper method updateGpxRoutingParameter.
public void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
GPXRouteParamsBuilder rp = app.getRoutingHelper().getCurrentGPXRoute();
final OsmandSettings settings = app.getSettings();
boolean selected = gpxParam.isSelected(settings);
if (rp != null) {
if (gpxParam.id == R.string.gpx_option_reverse_route) {
rp.setReverse(selected);
TargetPointsHelper tg = app.getTargetPointsHelper();
List<Location> ps = rp.getPoints(app);
if (ps.size() > 0) {
Location firstLoc = ps.get(0);
Location lastLoc = ps.get(ps.size() - 1);
TargetPoint pointToStart = tg.getPointToStart();
TargetPoint pointToNavigate = tg.getPointToNavigate();
if (rp.getFile().hasRoute()) {
LatLon firstLatLon = new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude());
LatLon endLocation = pointToStart != null ? pointToStart.point : new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude());
LatLon startLocation = pointToNavigate != null ? pointToNavigate.point : firstLatLon;
tg.navigateToPoint(endLocation, false, -1);
if (pointToStart != null) {
tg.setStartPoint(startLocation, false, null);
}
tg.updateRouteAndRefresh(true);
} else {
boolean update = false;
if (pointToNavigate == null || MapUtils.getDistance(pointToNavigate.point, new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude())) < 10) {
tg.navigateToPoint(new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude()), false, -1);
update = true;
}
if (pointToStart != null && MapUtils.getDistance(pointToStart.point, new LatLon(lastLoc.getLatitude(), lastLoc.getLongitude())) < 10) {
tg.setStartPoint(new LatLon(firstLoc.getLatitude(), firstLoc.getLongitude()), false, null);
update = true;
}
if (update) {
tg.updateRouteAndRefresh(true);
}
}
}
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
rp.setCalculateOsmAndRouteParts(selected);
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
} else if (gpxParam.id == R.string.gpx_option_from_start_point) {
rp.setPassWholeRoute(selected);
} else if (gpxParam.id == R.string.calculate_osmand_route_gpx) {
settings.GPX_ROUTE_CALC.set(selected);
rp.setCalculateOsmAndRoute(selected);
} else if (gpxParam.id == R.string.connect_track_points_as) {
rp.setConnectPointStraightly(selected);
}
}
if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
}
if (gpxParam.id == R.string.fast_route_mode) {
settings.FAST_ROUTE_MODE.set(selected);
}
if (gpxParam.id == R.string.speak_favorites) {
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
}
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class WaypointsFragment method applyPointsChanges.
private void applyPointsChanges() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
app.runInUIThread(new Runnable() {
@Override
public void run() {
OsmandApplication app = getMyApplication();
if (app == null || !isVisible()) {
return;
}
List<TargetPoint> allTargets = new ArrayList<>();
TargetPoint start = null;
List<Object> items = listAdapter.getActiveObjects();
if (items != null) {
for (Object obj : items) {
if (obj instanceof LocationPointWrapper) {
LocationPointWrapper p = (LocationPointWrapper) obj;
if (p.getPoint() instanceof TargetPoint) {
TargetPoint t = (TargetPoint) p.getPoint();
if (t.start) {
start = t;
} else {
t.intermediate = true;
}
allTargets.add(t);
}
}
}
if (allTargets.size() > 0) {
allTargets.get(allTargets.size() - 1).intermediate = false;
}
}
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
if (start != null) {
int startInd = allTargets.indexOf(start);
TargetPoint first = allTargets.remove(0);
if (startInd != 0) {
start.start = false;
start.intermediate = startInd != allTargets.size() - 1;
if (targetPointsHelper.getPointToStart() == null) {
start.getOriginalPointDescription().setName(PointDescription.getLocationNamePlain(getMyApplication(), start.getLatitude(), start.getLongitude()));
}
first.start = true;
first.intermediate = false;
targetPointsHelper.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, first.getPointDescription(getMyApplication()));
}
}
targetPointsHelper.reorderAllTargetPoints(allTargets, false);
newRouteIsCalculated(false, new ValueHolder<Boolean>());
targetPointsHelper.updateRouteAndRefresh(true);
}
}, 50);
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class PreviousRouteCard method updateContent.
@Override
protected void updateContent() {
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TextView startTitle = view.findViewById(R.id.start_title);
TextView destinationTitle = view.findViewById(R.id.destination_title);
TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
boolean myLocation = false;
if (startPoint == null) {
myLocation = true;
startPoint = targetPointsHelper.getMyLocationToStart();
}
StringBuilder startText = new StringBuilder(myLocation ? mapActivity.getText(R.string.my_location) : "");
if (startPoint != null) {
String descr = getPointName(app, startPoint);
if (!Algorithms.isEmpty(descr)) {
if (startText.length() > 0) {
startText.append(" — ");
}
startText.append(descr);
}
}
startTitle.setText(startText.toString());
TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
String destinationName = "";
destinationName = getPointName(app, destinationPoint);
destinationTitle.setText(destinationName);
View button = view.findViewById(R.id.card_button);
button.setOnClickListener(v -> notifyButtonPressed(0));
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class MapControlsLayer method addDestination.
public void addDestination(@NonNull LatLon latLon, @Nullable PointDescription pointDescription) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && !OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
requestedLatLon = latLon;
ActivityCompat.requestPermissions(mapActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION);
} else {
if (pointDescription == null) {
pointDescription = getPointDescriptionForTarget(latLon, null);
}
if (mapActivity != null) {
mapActivity.getContextMenu().close();
}
final TargetPointsHelper targets = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
targets.navigateToPoint(latLon, true, targets.getIntermediatePoints().size() + 1, pointDescription);
} else if (targets.getIntermediatePoints().isEmpty()) {
startRoutePlanningWithDestination(latLon, pointDescription, targets);
}
}
}
Aggregations