From 42e9e10fa80297b3d0b9e618edcd874eae66a51d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 27 Aug 2012 00:16:06 +0200 Subject: [PATCH] Fix routing issue --- .../osmand/binary/BinaryMapIndexReader.java | 5 ++ .../binary/BinaryMapRouteReaderAdapter.java | 77 +++++++++++++------ .../src/net/osmand/router/RoutingContext.java | 5 ++ .../plus/activities/MapActivityActions.java | 3 + 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index 10e89bd2ae..caf5822a42 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1958,6 +1958,10 @@ public class BinaryMapIndexReader { } })); } + + public void initRouteRegionsIfNeeded(SearchRequest req) throws IOException { + routeAdapter.initRouteTypesIfNeeded(req); + } public void searchRouteIndex(SearchRequest req, List list) throws IOException { req.numberOfVisitedObjects = 0; @@ -1965,6 +1969,7 @@ public class BinaryMapIndexReader { req.numberOfAcceptedSubtrees = 0; req.numberOfReadSubtrees = 0; if(routeAdapter != null){ + initRouteRegionsIfNeeded(req); routeAdapter.searchRouteRegion(req, list); } } diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index fbd6ebdabd..ecc634202f 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -154,10 +154,6 @@ public class BinaryMapRouteReaderAdapter { } public static class RouteRegion extends BinaryIndexPart { - double leftLongitude; - double rightLongitude; - double topLatitude; - double bottomLatitude; int regionsRead; List subregions = new ArrayList(); @@ -165,22 +161,6 @@ public class BinaryMapRouteReaderAdapter { int nameTypeRule = -1; int refTypeRule = -1; - public double getLeftLongitude() { - return leftLongitude; - } - - public double getRightLongitude() { - return rightLongitude; - } - - public double getTopLatitude() { - return topLatitude; - } - - public double getBottomLatitude() { - return bottomLatitude; - } - public RouteTypeRule quickGetEncodingRule(int id) { return routeEncodingRules.get(id); } @@ -200,6 +180,38 @@ public class BinaryMapRouteReaderAdapter { public List getSubregions(){ return subregions; } + + public double getLeftLongitude() { + double l = 180; + for(RouteSubregion s : subregions) { + l = Math.min(l, MapUtils.get31LongitudeX(s.left)); + } + return l; + } + + public double getRightLongitude() { + double l = -180; + for(RouteSubregion s : subregions) { + l = Math.max(l, MapUtils.get31LongitudeX(s.right)); + } + return l; + } + + public double getBottomLatitude() { + double l = 90; + for(RouteSubregion s : subregions) { + l = Math.min(l, MapUtils.get31LatitudeY(s.bottom)); + } + return l; + } + + public double getTopLatitude() { + double l = -90; + for(RouteSubregion s : subregions) { + l = Math.max(l, MapUtils.get31LatitudeY(s.top)); + } + return l; + } } public static class RouteSubregion { @@ -285,10 +297,6 @@ public class BinaryMapRouteReaderAdapter { codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.popLimit(oldLimit); - region.bottomLatitude = MapUtils.get31LatitudeY(subregion.bottom); - region.topLatitude = MapUtils.get31LatitudeY(subregion.top); - region.rightLongitude = MapUtils.get31LongitudeX(subregion.right); - region.leftLongitude = MapUtils.get31LongitudeX(subregion.left); // Finish reading file! codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); } break; @@ -591,6 +599,27 @@ public class BinaryMapRouteReaderAdapter { } } + public void initRouteTypesIfNeeded(SearchRequest req) throws IOException{ + for(RouteRegion r: map.getRoutingIndexes() ) { + if (r.routeEncodingRules.isEmpty()) { + boolean intersect = false; + for (RouteSubregion rs : r.subregions) { + if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) { + intersect = true; + break; + } + } + if(intersect) { + codedIS.seek(r.filePointer); + int oldLimit = codedIS.pushLimit(r.length); + readRouteIndex(r); + codedIS.popLimit(oldLimit); + } + } + } + + } + public void searchRouteRegion(SearchRequest req, List list) throws IOException { List toLoad = new ArrayList(); searchRouteRegion(req, list, toLoad); diff --git a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java index 00e21e907c..9c988d98f4 100644 --- a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java +++ b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java @@ -259,6 +259,11 @@ public class RoutingContext { (tileX + 1) << zoomToLoad, tileY << zoomToLoad, (tileY + 1) << zoomToLoad, matcher); for (Entry> r : map.entrySet()) { if(nativeLib != null) { + try { + r.getKey().initRouteRegionsIfNeeded(request); + } catch (IOException e) { + throw new RuntimeException("Loading data exception", e); + } for(RouteRegion reg : r.getKey().getRoutingIndexes()) { NativeRouteSearchResult rs = nativeLoadRegion(request, reg, nativeLib, loadData); if(rs != null) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 55a26b3b97..988de9e0b5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -412,6 +412,9 @@ public class MapActivityActions implements DialogProvider { buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton); buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton); ApplicationMode appMode = settings.getApplicationMode(); + if(appMode == ApplicationMode.DEFAULT) { + appMode = ApplicationMode.CAR; + } for (int i = 0; i < buttons.length; i++) { if (buttons[i] != null) { final int ind = i;