use of net.osmand.Location in project Osmand by osmandapp.
the class RouteProvider method findStartAndEndLocationsFromRoute.
private ArrayList<Location> findStartAndEndLocationsFromRoute(List<Location> route, Location startLoc, LatLon endLoc, int[] startI, int[] endI) {
float minDist = Integer.MAX_VALUE;
int start = 0;
int end = route.size();
if (startLoc != null) {
for (int i = 0; i < route.size(); i++) {
float d = route.get(i).distanceTo(startLoc);
if (d < minDist) {
start = i;
minDist = d;
}
}
} else {
startLoc = route.get(0);
}
// $NON-NLS-1$
Location l = new Location("temp");
l.setLatitude(endLoc.getLatitude());
l.setLongitude(endLoc.getLongitude());
minDist = Integer.MAX_VALUE;
// get in reverse order taking into account ways with cycle
for (int i = route.size() - 1; i >= start; i--) {
float d = route.get(i).distanceTo(l);
if (d < minDist) {
end = i + 1;
// slightly modify to allow last point to be added
minDist = d - 40;
}
}
ArrayList<Location> sublist = new ArrayList<Location>(route.subList(start, end));
if (startI != null) {
startI[0] = start;
}
if (endI != null) {
endI[0] = end;
}
return sublist;
}
use of net.osmand.Location in project Osmand by osmandapp.
the class ImpassableRoadsLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
for (long id : getImpassableRoadLocations().keySet()) {
if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
RouteDataObject object = (RouteDataObject) contextMenuLayer.getMoveableObject();
if (object.id == id) {
continue;
}
}
Location location = getImpassableRoadLocations().get(id);
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
if (tileBox.containsLatLon(latitude, longitude)) {
drawPoint(canvas, tileBox, latitude, longitude);
}
}
for (StoredRoadDataObject storedRoadDataObject : storedRoadDataObjects) {
final LatLon latLon = storedRoadDataObject.getLatLon();
if (tileBox.containsLatLon(latLon)) {
drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
}
}
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class BinaryMapIndexReader method testSearchOnthePath.
private static void testSearchOnthePath(BinaryMapIndexReader reader) throws IOException {
float radius = 1000;
final MapPoiTypes poiTypes = MapPoiTypes.getDefault();
long now = System.currentTimeMillis();
println("Searching poi on the path...");
final List<Location> locations = readGPX(new File("/Users/victorshcherb/osmand/maps/2015-03-07_19-07_Sat.gpx"));
SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
if (type == poiTypes.getPoiCategoryByName("shop") && subcategory.contains("super")) {
return true;
}
return false;
}
@Override
public boolean isEmpty() {
return false;
}
}, null);
req.zoom = -1;
List<Amenity> results = reader.searchPoi(req);
int k = 0;
println("Search done in " + (System.currentTimeMillis() - now) + " ms ");
now = System.currentTimeMillis();
for (Amenity a : results) {
final float dds = dist(a.getLocation(), locations);
if (dds <= radius) {
println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float) a.getRoutePoint().deviateDistance + ") " + a.getName() + " " + a.getLocation());
k++;
} else {
println(a.getType() + " " + a.getSubType() + " Dist " + dds + " " + a.getName() + " " + a.getLocation());
}
}
println("Filtered in " + (System.currentTimeMillis() - now) + "ms " + k + " of " + results.size());
}
use of net.osmand.Location in project Osmand by osmandapp.
the class MapActivityActions method setGPXRouteParams.
public void setGPXRouteParams(GPXFile result) {
if (result == null) {
mapActivity.getRoutingHelper().setGpxParams(null);
settings.FOLLOW_THE_GPX_ROUTE.set(null);
} else {
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication().getSettings());
if (result.hasRtePt() && !result.hasTrkPt()) {
settings.GPX_CALCULATE_RTEPT.set(true);
} else {
settings.GPX_CALCULATE_RTEPT.set(false);
}
params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get());
params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
List<Location> ps = params.getPoints();
mapActivity.getRoutingHelper().setGpxParams(params);
settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
if (!ps.isEmpty()) {
Location startLoc = ps.get(0);
Location finishLoc = ps.get(ps.size() - 1);
TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper();
tg.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()), false, -1);
if (startLoc != finishLoc) {
tg.setStartPoint(new LatLon(startLoc.getLatitude(), startLoc.getLongitude()), false, null);
} else {
tg.clearStartPoint(false);
}
}
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class MapActivity method newRouteIsCalculated.
@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
RoutingHelper rh = app.getRoutingHelper();
if (newRoute && rh.isRoutePlanningMode() && mapView != null) {
Location lt = rh.getLastProjection();
if (lt == null) {
lt = app.getTargetPointsHelper().getPointToStartLocation();
}
if (lt != null) {
double left = lt.getLongitude(), right = lt.getLongitude();
double top = lt.getLatitude(), bottom = lt.getLatitude();
List<Location> list = rh.getCurrentCalculatedRoute();
for (Location l : list) {
left = Math.min(left, l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
for (TargetPoint l : targetPoints) {
left = Math.min(left, l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
MapRouteInfoMenu routeInfoMenu = mapLayers.getMapControlsLayer().getMapRouteInfoMenu();
WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
if (fragmentRef != null) {
MapRouteInfoMenuFragment f = fragmentRef.get();
if (landscapeLayout) {
tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
} else {
tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
}
}
mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
}
}
}
Aggregations