Add dynamic street association

This commit is contained in:
Victor Shcherb 2013-01-13 16:46:18 +01:00
parent 0ba034d652
commit 6627691feb
5 changed files with 144 additions and 4 deletions

View file

@ -1108,7 +1108,6 @@ Memoria proporcional %4$s MB (Limite Android %5$s MB, Dalvik %6$s MB).</string>
<string name="recording_context_menu_precord">Hacer una foto</string> <string name="recording_context_menu_precord">Hacer una foto</string>
<string name="stop_routing_confirm">¿Seguro que quieres parar la navegación?</string> <string name="stop_routing_confirm">¿Seguro que quieres parar la navegación?</string>
<string name="clear_dest_confirm">¿Seguro que quieres borrar tu punto de destino?</string> <string name="clear_dest_confirm">¿Seguro que quieres borrar tu punto de destino?</string>
<string name="precise_routing_mode_descr"/>
<string name="precise_routing_mode_descr">Activa el enrutamiento preciso para calcular rutas precisas sin fallos. Está muy limitado por la distancia y no utiliza la biblioteca nativa.</string> <string name="precise_routing_mode_descr">Activa el enrutamiento preciso para calcular rutas precisas sin fallos. Está muy limitado por la distancia y no utiliza la biblioteca nativa.</string>
<string name="precise_routing_mode">Enrutado preciso (alfa)</string> <string name="precise_routing_mode">Enrutado preciso (alfa)</string>
</resources> </resources>

View file

@ -0,0 +1,118 @@
package net.osmand.plus;
import java.io.IOException;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.osm.MapUtils;
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.RoutePlannerFrontEnd;
import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingContext;
public class CurrentPositionHelper {
private RouteDataObject lastFound;
private Location lastAskedLocation = null;
private Thread calculatingThread = null;
private RoutingContext ctx;
private OsmandApplication app;
private ApplicationMode am;
public CurrentPositionHelper(OsmandApplication app) {
this.app = app;
}
private void initCtx(OsmandApplication app) {
ResourceManager r = app.getResourceManager();
am = app.getSettings().getApplicationMode();
GeneralRouterProfile p ;
if (am == ApplicationMode.BICYCLE) {
p = GeneralRouterProfile.BICYCLE;
} else if (am == ApplicationMode.PEDESTRIAN) {
p = GeneralRouterProfile.PEDESTRIAN;
} else {
p = GeneralRouterProfile.CAR;
}
RoutingConfiguration cfg = RoutingConfiguration.getDefault().build(p.name().toLowerCase(), 10);
ctx = new RoutingContext(cfg, null, r.getRoutingMapFiles());
}
private RouteDataObject runUpdateInThread(Location loc) {
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
try {
if(ctx == null || am != app.getSettings().getApplicationMode()) {
initCtx(app);
}
RouteSegment sg = rp.findRouteSegment(loc.getLatitude(), loc.getLongitude(), ctx);
return sg.getRoad();
} catch (IOException e) {
return null;
}
}
private void scheduleRouteSegmentFind(final Location loc){
if(calculatingThread == Thread.currentThread()) {
lastFound = runUpdateInThread(loc);
} else if(calculatingThread == null && loc != null) {
calculatingThread = new Thread(new Runnable() {
@Override
public void run() {
try {
lastFound = runUpdateInThread(loc);
if (lastAskedLocation != loc) {
// refresh and run new task if needed
getLastKnownRouteSegment(lastAskedLocation);
}
} finally {
calculatingThread = null;
}
}
});
calculatingThread.start();
}
}
private static double getOrthogonalDistance(RouteDataObject r, Location loc){
double d = 1000;
if (r.getPointsLength() > 0) {
double pLt = MapUtils.get31LatitudeY(r.getPoint31YTile(0));
double pLn = MapUtils.get31LongitudeX(r.getPoint31XTile(0));
for (int i = 1; i < r.getPointsLength(); i++) {
double lt = MapUtils.get31LatitudeY(r.getPoint31YTile(i));
double ln = MapUtils.get31LongitudeX(r.getPoint31XTile(i));
double od = MapUtils.getOrthogonalDistance(loc.getLatitude(), loc.getLongitude(), pLt, pLn, lt, ln);
if (od < d) {
d = od;
}
pLt = lt;
pLn = ln;
}
}
return d;
}
public RouteDataObject getLastKnownRouteSegment(Location loc) {
lastAskedLocation = loc;
RouteDataObject r = lastFound;
if (loc == null || loc.getAccuracy() > 50) {
return null;
}
if (r == null) {
scheduleRouteSegmentFind(loc);
return null;
}
double d = getOrthogonalDistance(r, loc);
if (d > 25) {
scheduleRouteSegmentFind(loc);
}
if (d < 70) {
return r;
}
return null;
}
}

View file

@ -14,6 +14,7 @@ import net.osmand.access.AccessibleActivity;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.access.NavigationInfo; import net.osmand.access.NavigationInfo;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.DownloadRequest;
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.map.IMapLocationListener; import net.osmand.map.IMapLocationListener;
@ -24,6 +25,7 @@ import net.osmand.plus.BusyIndicator;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.CurrentPositionHelper;
import net.osmand.plus.MapScreen; import net.osmand.plus.MapScreen;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -119,6 +121,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
private OsmandMapTileView mapView; private OsmandMapTileView mapView;
private MapActivityActions mapActions; private MapActivityActions mapActions;
private MapActivityLayers mapLayers; private MapActivityLayers mapLayers;
private CurrentPositionHelper currentPositionHelper;
private NavigationInfo navigationInfo; private NavigationInfo navigationInfo;
private SavingTrackHelper savingTrackHelper; private SavingTrackHelper savingTrackHelper;
@ -167,6 +170,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
settings = getMyApplication().getSettings(); settings = getMyApplication().getSettings();
mapActions = new MapActivityActions(this); mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this); mapLayers = new MapActivityLayers(this);
currentPositionHelper = new CurrentPositionHelper(getMyApplication());
navigationInfo = new NavigationInfo(this); navigationInfo = new NavigationInfo(this);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
// Full screen is not used here // Full screen is not used here
@ -1044,6 +1048,10 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
return mapLayers.getLocationLayer().getLastKnownLocation(); return mapLayers.getLocationLayer().getLastKnownLocation();
} }
public RouteDataObject getLastRouteDataObject(){
return currentPositionHelper.getLastKnownRouteSegment(getLastKnownLocation());
}
public LatLon getMapLocation(){ public LatLon getMapLocation(){
return new LatLon(mapView.getLatitude(), mapView.getLongitude()); return new LatLon(mapView.getLatitude(), mapView.getLongitude());
} }
@ -1438,7 +1446,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
} }
private boolean isMapLinkedToLocation(){ public boolean isMapLinkedToLocation(){
return isMapLinkedToLocation; return isMapLinkedToLocation;
} }

View file

@ -11,6 +11,7 @@ import java.util.Set;
import net.osmand.Algoritms; import net.osmand.Algoritms;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.binary.RouteDataObject;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -902,9 +903,14 @@ public class MapInfoLayer extends OsmandMapLayer {
int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo(); int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo();
if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) { if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) {
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
text = routingHelper.formatStreetName(next.getStreetName(), next.getRef()); text = RoutingHelper.formatStreetName(next.getStreetName(), next.getRef());
} }
} }
} else if(map.isMapLinkedToLocation()) {
RouteDataObject rt = map.getLastRouteDataObject();
if(rt != null) {
text = RoutingHelper.formatStreetName(rt.getName(), rt.getRef());
}
} }
if(text == null) { if(text == null) {
text = ""; text = "";

View file

@ -6,6 +6,7 @@ import java.util.Arrays;
import net.osmand.Algoritms; import net.osmand.Algoritms;
import net.osmand.GeoidAltitudeCorrection; import net.osmand.GeoidAltitudeCorrection;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.osm.LatLon; import net.osmand.osm.LatLon;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -316,7 +317,15 @@ public class RouteInfoControls {
@Override @Override
public boolean updateInfo() { public boolean updateInfo() {
float mx = rh == null ? 0 : rh.getCurrentMaxSpeed(); float mx = 0;
if ((rh == null || !rh.isFollowingMode()) && map.isMapLinkedToLocation()) {
RouteDataObject ro = map.getLastRouteDataObject();
if(ro != null) {
mx = ro.getMaximumSpeed();
}
} else {
mx = rh.getCurrentMaxSpeed();
}
if (cachedSpeed != mx) { if (cachedSpeed != mx) {
cachedSpeed = mx; cachedSpeed = mx;
if (cachedSpeed == 0) { if (cachedSpeed == 0) {