Implement osmand offline routing

This commit is contained in:
Victor Shcherb 2012-06-10 21:47:24 +02:00
parent 61670cc67c
commit 118076b0c9
6 changed files with 31 additions and 19 deletions

View file

@ -262,6 +262,10 @@ public class BinaryMapIndexReader {
return poiIndexes.size() > 0;
}
public boolean containsRouteData(){
return routingIndexes.size() > 0;
}
public boolean containsPoiData(double latitude, double longitude) {
for (PoiRegion index : poiIndexes) {
if (index.rightLongitude >= longitude && index.leftLongitude <= longitude &&

View file

@ -190,7 +190,12 @@ public class BinaryRoutePlanner {
boolean inverse = false;
boolean init = false;
PriorityQueue<RouteSegment> graphSegments = inverse ? graphReverseSegments : graphDirectSegments;
PriorityQueue<RouteSegment> graphSegments;
if(inverse) {
graphSegments = graphReverseSegments;
} else {
graphSegments = graphDirectSegments;
}
while (!graphSegments.isEmpty()) {
RouteSegment segment = graphSegments.poll();
@ -224,7 +229,11 @@ public class BinaryRoutePlanner {
// different strategy : use onedirectional graph
inverse = !ctx.getPlanRoadDirection().booleanValue();
}
graphSegments = inverse ? graphReverseSegments : graphDirectSegments;
if(inverse) {
graphSegments = graphReverseSegments;
} else {
graphSegments = graphDirectSegments;
}
}

View file

@ -553,7 +553,7 @@ public class ResourceManager {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
}
}
if(index.containsMapData()){
if(index.containsRouteData()) {
try {
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
routingMapFiles.put(f.getAbsolutePath(), new BinaryMapIndexReader(raf, index));

View file

@ -511,10 +511,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
getMyApplication().showDialogInitializingCommandPlayer(this, false);
}
} else if (listPref.getId().equals(osmandSettings.ROUTER_SERVICE.getId())) {
// TO Delete when it will be available
if (osmandSettings.ROUTER_SERVICE.get() == RouteService.OSMAND) {
AccessibleToast.makeText(this, R.string.offline_navigation_not_available, Toast.LENGTH_LONG).show();
}
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " [" + osmandSettings.ROUTER_SERVICE.get() + "]");
} else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
updateAllSettings();

View file

@ -3,10 +3,10 @@ package net.osmand.plus.activities.search;
import java.util.Comparator;
import java.util.List;
import net.osmand.Algoritms;
import net.osmand.ResultMatcher;
import net.osmand.data.Building;
import net.osmand.data.City;
import net.osmand.data.MapObjectComparator;
import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -22,7 +22,14 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
@Override
protected Comparator<? super Building> createComparator() {
return new MapObjectComparator(getMyApplication().getSettings().usingEnglishNames());
return new Comparator<Building>() {
@Override
public int compare(Building o1, Building o2) {
int i1 = Algoritms.extractFirstIntegerNumber(o1.getName());
int i2 = Algoritms.extractFirstIntegerNumber(o2.getName());
return i1 - i2;
}
};
}
@Override

View file

@ -25,7 +25,6 @@ import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.LogUtil;
import net.osmand.OsmAndFormatter;
import net.osmand.access.AccessibleToast;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
@ -52,7 +51,6 @@ import org.xml.sax.SAXException;
import android.content.Context;
import android.location.Location;
import android.widget.Toast;
public class RouteProvider {
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RouteProvider.class);
@ -271,13 +269,10 @@ public class RouteProvider {
} else if (type == RouteService.ORS) {
res = findORSRoute(start, end, mode, fast);
addMissingTurnsToRoute(res, start, end, mode, ctx, leftSide);
// } else if (type == RouteService.OSMAND) {
// res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
// addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.OSMAND) {
res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
addMissingTurnsToRoute(res, start, end, mode, ctx, leftSide);
} else {
if (type == RouteService.OSMAND) {
AccessibleToast.makeText(ctx, R.string.offline_navigation_not_available, Toast.LENGTH_LONG).show();
}
res = findCloudMadeRoute(start, end, mode, ctx, fast, leftSide);
// for test purpose
addMissingTurnsToRoute(res, start, end, mode, ctx, leftSide);
@ -618,10 +613,11 @@ public class RouteProvider {
BinaryRoutePlanner router = new BinaryRoutePlanner(files);
RoutingContext ctx = new RoutingContext();
ctx.setUsingShortestWay(!fast);
if(mode == ApplicationMode.BICYCLE){
//ctx.setPlanRoadDirection(null);
if (mode == ApplicationMode.BICYCLE) {
ctx.setRouter(new BicycleRouter());
ctx.setUseDynamicRoadPrioritising(true);
} else if(mode == ApplicationMode.PEDESTRIAN){
} else if (mode == ApplicationMode.PEDESTRIAN) {
ctx.setRouter(new PedestrianRouter());
ctx.setUseDynamicRoadPrioritising(false);
ctx.setHeuristicCoefficient(2);