From bf7c14a8e913fb9ba0e25f4e827b20c75756df7f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 7 Sep 2012 11:20:24 +0200 Subject: [PATCH 1/2] Slightly change update distance mechanism. Do not calculate route in default mode --- OsmAnd/src/net/osmand/OsmAndFormatter.java | 18 ++++++++++++------ .../osmand/plus/activities/MapActivity.java | 5 ++++- .../plus/activities/MapActivityActions.java | 4 ++-- .../parkingpoint/ParkingPositionPlugin.java | 2 +- .../net/osmand/plus/routing/RoutingHelper.java | 3 --- .../osmand/plus/views/RouteInfoControls.java | 10 ++++++---- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/OsmAndFormatter.java b/OsmAnd/src/net/osmand/OsmAndFormatter.java index a6ae02aaf6..be81463f3b 100644 --- a/OsmAnd/src/net/osmand/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/OsmAndFormatter.java @@ -10,6 +10,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.SpecialPhrases; +import net.osmand.plus.activities.ApplicationMode; import android.content.Context; public class OsmAndFormatter { @@ -97,16 +98,21 @@ public class OsmAndFormatter { public static String getFormattedSpeed(float metersperseconds, Context ctx) { OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings(); MetricsConstants mc = settings.METRIC_SYSTEM.get(); + ApplicationMode am = settings.getApplicationMode(); float kmh = metersperseconds * 3.6f; - if(mc == MetricsConstants.KILOMETERS_AND_METERS){ - return ((int) kmh) + " " + ctx.getString(R.string.km_h); + if (mc == MetricsConstants.KILOMETERS_AND_METERS) { + if (kmh >= 15 || (am == ApplicationMode.CAR)) { + return ((int) kmh) + " " + ctx.getString(R.string.km_h); + } + kmh = ((int) kmh * 10f) / 10f; + return kmh + " " + ctx.getString(R.string.km_h); } else { float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_MILE; - if(mph >= 10) { - return ((int) (mph)) + " "+ ctx.getString(R.string.mile_per_hour); + if (mph >= 10) { + return ((int) (mph)) + " " + ctx.getString(R.string.mile_per_hour); } else { - mph = ((int)mph*10f)/10f; - return mph + " "+ ctx.getString(R.string.mile_per_hour); + mph = ((int) mph * 10f) / 10f; + return mph + " " + ctx.getString(R.string.mile_per_hour); } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 90f14d1d07..5c90fb797e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -932,7 +932,10 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe } else { settings.clearPointToNavigate(); } - routingHelper.setFinalAndCurrentLocation(point, getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); + if(routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() || + routingHelper.isFollowingMode()) { + routingHelper.setFinalAndCurrentLocation(point, getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); + } mapLayers.getNavigationLayer().setPointToNavigate(point); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index c2fb2d7ce5..5f9c36d46d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -467,7 +467,7 @@ public class MapActivityActions implements DialogProvider { settings.FOLLOW_THE_ROUTE.set(false); settings.FOLLOW_THE_GPX_ROUTE.set(null); routingHelper.setFollowingMode(false); - routingHelper.setFinalAndCurrentLocation(mapActivity.getPointToNavigate(), from); + routingHelper.setFinalAndCurrentLocation(mapActivity.getPointToNavigate(), from, null); } }; @@ -503,7 +503,7 @@ public class MapActivityActions implements DialogProvider { settings.FOLLOW_THE_ROUTE.set(true); settings.FOLLOW_THE_GPX_ROUTE.set(null); routingHelper.setFollowingMode(true); - routingHelper.setFinalAndCurrentLocation(mapActivity.getPointToNavigate(), current); + routingHelper.setFinalAndCurrentLocation(mapActivity.getPointToNavigate(), current, null); dialog.dismiss(); getMyApplication().showDialogInitializingCommandPlayer(mapActivity); } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index fecabc4e6e..e4876794d1 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -409,7 +409,7 @@ public class ParkingPositionPlugin extends OsmandPlugin { * @return */ private boolean distChanged(int oldDist, int dist){ - if(oldDist != 0 && oldDist - dist < 100 && Math.abs(((float) dist - oldDist)/oldDist) < 0.01){ + if(oldDist != 0 && oldDist - dist < 30){ return false; } return true; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 13aef334f6..d2a5a3b588 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -88,9 +88,6 @@ public class RoutingHelper { } - public void setFinalAndCurrentLocation(LatLon finalLocation, Location currentLocation){ - setFinalAndCurrentLocation(finalLocation, currentLocation, null); - } public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, Location currentLocation, GPXRouteParams gpxRoute){ clearCurrentRoute(finalLocation); diff --git a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java b/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java index f9604a18e2..e797fc4023 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java @@ -308,11 +308,13 @@ public class RouteInfoControls { public boolean updateInfo() { // draw speed if (map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()) { - // .3 mps == 1.08 kph - float minDelta = .3f; + // .1 mps == 0.36 kph + float minDelta = .1f; // Update more often at walk/run speeds, since we give higher resolution // and use .02 instead of .03 to account for rounding effects. - if (cachedSpeed < 6) minDelta = .015f; + if (cachedSpeed < 6) { + minDelta = .015f; + } if (Math.abs(map.getLastKnownLocation().getSpeed() - cachedSpeed) > minDelta) { cachedSpeed = map.getLastKnownLocation().getSpeed(); String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map); @@ -601,7 +603,7 @@ public class RouteInfoControls { public boolean distChanged(int oldDist, int dist){ - if(oldDist != 0 && oldDist - dist < 100 && Math.abs(((float) dist - oldDist)/oldDist) < 0.01){ + if(oldDist != 0 && oldDist - dist < 10){ return false; } return true; From 5c986aa0f59b4410d5bb1de74fdac69844cba847 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 7 Sep 2012 11:38:37 +0200 Subject: [PATCH 2/2] Adjust coastline for some areas --- .../net/osmand/plus/render/MapRenderRepositories.java | 7 +++++-- Osmand-kernel/osmand/src/binaryRead.cpp | 11 +++++------ Osmand-kernel/osmand/src/binaryRead.h | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 304076e001..3b5ae0c006 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -316,6 +316,7 @@ public class MapRenderRepositories { searchFilter = null; } boolean ocean = false; + boolean land = false; MapIndex mi = null; searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter); for (BinaryMapIndexReader c : files.values()) { @@ -353,8 +354,10 @@ public class MapRenderRepositories { if (searchRequest.isOcean()) { mi = c.getMapIndexes().get(0); ocean = true; - } else if (searchRequest.isLand()) { + } + if (searchRequest.isLand()) { mi = c.getMapIndexes().get(0); + land = true; } } @@ -379,7 +382,7 @@ public class MapRenderRepositories { } if(addBasemapCoastlines && mi != null){ BinaryMapDataObject o = new BinaryMapDataObject(new int[] { leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, - topY }, new int[] { ocean ? mi.coastlineEncodingType : (mi.landEncodingType) }, null, -1); + topY }, new int[] { ocean && !land ? mi.coastlineEncodingType : (mi.landEncodingType) }, null, -1); o.setMapIndex(mi); tempResult.add(o); } diff --git a/Osmand-kernel/osmand/src/binaryRead.cpp b/Osmand-kernel/osmand/src/binaryRead.cpp index 474965d6c3..ddc90e253a 100644 --- a/Osmand-kernel/osmand/src/binaryRead.cpp +++ b/Osmand-kernel/osmand/src/binaryRead.cpp @@ -744,7 +744,7 @@ bool searchMapTreeBounds(CodedInputStream* input, MapTreeBounds* current, MapTre if(current->ocean){ req->ocean = true; } else { - req->land = true; + req->mixed = true; } break; } @@ -882,7 +882,6 @@ ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, map::iterator i = openFiles.begin(); UNORDERED(set) ids; int count = 0; - bool ocean = false; std::vector basemapResult; std::vector tempResult; std::vector coastLines; @@ -941,9 +940,7 @@ ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, } } } - if (q->ocean) { - ocean = true; - } + if (!q->publisher->isCancelled()) { std::vector::iterator r = q->publisher->result.begin(); tempResult.reserve((size_t)(q->publisher->result.size() + tempResult.size())); @@ -982,6 +979,8 @@ ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, deleteObjects(basemapCoastLines); deleteObjects(basemapResult); } else { + bool ocean = q->ocean; + bool land = q->mixed; bool addBasemapCoastlines = true; bool emptyData = q->zoom > BASEMAP_ZOOM && tempResult.empty() && coastLines.empty(); bool basemapMissing = q->zoom <= BASEMAP_ZOOM && basemapCoastLines.empty() && !basemapExists; @@ -1006,7 +1005,7 @@ ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, o->points.push_back(int_pair(q->right, q->bottom)); o->points.push_back(int_pair(q->left, q->bottom)); o->points.push_back(int_pair(q->left, q->top)); - if (ocean) { + if (ocean && !land) { o->types.push_back(tag_value("natural", "coastline")); } else { o->types.push_back(tag_value("natural", "land")); diff --git a/Osmand-kernel/osmand/src/binaryRead.h b/Osmand-kernel/osmand/src/binaryRead.h index 94c36bd741..61046d60b8 100644 --- a/Osmand-kernel/osmand/src/binaryRead.h +++ b/Osmand-kernel/osmand/src/binaryRead.h @@ -221,7 +221,7 @@ struct SearchQuery { coordinates cacheCoordinates; bool ocean; - bool land; + bool mixed; int numberOfVisitedObjects; int numberOfAcceptedObjects; @@ -232,7 +232,7 @@ struct SearchQuery { req(req), left(l), right(r), top(t), bottom(b),publisher(publisher) { numberOfAcceptedObjects = numberOfVisitedObjects = 0; numberOfAcceptedSubtrees = numberOfReadSubtrees = 0; - ocean = land = false; + ocean = mixed = false; } SearchQuery(int l, int r, int t, int b) : req(req), left(l), right(r), top(t), bottom(b) {