From 118076b0c908d8e0f00b41bb6fc84cc1b0b45dc4 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 10 Jun 2012 21:47:24 +0200 Subject: [PATCH] Implement osmand offline routing --- .../net/osmand/binary/BinaryMapIndexReader.java | 4 ++++ .../net/osmand/router/BinaryRoutePlanner.java | 13 +++++++++++-- OsmAnd/src/net/osmand/plus/ResourceManager.java | 2 +- .../osmand/plus/activities/SettingsActivity.java | 4 ---- .../search/SearchBuildingByNameActivity.java | 11 +++++++++-- .../net/osmand/plus/routing/RouteProvider.java | 16 ++++++---------- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index ff2f93cfde..d0160e8705 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -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 && diff --git a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java index f70846a1c3..f413b3a67a 100644 --- a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java +++ b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java @@ -190,7 +190,12 @@ public class BinaryRoutePlanner { boolean inverse = false; boolean init = false; - PriorityQueue graphSegments = inverse ? graphReverseSegments : graphDirectSegments; + PriorityQueue 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; + } } diff --git a/OsmAnd/src/net/osmand/plus/ResourceManager.java b/OsmAnd/src/net/osmand/plus/ResourceManager.java index 1d23de4cc4..b71b2bef53 100644 --- a/OsmAnd/src/net/osmand/plus/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/ResourceManager.java @@ -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)); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index b3d042fb06..22b4bb8b5f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -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(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java index 8e657c096e..d75dae9e7f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java @@ -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 createComparator() { - return new MapObjectComparator(getMyApplication().getSettings().usingEnglishNames()); + return new Comparator() { + @Override + public int compare(Building o1, Building o2) { + int i1 = Algoritms.extractFirstIntegerNumber(o1.getName()); + int i2 = Algoritms.extractFirstIntegerNumber(o2.getName()); + return i1 - i2; + } + }; } @Override diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 44a2c4f6fa..9a5c2d58dd 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -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);